Permalink
Browse files

Added exception and message to previous exceptions and cleaned up #586

  • Loading branch information...
1 parent 2711e9d commit 33a4042f63993738cb7dd9330b0be0474481bfcf @edorian edorian committed Jul 27, 2012
Showing with 32 additions and 17 deletions.
  1. +1 −0 PHPUnit/TextUI/ResultPrinter.php
  2. +19 −6 Tests/TextUI/exception-stack.phpt
  3. +12 −11 Tests/_files/ExceptionStack.php
@@ -279,6 +279,7 @@ protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect)
while ($e) {
$this->write(
"\nCaused by\n" .
+ PHPUnit_Framework_TestFailure::exceptionToString($e). "\n" .
PHPUnit_Util_Filter::getFilteredStacktrace($e)
);
$e = $e->getPrevious();
@@ -2,8 +2,6 @@
phpunit ExceptionStackTest ../_files/ExceptionStack.php
--FILE--
<?php
-define('PHPUNIT_TESTSUITE', TRUE);
-
$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = 'ExceptionStackTest';
$_SERVER['argv'][3] = dirname(dirname(__FILE__)) . '/_files/ExceptionStack.php';
@@ -14,13 +12,13 @@ PHPUnit_TextUI_Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann.
-E
+EE
Time: %i %s, Memory: %sMb
-There was 1 error:
+There were 2 errors:
-1) ExceptionStackTest::testAssertArrayEqualsArray
+1) ExceptionStackTest::testPrintingChildException
ExceptionStackTestException: Child exception
message
Failed asserting that two arrays are equal.
@@ -37,6 +35,21 @@ Failed asserting that two arrays are equal.
Caused by
%s:%i
+2) ExceptionStackTest::testNestedExceptions
+Exception: One
+
+%s:%i
+
+Caused by
+InvalidArgumentException: Two
+
+%s:%i
+
+Caused by
+Exception: Three
+
+%s:%i
+
FAILURES!
-Tests: 1, Assertions: 1, Errors: 1.
+Tests: 2, Assertions: 1, Errors: 2.
@@ -3,20 +3,21 @@ class ExceptionStackTestException extends Exception { }
class ExceptionStackTest extends PHPUnit_Framework_TestCase
{
- public function testAssertArrayEqualsArray()
+ public function testPrintingChildException()
{
try {
$this->assertEquals(array(1), array(2), 'message');
- } catch (PHPUnit_Framework_ExpectationFailedException $e) {
- $comp = $e->getComparisonFailure();
- $msg = $e->getMessage();
- if ($comp) {
- $msg = "$msg\n" . $comp->getDiff();
- }
- $newe = new ExceptionStackTestException("Child exception\n$msg", 101, $e);
- //$newe = new ExceptionStackTestException("Child exception\n$msg", 101);
- throw $newe;
+ } catch (PHPUnit_Framework_ExpectationFailedException $e) {
+ $message = $e->getMessage() . "\n" . $e->getComparisonFailure()->getDiff();
+ throw new ExceptionStackTestException("Child exception\n$message", 101, $e);
}
- }
+ }
+ public function testNestedExceptions()
+ {
+ $exceptionThree = new Exception('Three');
+ $exceptionTwo = new InvalidArgumentException('Two', 0, $exceptionThree);
+ $exceptionOne = new Exception('One', 0, $exceptionTwo);
+ throw $exceptionOne;
+ }
}

0 comments on commit 33a4042

Please sign in to comment.