Browse Source

Merge pull request #8171 from burzum/better-exceptions-fixture-manager

Improving the exception messages for the FixtureManager.
Mark Story 10 years ago
parent
commit
00e82364b9
1 changed files with 19 additions and 4 deletions
  1. 19 4
      src/TestSuite/Fixture/FixtureManager.php

+ 19 - 4
src/TestSuite/Fixture/FixtureManager.php

@@ -274,7 +274,12 @@ class FixtureManager
 
                 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" in "%s" test case: ' . "\n" . '%s', get_class($fixture), get_class($test), $e->getMessage());
+                            throw new Exception($msg);
+                        }
                     }
                 }
 
@@ -287,15 +292,25 @@ class FixtureManager
                 }
 
                 foreach ($fixtures as $name => $fixture) {
-                    $fixture->createConstraints($db);
+                    try {
+                        $fixture->createConstraints($db);
+                    } catch (PDOException $e) {
+                        $msg = sprintf('Unable to create constraints for fixture "%s" in "%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" in "%s" test case: ' . "\n" . '%s', get_class($fixture), get_class($test), $e->getMessage());
+                        throw new Exception($msg);
+                    }
                 }
             };
             $this->_runOperation($fixtures, $insert);