Skip to content

Commit

Permalink
Make error message for missing fixture easier to understand.
Browse files Browse the repository at this point in the history
Telling both the class, fixture reference and test case will help
people solve problems a bit quicker.
  • Loading branch information
markstory committed Jan 11, 2014
1 parent b52059a commit a454332
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/TestSuite/Fixture/FixtureManager.php
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit a454332

Please sign in to comment.