Skip to content

Commit 8f97f19

Browse files
authored
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'
1 parent 05b2d6b commit 8f97f19

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Codeception/Module/Db.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
* * 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)
6363
* * databases - include more database configs and switch between them in tests.
6464
* * 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
65-
*
65+
* * 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
6666
* ## Example
6767
*
6868
* modules:
@@ -76,6 +76,7 @@
7676
* cleanup: true
7777
* reconnect: true
7878
* waitlock: 10
79+
* skip_cleanup_if_failed: true
7980
* ssl_key: '/path/to/client-key.pem'
8081
* ssl_cert: '/path/to/client-cert.pem'
8182
* ssl_ca: '/path/to/ca-cert.pem'
@@ -260,6 +261,7 @@ class Db extends Module implements DbInterface
260261
'waitlock' => 0,
261262
'dump' => null,
262263
'populator' => null,
264+
'skip_cleanup_if_failed' => false,
263265
];
264266

265267
/**
@@ -635,6 +637,15 @@ public function _before(TestInterface $test): void
635637
parent::_before($test);
636638
}
637639

640+
public function _failed(TestInterface $test, $fail)
641+
{
642+
foreach ($this->getDatabases() as $databaseKey => $databaseConfig) {
643+
if ($databaseConfig['skip_cleanup_if_failed'] ?? false) {
644+
$this->insertedRows[$databaseKey] = [];
645+
}
646+
}
647+
}
648+
638649
public function _after(TestInterface $test): void
639650
{
640651
$this->removeInsertedForDatabases();
@@ -748,7 +759,8 @@ protected function loadDumpUsingDriver(string $databaseKey): void
748759
}
749760

750761
/**
751-
* Inserts an SQL record into a database. This record will be erased after the test.
762+
* Inserts an SQL record into a database. This record will be erased after the test,
763+
* unless you've configured "skip_cleanup_if_failed", and the test fails.
752764
*
753765
* ```php
754766
* <?php

0 commit comments

Comments
 (0)