-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Questions on the test suite lights in CakePHP 4.3 #54
Comments
Hello @Rakasch , are you creating the schema with the MIgrator tool? This will create the schema of the test DB once when the test suite starts. If you are using migrations, it will recreate the schema only if migrations were added or removed since the last test suite run. If you are using the CakePHP 4.3 phpunit.xml.dist file, you should specify the truncation strategy by using the TruncateDirtyTables trait in your DB-interacting tests. The deprecated phpunit.xml.dist approach works as before. You may start by droping your test database (just once, to make sure) and let your tests run. You should not need to specify the tableSniffer in your config if you are using CakePHP's Mysql driver (see here). So in short my two questions:
|
Thanks for the additional info. Your setup looks fine imo. Are all the tables marked as dirty, namely is the table test_suite_light_dirty_tables populated with the name of all the tables? Something might be breaking due to the fact that you are using two test DB (although this should be supported). Let us debug that with one test DB only. What happens if you comment out the code related to the |
I have found the cause of the problem. In my initial migration of "test_logs" the table "test_suite_light_dirty_tables" is included. In any case, that is the reason why the if-condition said that the table already exists and accordingly did not execute the init code at all. If I take the test_suite_light_dirty_tables out of the migration, the tests are working. |
Glad to read that. Let me know about the other few oddities! |
For the first 'oddity': For the second 'oddity': I've setup two initial migrations for my two database configs
Looking into the migration file, there's no information to which database this migration belongs to. After running the test, I have all tables from both migrations in the test db. in bootstrap.php |
Your migrations should be placed in two different directories, right? Otherways the logs migration would run on the default DB, and the default migrations on the logs DB when using the migrator. So assuming you have your default migrations in config/Migrations and your logs migrations in config/MigrationsLogs: The snapshot commands should read:
When running the migrator on multiple sets of migrations, it is recommended to use the $migrator->runMany([
['connection' => 'test'],
['connection' => 'test_logs', 'source' => 'MigrationsLogs'],
]); Does this help? |
Looks promising. Thank you very much for your time and support! |
Ok, the tests are running now. My tests on a db-view are failing. You said |
The creation of views with migrations is still open here. Maybe something you would like to contribute to? To the sesond point, how does you call with the migrator look like now? |
Regarding the view, you could try to remove the table automatically created by the snapshot, and instead run a MySQL query in the migration file that creates this view, no? |
This is, what's happening each time: I'm new to migrations so I don't know yet how a lot of things work.
I restarted the test suite, but it's still running into the same if case on the screenshot. |
Nice idea. But I guess it doesn't work so easily: |
Regarding the view: Regarding the migrations: I'll close this for the moment. Do not forget to star our packages if those are useful to you. This helps us funding our projects! |
This might also be of interest to you: cakephp/cakephp#16122 |
Thank you again for everything. |
Hallo there,
I have a problem when updating to Cake 4.3.
We are using „Fixture Factories 2.5.1“ and „test-suite-light 2.4“.
Problem:
The tables are not emptied between tests, since the triggers are not created in the database.
After some evaluation, the Sniffer’s truncateDirtyTables() method is called, but createTriggers() is not.
We are using a MariaDB database, so I used the MysqlTriggerBasedTableSniffer in my DB config.
'tableSniffer' => '\CakephpTestSuiteLight\Sniffer\MysqlTriggerBasedTableSniffer',
Note: I already had the problem on Cake 4.2 and before that the triggers were not created automatically.
Therefore I had created the triggers manually on the database. That worked.
With the update, this workaround no longer works.
The triggers are now deleted when the test is executed, since the DB schema is created anew each time by the schema generator.
Would appreciate any help.
Thanks.
The text was updated successfully, but these errors were encountered: