diff --git a/composer.json b/composer.json index 2c48d3b..8098af3 100644 --- a/composer.json +++ b/composer.json @@ -14,10 +14,16 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": "^7.3 || ^8", - "phpspec/prophecy": "^1.3", - "phpunit/phpunit":"^9.1" + "php": "^8.1", + "phpspec/prophecy": "dev-allow-sebastian-comparator-5 as 1.15", + "phpunit/phpunit": "^10.0.x-dev" }, + "repositories": [ + { + "type": "github", + "url": "https://github.com/Jean85/prophecy" + } + ], "autoload": { "psr-4": { "Prophecy\\PhpUnit\\": "src" diff --git a/fixtures/NoProphecy.php b/fixtures/NoProphecy.php new file mode 100644 index 0000000..a153d3e --- /dev/null +++ b/fixtures/NoProphecy.php @@ -0,0 +1,16 @@ +assertTrue(true); + } +} diff --git a/fixtures/Error.php b/fixtures/WrongCall.php similarity index 90% rename from fixtures/Error.php rename to fixtures/WrongCall.php index e951786..4327fdc 100644 --- a/fixtures/Error.php +++ b/fixtures/WrongCall.php @@ -5,7 +5,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; -class Error extends TestCase +class WrongCall extends TestCase { use ProphecyTrait; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9c251d1..2cfa33d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,15 +1,18 @@ - - - - - ./tests/ - - - - - - ./src - - + + + + ./tests/ + + + + + ./src + + diff --git a/src/ProphecyTrait.php b/src/ProphecyTrait.php index 7fb7d54..a9a873e 100644 --- a/src/ProphecyTrait.php +++ b/src/ProphecyTrait.php @@ -38,11 +38,6 @@ trait ProphecyTrait */ protected function prophesize(?string $classOrInterface = null): ObjectProphecy { - if (\is_string($classOrInterface)) { - \assert($this instanceof TestCase); - $this->recordDoubledType($classOrInterface); - } - return $this->getProphet()->prophesize($classOrInterface); } diff --git a/tests/MockFailure.phpt b/tests/MockFailure.phpt new file mode 100644 index 0000000..c674d48 --- /dev/null +++ b/tests/MockFailure.phpt @@ -0,0 +1,31 @@ +--TEST-- +A test with a mock fails due to a missing expected call +--FILE-- +run(['phpunit', 'fixtures/MockFailure.php', '--no-progress'], false); +--EXPECTF-- +PHPUnit 10.%s + +Runtime: PHP 8.%s +Configuration: %s + +Time: %s + +There was 1 failure: + +1) Prophecy\PhpUnit\Tests\Fixtures\MockFailure::testMethod +Some predictions failed: +Double\DateTime\P1: + Expected exactly 2 calls that match: + Double\DateTime\P1->format(exact("Y-m-d")) + but 1 were made: + - format("Y-m-d") @ fixtures/MockFailure.php:%d + +%s/src/ProphecyTrait.php:%d + +FAILURES! +Tests: 1, Assertions: 1, Failures: 1. diff --git a/tests/NoProphecy.phpt b/tests/NoProphecy.phpt new file mode 100644 index 0000000..5da5b72 --- /dev/null +++ b/tests/NoProphecy.phpt @@ -0,0 +1,18 @@ +--TEST-- +A test without Prophecy is executed with no additional assertions counted +--FILE-- +run(['phpunit', 'fixtures/NoProphecy.php', '--no-progress'], false); +--EXPECTF-- +PHPUnit 10.%s + +Runtime: PHP 8.%s +Configuration: %s + +Time: %s + +OK (1 test, 1 assertion) diff --git a/tests/ProphecyTraitTest.php b/tests/ProphecyTraitTest.php deleted file mode 100644 index 6e6a168..0000000 --- a/tests/ProphecyTraitTest.php +++ /dev/null @@ -1,76 +0,0 @@ -run(); - - $this->assertSame(0, $result->errorCount()); - $this->assertSame(0, $result->failureCount()); - $this->assertCount(1, $result); - $this->assertSame(1, $test->getNumAssertions()); - $this->assertSame(BaseTestRunner::STATUS_PASSED, $test->getStatus()); - } - - public function testSpyPredictionFailure(): void - { - $test = new SpyFailure('testMethod'); - - $result = $test->run(); - - $this->assertSame(0, $result->errorCount()); - $this->assertSame(1, $result->failureCount()); - $this->assertCount(1, $result); - $this->assertSame(1, $test->getNumAssertions()); - $this->assertSame(BaseTestRunner::STATUS_FAILURE, $test->getStatus()); - } - - public function testMockPredictionFailure(): void - { - $test = new MockFailure('testMethod'); - - $result = $test->run(); - - $this->assertSame(0, $result->errorCount()); - $this->assertSame(1, $result->failureCount()); - $this->assertCount(1, $result); - $this->assertSame(1, $test->getNumAssertions()); - $this->assertSame(BaseTestRunner::STATUS_FAILURE, $test->getStatus()); - } - - public function testDoublingError(): void - { - $test = new Error('testMethod'); - - $result = $test->run(); - - $this->assertSame(1, $result->errorCount()); - $this->assertSame(0, $result->failureCount()); - $this->assertCount(1, $result); - $this->assertSame(0, $test->getNumAssertions()); - $this->assertSame(BaseTestRunner::STATUS_ERROR, $test->getStatus()); - } -} diff --git a/tests/SpyFailure.phpt b/tests/SpyFailure.phpt new file mode 100644 index 0000000..661dd95 --- /dev/null +++ b/tests/SpyFailure.phpt @@ -0,0 +1,28 @@ +--TEST-- +A test with a spy fails due to expected call not made +--FILE-- +run(['phpunit', 'fixtures/SpyFailure.php', '--no-progress'], false); +--EXPECTF-- +PHPUnit 10.%s + +Runtime: PHP 8.%s +Configuration: %s + +Time: %s + +There was 1 error: + +1) Prophecy\PhpUnit\Tests\Fixtures\SpyFailure::testMethod +Prophecy\Exception\Prediction\NoCallsException: No calls have been made that match: + Double\DateTime\P1->format(exact("Y-m-d")) +but expected at least one. + +%a%s/fixtures/SpyFailure.php:%d + +ERRORS! +Tests: 1, Assertions: 1, Errors: 1. diff --git a/tests/Success.phpt b/tests/Success.phpt new file mode 100644 index 0000000..0882f43 --- /dev/null +++ b/tests/Success.phpt @@ -0,0 +1,18 @@ +--TEST-- +A test with a mock is executed successfully +--FILE-- +run(['phpunit', 'fixtures/Success.php', '--no-progress'], false); +--EXPECTF-- +PHPUnit 10.%s + +Runtime: PHP 8.%s +Configuration: %s + +Time: %s + +OK (1 test, 1 assertion) diff --git a/tests/WrongCall.phpt b/tests/WrongCall.phpt new file mode 100644 index 0000000..9b30437 --- /dev/null +++ b/tests/WrongCall.phpt @@ -0,0 +1,26 @@ +--TEST-- +A test fails due to calling an unexisting method on a mock +--FILE-- +run(['phpunit', 'fixtures/WrongCall.php', '--no-progress'], false); +--EXPECTF-- +PHPUnit 10.%s + +Runtime: PHP 8.%s +Configuration: %s + +Time: %s + +There was 1 error: + +1) Prophecy\PhpUnit\Tests\Fixtures\WrongCall::testMethod +Prophecy\Exception\Doubler\MethodNotFoundException: Method `Double\stdClass\P1::talk()` is not defined. + +%a%s/fixtures/WrongCall.php:%d + +ERRORS! +Tests: 1, Assertions: 0, Errors: 1. diff --git a/xdebug_filter.php b/xdebug_filter.php new file mode 100644 index 0000000..6cb12dd --- /dev/null +++ b/xdebug_filter.php @@ -0,0 +1,13 @@ +