In my tests i have an extensive use of the db module that i configure in the codeception.yaml in the following way:
However, the structure of
somedb often changes, and the tests suite should run with the updated version of it. Therefore the need to drop and recreate the entirety of
somedb according to the new structure before i run the tests has arised.
Currently i simply drop
somedb and recreate it once before i run the tests. But! this method forces me to have a database named
somedb in order to run the tests. Failing to do so will result in the following error:
In Db.php line 555:
Db: SQLSTATE[HY000]  Unknown database 'somedb' while creating PDO
I understand that this is due to the db module initializing and creating a pdo connection to `somedb` before i have a chance to programmatically create one (due to it being configured in codeception.yaml) . My question is -
Is there a way to manually configure the db module outside of the codeception.yaml config file?
Something like this ( i drop and recreate the db with the following code):
private static function init_db_dump()
// Check if `somedb` exist. If no - create it.
// create the codeception/db module
// drop the db
exec("mysql -u somehost -p -e 'DROP DATABASE IF EXISTS somedb;'");
// delete the outdated dump file
// construct the new dump file the db module will use to initiate `somedb`
exec("cat infra/db/db_structure.sql infra/db/db_data.sql infra/db/db_views.sql tests/_data/db_test_data.sql tests/_data/bi_views.sql tests/_data/db_test_tables.sql > tests/_data/dump_actual.sql");