From 8a2d509e8a0f1ba384fb610978fe47cb2ddf4972 Mon Sep 17 00:00:00 2001 From: Thomas Faurbye Nielsen Date: Thu, 6 Jan 2022 13:01:38 +0100 Subject: [PATCH 1/3] Add no_cleanup_failed option for not cleaning up failed tests --- src/Codeception/Module/Db.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index 8d41bba9..996ca780 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -260,6 +260,7 @@ class Db extends Module implements DbInterface 'waitlock' => 0, 'dump' => null, 'populator' => null, + 'no_cleanup_failed' => false, ]; /** @@ -635,6 +636,13 @@ public function _before(TestInterface $test): void parent::_before($test); } + public function _failed(TestInterface $test, $fail) + { + if ($this->config['no_cleanup_failed'] ?? false) { + $this->insertedRows = []; + } + } + public function _after(TestInterface $test): void { $this->removeInsertedForDatabases(); @@ -748,7 +756,8 @@ protected function loadDumpUsingDriver(string $databaseKey): void } /** - * 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 "no_cleanup_failed", and the test fails. * * ```php * Date: Thu, 6 Jan 2022 13:04:57 +0100 Subject: [PATCH 2/3] Update to handle all databases --- src/Codeception/Module/Db.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index 996ca780..d5cd2d3e 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -638,8 +638,10 @@ public function _before(TestInterface $test): void public function _failed(TestInterface $test, $fail) { - if ($this->config['no_cleanup_failed'] ?? false) { - $this->insertedRows = []; + foreach ($this->getDatabases() as $databaseKey => $databaseConfig) { + if ($databaseConfig['no_cleanup_failed'] ?? false) { + $this->insertedRows[$databaseKey] = []; + } } } From 227f5bfff4e5d5cb280600950edcdc338d27fb5a Mon Sep 17 00:00:00 2001 From: Thomas Faurbye Nielsen Date: Fri, 25 Feb 2022 17:41:30 +0100 Subject: [PATCH 3/3] Change name from 'no_cleanup_failed' to 'skip_cleanup_if_failed' --- src/Codeception/Module/Db.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index d5cd2d3e..6c116b60 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -62,7 +62,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: @@ -76,6 +76,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' @@ -260,7 +261,7 @@ class Db extends Module implements DbInterface 'waitlock' => 0, 'dump' => null, 'populator' => null, - 'no_cleanup_failed' => false, + 'skip_cleanup_if_failed' => false, ]; /** @@ -639,7 +640,7 @@ public function _before(TestInterface $test): void public function _failed(TestInterface $test, $fail) { foreach ($this->getDatabases() as $databaseKey => $databaseConfig) { - if ($databaseConfig['no_cleanup_failed'] ?? false) { + if ($databaseConfig['skip_cleanup_if_failed'] ?? false) { $this->insertedRows[$databaseKey] = []; } } @@ -759,7 +760,7 @@ protected function loadDumpUsingDriver(string $databaseKey): void /** * Inserts an SQL record into a database. This record will be erased after the test, - * unless you've configured "no_cleanup_failed", and the test fails. + * unless you've configured "skip_cleanup_if_failed", and the test fails. * * ```php *