From 984d4a30453c4c1f53080e8752578f7f57647280 Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sun, 14 Dec 2014 17:51:26 +1100 Subject: [PATCH 1/3] testSuccessfulVerifyReturnsTrue --- src/Concise/TestCase.php | 8 ++++++++ tests/Concise/VerifyTest.php | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/Concise/VerifyTest.php diff --git a/src/Concise/TestCase.php b/src/Concise/TestCase.php index f6939fcb..dc02610f 100644 --- a/src/Concise/TestCase.php +++ b/src/Concise/TestCase.php @@ -274,4 +274,12 @@ public function assertMock(MockInterface $mock) $this->mockManager->validateMockByInstance($mock); return true; } + + /** + * @return bool + */ + public function verify() + { + return true; + } } diff --git a/tests/Concise/VerifyTest.php b/tests/Concise/VerifyTest.php new file mode 100644 index 00000000..f82c6215 --- /dev/null +++ b/tests/Concise/VerifyTest.php @@ -0,0 +1,14 @@ +assert($this->verify(true), is_true); + } +} From 1204786252027eb0101c532a4ca3abea87425f83 Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sun, 14 Dec 2014 18:42:08 +1100 Subject: [PATCH 2/3] testMultipleVerifyFailures --- src/Concise/TestCase.php | 22 ++++++++++++--- tests/Concise/VerifyFailuresTest.php | 41 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 tests/Concise/VerifyFailuresTest.php diff --git a/src/Concise/TestCase.php b/src/Concise/TestCase.php index dc02610f..0e4d44e1 100644 --- a/src/Concise/TestCase.php +++ b/src/Concise/TestCase.php @@ -8,6 +8,7 @@ use Concise\Mock\MockManager; use Concise\Validation\ArgumentChecker; use Exception; +use PHPUnit_Framework_AssertionFailedError; use PHPUnit_Framework_TestCase; use ReflectionClass; use Concise\Mock\MockInterface; @@ -33,6 +34,11 @@ class TestCase extends PHPUnit_Framework_TestCase */ protected $properties = array(); + /** + * @var array + */ + protected $verifyFailures = array(); + /** * @param string|null $name * @param array $data @@ -161,6 +167,12 @@ public function assert() public function tearDown() { $this->mockManager->validateMocks(); + if ($this->verifyFailures) { + $count = count($this->verifyFailures); + $message = "$count verify failure" . ($count === 1 ? '' : 's') . ":"; + $message .= "\n\n" . implode("\n\n", $this->verifyFailures); + throw new PHPUnit_Framework_AssertionFailedError($message); + } parent::tearDown(); } @@ -218,12 +230,10 @@ protected function loadKeywords() define('on_error', 'on error'); } - /** - * This looks useless but we need to change the visibility of setUp() to public. - */ public function setUp() { parent::setUp(); + $this->verifyFailures = array(); } /** @@ -280,6 +290,10 @@ public function assertMock(MockInterface $mock) */ public function verify() { - return true; + try { + call_user_func_array(array($this, 'assert'), func_get_args()); + } catch (PHPUnit_Framework_AssertionFailedError $e) { + $this->verifyFailures[] = $e->getMessage(); + } } } diff --git a/tests/Concise/VerifyFailuresTest.php b/tests/Concise/VerifyFailuresTest.php new file mode 100644 index 00000000..c417b87f --- /dev/null +++ b/tests/Concise/VerifyFailuresTest.php @@ -0,0 +1,41 @@ + "2 verify failures:\n\n10 equals 15\n\n15 equals 20", + ); + + /** + * @group #216 + */ + public function testMultipleVerifyFailures() + { + $this->verify(10, equals, 15); + $this->verify(15, equals, 20); + } + + protected function onNotSuccessfulTest(\Exception $e) + { + $c = new Color(); + self::$failures[] = $this->getName(); + $this->assert(self::$expectedFailures[$this->getName()], equals, $c($e->getMessage())->clean()); + } + + public static function tearDownAfterClass() + { + $a = array_keys(self::$expectedFailures); + $b = self::$failures; + $testCase = new TestCase(); + $testCase->setUp(); + $testCase->assert(array_diff($a, $b), equals, array_diff($b, $a)); + $testCase->tearDown(); + } +} From d60acbeb5bd7efa6716e7425eb74fcc613d16d52 Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sun, 14 Dec 2014 18:43:36 +1100 Subject: [PATCH 3/3] testSingleVerifyFailures --- tests/Concise/VerifyFailuresTest.php | 9 +++++++++ tests/Concise/VerifyTest.php | 14 -------------- 2 files changed, 9 insertions(+), 14 deletions(-) delete mode 100644 tests/Concise/VerifyTest.php diff --git a/tests/Concise/VerifyFailuresTest.php b/tests/Concise/VerifyFailuresTest.php index c417b87f..1686dfcf 100644 --- a/tests/Concise/VerifyFailuresTest.php +++ b/tests/Concise/VerifyFailuresTest.php @@ -11,6 +11,7 @@ class VerifyFailuresTest extends TestCase protected static $expectedFailures = array( 'testMultipleVerifyFailures' => "2 verify failures:\n\n10 equals 15\n\n15 equals 20", + 'testSingleVerifyFailures' => "1 verify failure:\n\n10 equals 15", ); /** @@ -22,6 +23,14 @@ public function testMultipleVerifyFailures() $this->verify(15, equals, 20); } + /** + * @group #216 + */ + public function testSingleVerifyFailures() + { + $this->verify(10, equals, 15); + } + protected function onNotSuccessfulTest(\Exception $e) { $c = new Color(); diff --git a/tests/Concise/VerifyTest.php b/tests/Concise/VerifyTest.php deleted file mode 100644 index f82c6215..00000000 --- a/tests/Concise/VerifyTest.php +++ /dev/null @@ -1,14 +0,0 @@ -assert($this->verify(true), is_true); - } -}