diff --git a/.gitignore b/.gitignore index a79486f..9d98656 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor composer.lock phpunit.xml +.*.cache diff --git a/CHANGES.md b/CHANGES.md index 15111e6..8c87a5d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +# 2.1.0 / TBA + +Add support for PHPUnit 10.1+ (10.0 is not supported) +Bump requirement to Prophecy 1.18+ + # 2.0.2 / 2023-04-18 Add the `@not-deprecated` annotation to avoid phpstan reporting `prophesize` as deprecated due to the TestCase deprecation. diff --git a/composer.json b/composer.json index 2c48d3b..83a8818 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ "prefer-stable": true, "require": { "php": "^7.3 || ^8", - "phpspec/prophecy": "^1.3", - "phpunit/phpunit":"^9.1" + "phpspec/prophecy": "^1.18", + "phpunit/phpunit":"^9.1 || ^10.1" }, "autoload": { "psr-4": { diff --git a/fixtures/NoClass.php b/fixtures/NoClass.php new file mode 100644 index 0000000..c4494b8 --- /dev/null +++ b/fixtures/NoClass.php @@ -0,0 +1,18 @@ +prophesize()->reveal(); + + $this->assertInstanceOf(\stdClass::class, $prophecy); + } +} diff --git a/src/ProphecyTrait.php b/src/ProphecyTrait.php index 34ff25d..494c228 100644 --- a/src/ProphecyTrait.php +++ b/src/ProphecyTrait.php @@ -39,7 +39,14 @@ trait ProphecyTrait */ protected function prophesize(?string $classOrInterface = null): ObjectProphecy { - if (\is_string($classOrInterface)) { + static $isPhpUnit9; + $isPhpUnit9 = $isPhpUnit9 ?? method_exists($this, 'recordDoubledType'); + + if (! $isPhpUnit9) { + // PHPUnit 10.1 + $this->registerFailureType(PredictionException::class); + } elseif (\is_string($classOrInterface)) { + // PHPUnit 9 \assert($this instanceof TestCase); $this->recordDoubledType($classOrInterface); } diff --git a/tests/MockFailure.phpt b/tests/MockFailure.phpt index b80a873..8fd1853 100644 --- a/tests/MockFailure.phpt +++ b/tests/MockFailure.phpt @@ -9,6 +9,8 @@ require_once __DIR__ . '/run_test.php'; --EXPECTF-- PHPUnit %s +Runtime: %s + F %s 1 / 1 (100%) Time: %s diff --git a/tests/NoClass.phpt b/tests/NoClass.phpt new file mode 100644 index 0000000..e9db4f5 --- /dev/null +++ b/tests/NoClass.phpt @@ -0,0 +1,18 @@ +--TEST-- +A test with a Prophecy called without any argument +--FILE-- +format(exact("Y-m-d")) but expected at least one. -%s/tests/run_test.php:%d +%a/tests/run_test.php:%d FAILURES! Tests: 1, Assertions: 1, Failures: 1. diff --git a/tests/Success.phpt b/tests/Success.phpt index 84a7c64..4e12439 100644 --- a/tests/Success.phpt +++ b/tests/Success.phpt @@ -9,6 +9,8 @@ require_once __DIR__ . '/run_test.php'; --EXPECTF-- PHPUnit %s +Runtime: %s + . %s 1 / 1 (100%) Time: %s diff --git a/tests/WrongCall.phpt b/tests/WrongCall.phpt index 0485d3f..9831304 100644 --- a/tests/WrongCall.phpt +++ b/tests/WrongCall.phpt @@ -9,6 +9,8 @@ require_once __DIR__ . '/run_test.php'; --EXPECTF-- PHPUnit %s +Runtime: %s + E %s 1 / 1 (100%) Time: %a diff --git a/tests/run_test.php b/tests/run_test.php index 71540d3..5f1ec63 100644 --- a/tests/run_test.php +++ b/tests/run_test.php @@ -2,6 +2,7 @@ namespace Prophecy\PhpUnit\Tests; +use PHPUnit\TextUI\Application; use PHPUnit\TextUI\Command; require_once __DIR__ . '/xdebug_filter.php'; @@ -14,5 +15,11 @@ function runTest(string $fixtureName): void throw new \InvalidArgumentException('Unable to find test fixture at path ' . $filename); } - (new Command())->run(['phpunit', $filename], false); + if (class_exists(Command::class)) { + // PHPUnit 9.x + (new Command())->run(['phpunit', $filename, '--verbose', '--no-configuration'], false); + } else { + // PHPUnit 10.x + (new Application())->run(['phpunit', $filename, '--no-configuration']); + } }