Permalink
Browse files

Adding test for TextUi when tests use an exception stack

  • Loading branch information...
1 parent eea6710 commit e3ea6c05259f19fdf58c4c0c485de7f9b3d44cee @matheusd matheusd committed Jun 8, 2012
Showing with 64 additions and 0 deletions.
  1. +42 −0 Tests/TextUI/exception-stack.phpt
  2. +22 −0 Tests/_files/ExceptionStack.php
@@ -0,0 +1,42 @@
+--TEST--
+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';
+
+require_once dirname(dirname(dirname(__FILE__))) . '/PHPUnit/Autoload.php';
+PHPUnit_TextUI_Command::main();
+?>
+--EXPECTF--
+PHPUnit %s by Sebastian Bergmann.
+
+E
+
+Time: %i %s, Memory: %sMb
+
+There was 1 error:
+
+1) ExceptionStackTest::testAssertArrayEqualsArray
+ExceptionStackTestException: Child exception
+message
+Failed asserting that two arrays are equal.
+--- Expected
++++ Actual
+@@ @@
+ Array (
+- 0 => 1
++ 0 => 2
+ )
+
+%s:%i
+
+Caused by
+%s:%i
+
+FAILURES!
+Tests: 1, Assertions: 1, Errors: 1.
+
@@ -0,0 +1,22 @@
+<?php
+class ExceptionStackTestException extends Exception { }
+
+class ExceptionStackTest extends PHPUnit_Framework_TestCase
+{
+ public function testAssertArrayEqualsArray()
+ {
+ 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;
+ }
+ }
+
+}

0 comments on commit e3ea6c0

Please sign in to comment.