CakePHP is known for featuring a powerful and intuitive convention-based Object Relational Mapper. But like many PHP frameworks, it shows limitations in the management of test fixtures.
One approach consists in loading or emulating a database dump before each test is run. Another one creates the test fixtures with the help of factories inside each test.
The first approach breaks the rule of test independence, and leads to opaque tests. We investigated the second approach, which delivers more intelligible tests. But as a trade off, tests got slower to write.
Really slower? No. Thanks to the CakePHP ORM, we came up with an efficient method to write test fixtures on the fly: the CakePHP Fixture Factories. Tests are fast to write and document ideally your application. The package drastically increases the tests’ speed by offering the possibility to create entities without persistence.
On the journey we developed a trigger-based PHPUnit test listener in order to refresh test databases prior to each test.
Whether you are a CakePHP developer or not, the presentation will provide insights on how to arrange your tests and manage your test fixtures.
Juan Pablo Ramirez – Nicolas Masson