Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Codeception/Module/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand Down Expand Up @@ -260,6 +261,7 @@ class Db extends Module implements DbInterface
'waitlock' => 0,
'dump' => null,
'populator' => null,
'skip_cleanup_if_failed' => false,
];

/**
Expand Down Expand Up @@ -635,6 +637,15 @@ public function _before(TestInterface $test): void
parent::_before($test);
}

public function _failed(TestInterface $test, $fail)
{
foreach ($this->getDatabases() as $databaseKey => $databaseConfig) {
if ($databaseConfig['skip_cleanup_if_failed'] ?? false) {
$this->insertedRows[$databaseKey] = [];
}
}
}

public function _after(TestInterface $test): void
{
$this->removeInsertedForDatabases();
Expand Down Expand Up @@ -748,7 +759,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 "skip_cleanup_if_failed", and the test fails.
*
* ```php
* <?php
Expand Down