From 07c36669a79ab16cb43c5c79ecacb73686c9da75 Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Sun, 20 Feb 2022 18:55:44 +0200 Subject: [PATCH 1/4] Fix Sqlite primary key column detection on PHP 8.1 --- src/Codeception/Lib/Driver/Sqlite.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Lib/Driver/Sqlite.php b/src/Codeception/Lib/Driver/Sqlite.php index d33c26be..74b62f26 100644 --- a/src/Codeception/Lib/Driver/Sqlite.php +++ b/src/Codeception/Lib/Driver/Sqlite.php @@ -64,7 +64,7 @@ public function getPrimaryKey($tableName) $columns = $stmt->fetchAll(\PDO::FETCH_ASSOC); foreach ($columns as $column) { - if ($column['pk'] !== '0') { + if ($column['pk'] !== '0' && $column['pk'] !== 0) { $primaryKey []= $column['name']; } } From 6abb4c6f0f229d166adc3df28d6b84d7c614b89b Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Sat, 5 Mar 2022 20:54:50 +0200 Subject: [PATCH 2/4] Null safety in destructor --- src/Codeception/Lib/Driver/Db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Lib/Driver/Db.php b/src/Codeception/Lib/Driver/Db.php index fb1a2228..c327cb47 100755 --- a/src/Codeception/Lib/Driver/Db.php +++ b/src/Codeception/Lib/Driver/Db.php @@ -103,7 +103,7 @@ public function __construct($dsn, $user, $password, $options = null) public function __destruct() { - if ($this->dbh->inTransaction()) { + if ($this->dbh !== null && $this->dbh->inTransaction()) { $this->dbh->rollBack(); } $this->dbh = null; From 04c3e66fbd3a3ced17fcccc49627f6393a97b04b Mon Sep 17 00:00:00 2001 From: Thomas Faurbye Nielsen Date: Sat, 5 Mar 2022 19:49:46 +0100 Subject: [PATCH 3/4] Add skip_cleanup_if_failed option for not cleaning up failed tests (#30) * Add no_cleanup_failed option for not cleaning up failed tests * Update to handle all databases * Change name from 'no_cleanup_failed' to 'skip_cleanup_if_failed' --- src/Codeception/Module/Db.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index 9414278b..26aafb19 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -55,7 +55,7 @@ * * ssl_cipher - list of one or more permissible ciphers to use for SSL encryption (MySQL specific, @see http://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-cipher) * * databases - include more database configs and switch between them in tests. * * initial_queries - list of queries to be executed right after connection to the database has been initiated, i.e. creating the database if it does not exist or preparing the database collation - * + * * skip_cleanup_if_failed - Do not perform the cleanup if the tests failed. If this is used, manual cleanup might be required when re-running * ## Example * * modules: @@ -69,6 +69,7 @@ * cleanup: true * reconnect: true * waitlock: 10 + * skip_cleanup_if_failed: true * ssl_key: '/path/to/client-key.pem' * ssl_cert: '/path/to/client-cert.pem' * ssl_ca: '/path/to/ca-cert.pem' @@ -253,6 +254,7 @@ class Db extends CodeceptionModule implements DbInterface 'waitlock' => 0, 'dump' => null, 'populator' => null, + 'skip_cleanup_if_failed' => false, ]; /** @@ -614,6 +616,15 @@ public function _before(TestInterface $test) parent::_before($test); } + public function _failed(TestInterface $test, $fail) + { + foreach ($this->getDatabases() as $databaseKey => $databaseConfig) { + if (!empty($databaseConfig['skip_cleanup_if_failed'])) { + $this->insertedRows[$databaseKey] = []; + } + } + } + public function _after(TestInterface $test) { $this->removeInsertedForDatabases(); @@ -723,7 +734,8 @@ protected function loadDumpUsingDriver($databaseKey) } /** - * Inserts an SQL record into a database. This record will be erased after the test. + * Inserts an SQL record into a database. This record will be erased after the test, + * unless you've configured "skip_cleanup_if_failed", and the test fails. * * ```php * Date: Thu, 23 Jun 2022 10:10:05 +0300 Subject: [PATCH 4/4] 1.x branch is compatible with Codeception 4 only --- composer.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/composer.json b/composer.json index f60f9327..1f7a0209 100644 --- a/composer.json +++ b/composer.json @@ -16,10 +16,7 @@ "minimum-stability": "RC", "require": { "php": ">=5.6.0 <9.0", - "codeception/codeception": "*@dev" - }, - "conflict": { - "codeception/codeception": "<4.0" + "codeception/codeception": "^4.1" }, "autoload":{ "classmap": ["src/"]