diff --git a/src/TestSuite/TestCase.php b/src/TestSuite/TestCase.php index 886ebaa90d9..6cff6605cd1 100644 --- a/src/TestSuite/TestCase.php +++ b/src/TestSuite/TestCase.php @@ -141,6 +141,13 @@ public function loadFixtures() foreach ($args as $class) { $this->fixtureManager->loadSingle($class, null, $this->dropTables); } + + if (empty($args)) { + $autoFixtures = $this->autoFixtures; + $this->autoFixtures = true; + $this->fixtureManager->load($this); + $this->autoFixtures = $autoFixtures; + } } /** diff --git a/tests/Fixture/FixturizedTestCase.php b/tests/Fixture/FixturizedTestCase.php index 00e3d42cc4c..5c0d5b4260f 100644 --- a/tests/Fixture/FixturizedTestCase.php +++ b/tests/Fixture/FixturizedTestCase.php @@ -2,6 +2,7 @@ namespace Cake\Test\Fixture; use Cake\TestSuite\TestCase; +use Cake\ORM\TableRegistry; use Exception; /** @@ -14,7 +15,7 @@ class FixturizedTestCase extends TestCase * Fixtures to use in this test * @var array */ - public $fixtures = ['core.categories']; + public $fixtures = ['core.categories', 'core.articles']; /** * test that the shared fixture is correctly set @@ -36,6 +37,20 @@ public function testFixtureLoadOnDemand() $this->loadFixtures('Categories'); } + /** + * test that calling loadFixtures without args loads all fixtures + * + * @return void + */ + public function testLoadAllFixtures() + { + $this->loadFixtures(); + $article = TableRegistry::get('Articles')->get(1); + $this->assertSame(1, $article->id); + $category = TableRegistry::get('Categories')->get(1); + $this->assertSame(1, $category->id); + } + /** * test that a test is marked as skipped using skipIf and its first parameter evaluates to true * diff --git a/tests/TestCase/TestSuite/TestCaseTest.php b/tests/TestCase/TestSuite/TestCaseTest.php index f692bddbd87..cacaf7c781c 100644 --- a/tests/TestCase/TestSuite/TestCaseTest.php +++ b/tests/TestCase/TestSuite/TestCaseTest.php @@ -22,6 +22,7 @@ use Cake\ORM\Entity; use Cake\ORM\Table; use Cake\ORM\TableRegistry; +use Cake\TestSuite\Fixture\FixtureManager; use Cake\TestSuite\TestCase; use Cake\Test\Fixture\FixturizedTestCase; @@ -138,6 +139,26 @@ public function testLoadFixturesOnDemand() $this->assertEquals(0, $result->errorCount()); } + /** + * tests loadFixtures loads all fixtures on the test + * + * @return void + */ + public function testLoadAllFixtures() + { + $test = new FixturizedTestCase('testLoadAllFixtures'); + $test->autoFixtures = false; + $manager = new FixtureManager(); + $manager->fixturize($test); + $test->fixtureManager = $manager; + + $result = $test->run(); + + $this->assertEquals(0, $result->errorCount()); + $this->assertCount(1, $result->passed()); + $this->assertFalse($test->autoFixtures); + } + /** * testSkipIf *