Skip to content

Commit

Permalink
Improving the exception messages for the FixtureManager.
Browse files Browse the repository at this point in the history
Before the message was very generic and not telling you which fixture caused the failure.
  • Loading branch information
Florian Krämer committed Feb 3, 2016
1 parent 6a36f60 commit 8921661
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/TestSuite/Fixture/FixtureManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ public function load($test)

foreach ($fixtures as $name => $fixture) {
if (in_array($fixture->table, $tables)) {
$fixture->dropConstraints($db);
try {
$fixture->dropConstraints($db);
} catch (PDOException $e) {
$msg = sprintf('Unable to drop constraints for fixture "%s" for "%s" test case: ' . "\n" . '%s', get_class($fixture), get_class($test), $e->getMessage());
throw new Exception($msg);
}
}
}

Expand All @@ -287,15 +292,25 @@ public function load($test)
}

foreach ($fixtures as $name => $fixture) {
$fixture->createConstraints($db);
try {
$fixture->createConstraints($db);
} catch (PDOException $e) {
$msg = sprintf('Unable to create constriants for fixture "%s" for "%s" test case: ' . "\n" . '%s', get_class($fixture), get_class($test), $e->getMessage());
throw new Exception($msg);
}
}
};
$this->_runOperation($fixtures, $createTables);

// Use a separate transaction because of postgres.
$insert = function ($db, $fixtures) {
$insert = function ($db, $fixtures) use ($test) {
foreach ($fixtures as $fixture) {
$fixture->insert($db);
try {
$fixture->insert($db);
} catch (PDOException $e) {
$msg = sprintf('Unable to insert fixture "%s" for "%s" test case: ' . "\n" . '%s', get_class($fixture), get_class($test), $e->getMessage());
throw new Exception($msg);
}
}
};
$this->_runOperation($fixtures, $insert);
Expand Down

0 comments on commit 8921661

Please sign in to comment.