diff --git a/.travis.yml b/.travis.yml index 46ac9a0..2e19896 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,9 @@ language: php sudo: false php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - hhvm + - 7.3 + - 7.4 install: composer install -script: phpunit --coverage-text +script: ./vendor/bin/phpunit --coverage-text diff --git a/ProphecyTestCase.php b/ProphecyTestCase.php index 2229677..4e21da5 100644 --- a/ProphecyTestCase.php +++ b/ProphecyTestCase.php @@ -1,51 +1,64 @@ -recordDoubledType($classOrInterface); + } + return $this->getProphet()->prophesize($classOrInterface); } - protected function verifyMockObjects() + protected function verifyMockObjects(): void { parent::verifyMockObjects(); - if (null === $this->prophet) { + if ($this->prophet === null) { return; } try { $this->prophet->checkPredictions(); - } catch (\Exception $e) { - /** Intentionally left empty */ - } - - $this->countProphecyAssertions(); - - if (isset($e)) { - throw $e; + } catch (PredictionException $e) { + throw new AssertionFailedError($e->getMessage()); + } finally { + $this->countProphecyAssertions(); } } - protected function tearDown() + /** + * @after + */ + protected function prophecyTearDown(): void { if (null !== $this->prophet && !$this->prophecyAssertionsCounted) { // Some Prophecy assertions may have been done in tests themselves even when a failure happened before checking mock objects. @@ -55,37 +68,27 @@ protected function tearDown() $this->prophet = null; } - protected function onNotSuccessfulTest(\Exception $e) - { - if ($e instanceof PredictionException) { - $e = new \PHPUnit_Framework_AssertionFailedError($e->getMessage(), $e->getCode(), $e); - } - - return parent::onNotSuccessfulTest($e); - } - - /** - * @return Prophet - */ - private function getProphet() - { - if (null === $this->prophet) { - $this->prophet = new Prophet(); - } - - return $this->prophet; - } - - private function countProphecyAssertions() + private function countProphecyAssertions(): void { $this->prophecyAssertionsCounted = true; foreach ($this->prophet->getProphecies() as $objectProphecy) { foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) { foreach ($methodProphecies as $methodProphecy) { - $this->addToAssertionCount(count($methodProphecy->getCheckedPredictions())); + \assert($methodProphecy instanceof MethodProphecy); + + $this->addToAssertionCount(\count($methodProphecy->getCheckedPredictions())); } } } } + + private function getProphet(): Prophet + { + if ($this->prophet === null) { + $this->prophet = new Prophet; + } + + return $this->prophet; + } } diff --git a/Tests/ProphecyTestCaseTest.php b/Tests/ProphecyTestCaseTest.php index 0750d16..74b0d6e 100644 --- a/Tests/ProphecyTestCaseTest.php +++ b/Tests/ProphecyTestCaseTest.php @@ -1,63 +1,71 @@ -run(); - $this->assertEquals(0, $result->errorCount()); - $this->assertEquals(0, $result->failureCount()); + $this->assertSame(0, $result->errorCount()); + $this->assertSame(0, $result->failureCount()); $this->assertCount(1, $result); - $this->assertEquals(1, $test->getNumAssertions()); + $this->assertSame(1, $test->getNumAssertions()); } - public function testSpyPredictionFailure() + public function testSpyPredictionFailure(): void { $test = new SpyFailure('testMethod'); + $result = $test->run(); - $this->assertEquals(0, $result->errorCount()); - $this->assertEquals(1, $result->failureCount()); + $this->assertSame(0, $result->errorCount()); + $this->assertSame(1, $result->failureCount()); $this->assertCount(1, $result); - $this->assertEquals(1, $test->getNumAssertions()); + $this->assertSame(1, $test->getNumAssertions()); } - public function testMockPredictionFailure() + public function testMockPredictionFailure(): void { $test = new MockFailure('testMethod'); + $result = $test->run(); - $this->assertEquals(0, $result->errorCount()); - $this->assertEquals(1, $result->failureCount()); + $this->assertSame(0, $result->errorCount()); + $this->assertSame(1, $result->failureCount()); $this->assertCount(1, $result); - $this->assertEquals(1, $test->getNumAssertions()); + $this->assertSame(1, $test->getNumAssertions()); } - public function testDoublingError() + public function testDoublingError(): void { $test = new Error('testMethod'); + $result = $test->run(); - $this->assertEquals(1, $result->errorCount()); - $this->assertEquals(0, $result->failureCount()); + $this->assertSame(1, $result->errorCount()); + $this->assertSame(0, $result->failureCount()); $this->assertCount(1, $result); - $this->assertEquals(0, $test->getNumAssertions()); + $this->assertSame(0, $test->getNumAssertions()); } } diff --git a/composer.json b/composer.json index 6937d75..6490597 100644 --- a/composer.json +++ b/composer.json @@ -11,12 +11,12 @@ "email": "stof@notk.org" } ], + "minimum-stability": "dev", + "prefer-stable": true, "require": { - "php": ">=5.3.3", - "phpspec/prophecy": "~1.3" - }, - "suggest": { - "phpunit/phpunit": "if it is not installed globally" + "php": "^7.3", + "phpspec/prophecy": "^1.3", + "phpunit/phpunit":"^9.1" }, "autoload": { "psr-4": { @@ -25,7 +25,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0-dev" } } }