Does CakePHP ignore $dropTables in unit tests?


I’m writing unit tests for my CakePHP application. They currently run really slowly as my tables get dropped and recreated before every single test. I want to disable this behaviour, and instead have it so that fixtures are executed once per TestCase. Apparently it’s possible via $dropTables:

But no matter what I set dropTables to, fixtures are still loaded/unloaded between each test run, which means my tests still run excruciatingly slowly. (30 seconds per test, and I have a few hundred tests already)

If I disable $autoFixtures then CakePHP skips running my fixtures, but it doesn’t run them at all. I need my fixtures to be run once at the start and end of every TestCase.

I thought about using setUpBeforeClass and setUpAfterClass to change the value of $autoFixtures on the fly or even to manually run my fixtures, but these functions have to be static and so I don’t think they have access to fixtureManager.

Help would be very much appreciated.


this might not be the answer for your question but ive had similar problem - with long running tests - and the solution was simple - move to memory engine i.e. for MySQL change in fixtures

'_options' => [
      'engine' => 'memory' 
1 Like

That seems like a great idea, where do I put the code you included? It doesn’t seem to go in app.php, or at least I can’t find documentation for it.

in every fixture i.e.:

class UsersFixture extends TestFixture

     * Fields
     * @var array
    // @codingStandardsIgnoreStart
    public $fields = [
       // some fields definitions
        '_options' => [
            'engine' => 'memory' 
1 Like

Thanks for the suggestion, I’ll look into that on Monday.

It should not run so slow, except if you have really a lot of records in your fixtures. Fixture data should be as small as possible, ideally only a very few records, just enough for testing.

I don’t have that many records in my fixtures, just the ones required for testing. I think the time it takes is mostly just for the structure of the tables.