Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7611391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:39:30+00:00 2026-05-31T01:39:30+00:00

How do you prevent a CakePHP 2.0 test case, which extends CakeTestCase (uses PHPUnit),

  • 0

How do you prevent a CakePHP 2.0 test case, which extends CakeTestCase (uses PHPUnit), from reloading fixtures between tests?

Background: There is a set of integration tests which we have written with CakePHP 2.0 using PHPUnit. We have extended the test case class from the standard CakeTestCase. For this set of tests, we have a bunch of fixtures setup to populate the data from the database. Naturally, these tests take a long time to run. Basically, all of the time is coming from Cake unloading and re-loading all of the fixtures between tests.

All of the tests act as READ only. We are just issuing find calls to the database and testing the logic among a set of class interactions based on those results. In fact, the tests can be boiled down to:

class ALongRunningTest extends CakeTestCase {
    public $fixtures = array('app.class1', 'app.class2', ... 'app.class8');

    /**
     * @dataProvider provider
     * @test
     */
    public function checkCompositionLogic($val1, $val2, $val3) {
        // internally calls class1 and class3
        $data = $this->ModelX->generateComplexStructure($val1);

        // internally calls other classes & models, which touch the
        // other loaded fixtures
        $results = $this->ModelY->checkAllWhichApply($val2, $data);

        $this->assertEquals($val3, $results);
    }

    public function provider() {
        return array(
            array(stuff, stuff1, stuff2),
            array(x_stuff, x_stuff1, x_stuff2),
            array(y_stuff, y_stuff1, y_stuff2),
            array(z_stuff, z_stuff1, z_stuff2),
            array(a_stuff, a_stuff1, a_stuff2),
            // More test cases
        );
    }
}

I’ve not been able to find anything on how to prevent this. I saw in the CakeTestCase class a public variable autoFixtures with a comment that says if you change it to false it won’t load the fixtures. It makes a note stating that you have to load them manually. However, I see no documentation on how to actually load them manually.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:39:31+00:00Added an answer on May 31, 2026 at 1:39 am

    Strictly speaking, CakePHP is correct in the way that it works. Tests shouldn’t be dependent upon each other, so that database is reset between each test case. You could even argue that it should be reset between each test method, but the overhead would be even more noticeable.

    However, since you’re doing read only actions on the database, you could remove all the references to fixtures in your test cases and set up your database entries before you run the test suite (e.g. import it from an SQL file).

    Or you could create a custom test suite that adds a whole load of data, e.g:

    class AllTest extends CakeTestSuite {
        public static function suite() {
            self::loadDB();
            $suite = new CakeTestSuite('All tests');
            $suite->addTestDirectoryRecursive(TESTS . 'Case');
            return $suite;
        }
        public static function loadDB() {
             //Do some set up here using your models
        }
    }
    

    The advantage of doing it that was is that if you ever had to introduce tests that do write to the database, you could run them under a separate test suite.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inherited a Cakephp application which uses a great deal of $this->redirect($url) statements; all of
To prevent impatient users from clicking on a link to a webstart application too
How do I prevent vim from replacing spaces with tabs when autoindent is on?
Is it possible to prevent an asp.net Hyperlink control from linking, i.e. so that
Does TCP/IP prevent multiple copies of the same packet from reaching the destination? Or
How do I prevent my users from accessing directly pages meant for ajax calls
How can I prevent a user from resizing GridViewColumns withing a ListView control?
I need to prevent duplicate names from been entered. This restriction needs to be
I am trying to prevent an instance from throwing an exception if a method
How can I prevent Uglifier from removing some comments from some files? I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.