php - Is there a way to only load specific fixtures for a given PHPUnit test? -


we using yii 1.1, suspect issue apply using phpunit.

some of our unit tests depend on specific data in database, we're using fixtures. unfortunately, define fixtures on per-test-class basis, not per-test-function basis.

example:

class accounttest extends cdbtestcase {     public $fixtures = array(         'users' => 'user',         'email_accounts' => 'emailaccount',         'histories' => 'history',         'email_queue' => 'emailqueue',         'org_unit' => 'orgunit',     );      // ...      public function testisvalid_preventswhitespacearoundnumber()     {         // ... (test logic)...     }      // ... (more tests)... } 

some of tests our account model require several different tables updated match defined fixtures, other tests same class don't depend on fixtures @ all. unfortunately, of tests in our accounttest.php file (which contains tests our account model) have added delay of reloading fixtures 5 tables in database.

as specific example, account->isvalid() function has 7 unit tests confirm various things or doesn't consider valid. did test of running testisvalid unit tests , without fixtures (which tests don't need): fixtures took 2.95 seconds, without took 0.068 seconds.

we have tried (in attempt solve different problem) creating 2 different accounttest.php files (in different folders) separate out our unit tests different groups, caused more problems resolved.

my ultimate goal able define for particular test whether needs database fixtures loaded (and if so, ones) tests don't depend on fixtures can run faster, without delay of waiting database (unnecessarily) updated.

thus question: there way load specific fixtures given phpunit test?

how this? assuming test class extends \cdbtestcase ...

  • change name of $fixtures $optionalfixtures
  • add following ...

    public function loadfixtures($fixtures=null) {     if ($fixtures === null) {         $fixtures = $this->optionalfixtures;     }      if(is_array($fixtures))         $this->getfixturemanager()->load($fixtures);     $this->fixtures = $fixtures; } 

then, in test want (the) fixtures loaded, add call method (with optional array). tests without call should end running without fixtures getting loaded, although fixtures may still in database previous tests.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -