From ba3b126025a8b9a3f0bd3d763da3ab932fc3378c Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Fri, 20 Dec 2024 12:03:42 +0100 Subject: [PATCH 1/5] Update Db.php: Fixing code formating, removing duplication --- src/Codeception/Module/Db.php | 173 ++++++++++++++++------------------ 1 file changed, 80 insertions(+), 93 deletions(-) diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index b78eb721..6b9da303 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -26,7 +26,7 @@ * This module also provides actions to perform checks in a database, e.g. [seeInDatabase()](https://codeception.com/docs/modules/Db#seeInDatabase) * * In order to have your database populated with data you need a raw SQL dump. - * Simply put the dump in the `tests/_data` directory (by default) and specify the path in the config. + * Simply put the dump in the `tests/Support/Data` directory (by default) and specify the path in the config. * The next time after the database is cleared, all your data will be restored from the dump. * Don't forget to include `CREATE TABLE` statements in the dump. * @@ -41,85 +41,72 @@ * * MS SQL * * Oracle * - * Connection is done by database Drivers, which are stored in the `Codeception\Lib\Driver` namespace. - * [Check out the drivers](https://github.com/Codeception/Codeception/tree/2.4/src/Codeception/Lib/Driver) - * if you run into problems loading dumps and cleaning databases. + * Connection is done by database drivers, which are stored in the `Codeception\Lib\Driver` namespace. + * Check out the drivers if you run into problems loading dumps and cleaning databases. * - * ## Config - * - * * dsn *required* - PDO DSN - * * user *required* - username to access database - * * password *required* - password - * * dump - path to database dump - * * populate: false - whether the the dump should be loaded before the test suite is started - * * cleanup: false - whether the dump should be reloaded before each test - * * reconnect: false - whether the module should reconnect to the database before each test - * * waitlock: 0 - wait lock (in seconds) that the database session should use for DDL statements - * * ssl_key - path to the SSL key (MySQL specific, @see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-key) - * * ssl_cert - path to the SSL certificate (MySQL specific, @see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-ssl-cert) - * * ssl_ca - path to the SSL certificate authority (MySQL specific, @see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-ssl-ca) - * * ssl_verify_server_cert - disables certificate CN verification (MySQL specific, @see https://php.net/manual/de/ref.pdo-mysql.php) - * * ssl_cipher - list of one or more permissible ciphers to use for SSL encryption (MySQL specific, @see https://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: - * enabled: - * - Db: - * dsn: 'mysql:host=localhost;dbname=testdb' - * user: 'root' - * password: '' - * dump: 'tests/_data/dump.sql' - * populate: true - * 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' - * ssl_verify_server_cert: false - * ssl_cipher: 'AES256-SHA' - * initial_queries: - * - 'CREATE DATABASE IF NOT EXISTS temp_db;' - * - 'USE temp_db;' - * - 'SET NAMES utf8;' + * ## Example `Functional.suite.yml` + * ```yaml + * modules: + * enabled: + * - Db: + * dsn: 'mysql:host=localhost;dbname=testdb' + * user: 'root' + * password: '' + * dump: 'tests/_data/dump.sql' + * populate: true # whether the dump should be loaded before the test suite is started + * cleanup: true # whether the dump should be reloaded before each test + * reconnect: true # whether the module should reconnect to the database before each test + * waitlock: 10 # wait lock (in seconds) that the database session should use for DDL statements + * databases: # include more database configs and switch between them in tests. + * skip_cleanup_if_failed: true # Do not perform the cleanup if the tests failed. If this is used, manual cleanup might be required when re-running + * ssl_key: '/path/to/client-key.pem' # path to the SSL key (MySQL specific, see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-key) + * ssl_cert: '/path/to/client-cert.pem' # path to the SSL certificate (MySQL specific, see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-ssl-cert) + * ssl_ca: '/path/to/ca-cert.pem' # path to the SSL certificate authority (MySQL specific, see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-ssl-ca) + * ssl_verify_server_cert: false # disables certificate CN verification (MySQL specific, see https://php.net/manual/de/ref.pdo-mysql.php) + * ssl_cipher: 'AES256-SHA' # list of one or more permissible ciphers to use for SSL encryption (MySQL specific, see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-cipher) + * 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 + * - 'CREATE DATABASE IF NOT EXISTS temp_db;' + * - 'USE temp_db;' + * - 'SET NAMES utf8;' + * ``` * * ## Example with multi-dumps - * modules: - * enabled: - * - Db: - * dsn: 'mysql:host=localhost;dbname=testdb' - * user: 'root' - * password: '' - * dump: - * - 'tests/_data/dump.sql' - * - 'tests/_data/dump-2.sql' + * ```yaml + * modules: + * enabled: + * - Db: + * dsn: 'mysql:host=localhost;dbname=testdb' + * user: 'root' + * password: '' + * dump: + * - 'tests/_data/dump.sql' + * - 'tests/_data/dump-2.sql' + * ``` * * ## Example with multi-databases - * - * modules: - * enabled: - * - Db: - * dsn: 'mysql:host=localhost;dbname=testdb' - * user: 'root' - * password: '' - * databases: + * ```yaml + * modules: + * enabled: + * - Db: + * dsn: 'mysql:host=localhost;dbname=testdb' + * user: 'root' + * password: '' + * databases: * db2: - * dsn: 'mysql:host=localhost;dbname=testdb2' - * user: 'userdb2' - * password: '' - * - * ## Example with Sqlite + * dsn: 'mysql:host=localhost;dbname=testdb2' + * user: 'userdb2' + * password: '' + * ``` * - * modules: - * enabled: - * - Db: - * dsn: 'sqlite:relative/path/to/sqlite-database.db' - * user: '' - * password: '' + * ## Example with SQLite + * ```yaml + * modules: + * enabled: + * - Db: + * dsn: 'sqlite:relative/path/to/sqlite-database.db' + * user: '' + * password: '' + * ``` * * ## SQL data dump * @@ -134,30 +121,30 @@ * * ```yaml * modules: - * enabled: - * - Db: - * dsn: 'mysql:host=localhost;dbname=testdb' - * user: 'root' - * password: '' - * dump: 'tests/_data/dump.sql' - * populate: true # run populator before all tests - * cleanup: true # run populator before each test - * populator: 'mysql -u $user -h $host $dbname < $dump' + * enabled: + * - Db: + * dsn: 'mysql:host=localhost;dbname=testdb' + * user: 'root' + * password: '' + * dump: 'tests/_data/dump.sql' + * populate: true # run populator before all tests + * cleanup: true # run populator before each test + * populator: 'mysql -u $user -h $host $dbname < $dump' * ``` * - * For PostgreSQL (using pg_restore) + * For PostgreSQL (using `pg_restore`) * - * ``` + * ```yaml * modules: - * enabled: - * - Db: - * dsn: 'pgsql:host=localhost;dbname=testdb' - * user: 'root' - * password: '' - * dump: 'tests/_data/db_backup.dump' - * populate: true # run populator before all tests - * cleanup: true # run populator before each test - * populator: 'pg_restore -u $user -h $host -D $dbname < $dump' + * enabled: + * - Db: + * dsn: 'pgsql:host=localhost;dbname=testdb' + * user: 'root' + * password: '' + * dump: 'tests/_data/db_backup.dump' + * populate: true # run populator before all tests + * cleanup: true # run populator before each test + * populator: 'pg_restore -u $user -h $host -D $dbname < $dump' * ``` * * Variable names are being taken from config and DSN which has a `keyword=value` format, so you should expect to have a variable named as the From 7c27497f4af1d0c9d371860641625aee15a62bfd Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Sun, 5 Jan 2025 12:25:44 +0100 Subject: [PATCH 2/5] Update src/Codeception/Module/Db.php Co-authored-by: Dieter Beck --- src/Codeception/Module/Db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index 6b9da303..81dcb890 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -52,7 +52,7 @@ * dsn: 'mysql:host=localhost;dbname=testdb' * user: 'root' * password: '' - * dump: 'tests/_data/dump.sql' + * dump: 'tests/Support/Data/dump.sql' * populate: true # whether the dump should be loaded before the test suite is started * cleanup: true # whether the dump should be reloaded before each test * reconnect: true # whether the module should reconnect to the database before each test From c1044e780468c9cc8c48fb9cdec258ea10cd7716 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Sun, 5 Jan 2025 12:25:57 +0100 Subject: [PATCH 3/5] Update src/Codeception/Module/Db.php Co-authored-by: Dieter Beck --- src/Codeception/Module/Db.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index 81dcb890..c93abba0 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -79,8 +79,8 @@ * user: 'root' * password: '' * dump: - * - 'tests/_data/dump.sql' - * - 'tests/_data/dump-2.sql' + * - 'tests/Support/Data/dump.sql' + * - 'tests/Support/Data/dump-2.sql' * ``` * * ## Example with multi-databases From 70d825a1133f816255ce65102a93c3738731dac0 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Sun, 5 Jan 2025 12:26:05 +0100 Subject: [PATCH 4/5] Update src/Codeception/Module/Db.php Co-authored-by: Dieter Beck --- src/Codeception/Module/Db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index c93abba0..ec542cd3 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -126,7 +126,7 @@ * dsn: 'mysql:host=localhost;dbname=testdb' * user: 'root' * password: '' - * dump: 'tests/_data/dump.sql' + * dump: 'tests/Support/Data/dump.sql' * populate: true # run populator before all tests * cleanup: true # run populator before each test * populator: 'mysql -u $user -h $host $dbname < $dump' From 6e0e8c36695fb05b7af6c66894226ebf69363ba4 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Sun, 5 Jan 2025 12:26:12 +0100 Subject: [PATCH 5/5] Update src/Codeception/Module/Db.php Co-authored-by: Dieter Beck --- src/Codeception/Module/Db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index ec542cd3..17aa3f28 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -141,7 +141,7 @@ * dsn: 'pgsql:host=localhost;dbname=testdb' * user: 'root' * password: '' - * dump: 'tests/_data/db_backup.dump' + * dump: 'tests/Support/Data/db_backup.dump' * populate: true # run populator before all tests * cleanup: true # run populator before each test * populator: 'pg_restore -u $user -h $host -D $dbname < $dump'