Skip to content

Commit 04c3e66

Browse files
ArchaniumNaktibalda
authored andcommitted
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 6abb4c6 commit 04c3e66

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
@@ -55,7 +55,7 @@
5555
* * 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)
5656
* * databases - include more database configs and switch between them in tests.
5757
* * 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
58-
*
58+
* * 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
5959
* ## Example
6060
*
6161
* modules:
@@ -69,6 +69,7 @@
6969
* cleanup: true
7070
* reconnect: true
7171
* waitlock: 10
72+
* skip_cleanup_if_failed: true
7273
* ssl_key: '/path/to/client-key.pem'
7374
* ssl_cert: '/path/to/client-cert.pem'
7475
* ssl_ca: '/path/to/ca-cert.pem'
@@ -253,6 +254,7 @@ class Db extends CodeceptionModule implements DbInterface
253254
'waitlock' => 0,
254255
'dump' => null,
255256
'populator' => null,
257+
'skip_cleanup_if_failed' => false,
256258
];
257259

258260
/**
@@ -614,6 +616,15 @@ public function _before(TestInterface $test)
614616
parent::_before($test);
615617
}
616618

619+
public function _failed(TestInterface $test, $fail)
620+
{
621+
foreach ($this->getDatabases() as $databaseKey => $databaseConfig) {
622+
if (!empty($databaseConfig['skip_cleanup_if_failed'])) {
623+
$this->insertedRows[$databaseKey] = [];
624+
}
625+
}
626+
}
627+
617628
public function _after(TestInterface $test)
618629
{
619630
$this->removeInsertedForDatabases();
@@ -723,7 +734,8 @@ protected function loadDumpUsingDriver($databaseKey)
723734
}
724735

725736
/**
726-
* Inserts an SQL record into a database. This record will be erased after the test.
737+
* Inserts an SQL record into a database. This record will be erased after the test,
738+
* unless you've configured "skip_cleanup_if_failed", and the test fails.
727739
*
728740
* ```php
729741
* <?php

0 commit comments

Comments
 (0)