From a454332e68c5b3ceaadc5f332d01733e5624e2bd Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 11 Jan 2014 12:15:21 -0500 Subject: [PATCH] Make error message for missing fixture easier to understand. Telling both the class, fixture reference and test case will help people solve problems a bit quicker. --- src/TestSuite/Fixture/FixtureManager.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/TestSuite/Fixture/FixtureManager.php b/src/TestSuite/Fixture/FixtureManager.php index f5ba245adff..cd251e3685d 100644 --- a/src/TestSuite/Fixture/FixtureManager.php +++ b/src/TestSuite/Fixture/FixtureManager.php @@ -68,10 +68,7 @@ public function fixturize($test) { if (!is_array($test->fixtures)) { $test->fixtures = array_map('trim', explode(',', $test->fixtures)); } - if (isset($test->fixtures)) { - $this->_loadFixtures($test->fixtures); - } - + $this->_loadFixtures($test); $this->_processed[get_class($test)] = true; } @@ -120,14 +117,15 @@ protected function _initDb() { /** * Looks for fixture files and instantiates the classes accordingly * - * @param array $fixtures the fixture names to load using the notation {type}.{name} + * @param Cake\TestSuite\Testcase $test The test suite to load fixtures for. * @return void * @throws UnexpectedValueException when a referenced fixture does not exist. */ - protected function _loadFixtures($fixtures) { - foreach ($fixtures as $fixture) { - $fixtureFile = null; - $fixtureIndex = $fixture; + protected function _loadFixtures($test) { + if (empty($test->fixtures)) { + return; + } + foreach ($test->fixtures as $fixture) { if (isset($this->_loaded[$fixture])) { continue; } @@ -151,7 +149,13 @@ protected function _loadFixtures($fixtures) { $this->_loaded[$fixture] = new $className(); $this->_fixtureMap[$base] = $this->_loaded[$fixture]; } else { - throw new \UnexpectedValueException(sprintf('Referenced fixture class %s not found', $className)); + $msg = sprintf( + 'Referenced fixture class "%s" not found. Fixture "%s" was referenced in test case "%s".', + $className, + $fixture, + get_class($test) + ); + throw new \UnexpectedValueException($msg); } } }