Skip to content

Commit 14b4960

Browse files
Jean85stof
authored andcommitted
Add support for Phpunit 10
1 parent 9f26c22 commit 14b4960

File tree

12 files changed

+72
-6
lines changed

12 files changed

+72
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor
22
composer.lock
33
phpunit.xml
4+
.*.cache

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 2.1.0 / TBA
2+
3+
Add support for PHPUnit 10.1+ (10.0 is not supported)
4+
Bump requirement to Prophecy 1.18+
5+
16
# 2.0.2 / 2023-04-18
27

38
Add the `@not-deprecated` annotation to avoid phpstan reporting `prophesize` as deprecated due to the TestCase deprecation.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"prefer-stable": true,
1616
"require": {
1717
"php": "^7.3 || ^8",
18-
"phpspec/prophecy": "^1.3",
19-
"phpunit/phpunit":"^9.1"
18+
"phpspec/prophecy": "^1.18",
19+
"phpunit/phpunit":"^9.1 || ^10.1"
2020
},
2121
"autoload": {
2222
"psr-4": {

fixtures/NoClass.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Prophecy\PhpUnit\Tests\Fixtures;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Prophecy\PhpUnit\ProphecyTrait;
7+
8+
class NoClass extends TestCase
9+
{
10+
use ProphecyTrait;
11+
12+
public function testProphesizeWithoutArguments(): void
13+
{
14+
$prophecy = $this->prophesize()->reveal();
15+
16+
$this->assertInstanceOf(\stdClass::class, $prophecy);
17+
}
18+
}

src/ProphecyTrait.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ trait ProphecyTrait
3939
*/
4040
protected function prophesize(?string $classOrInterface = null): ObjectProphecy
4141
{
42-
if (\is_string($classOrInterface)) {
42+
static $isPhpUnit9;
43+
$isPhpUnit9 = $isPhpUnit9 ?? method_exists($this, 'recordDoubledType');
44+
45+
if (! $isPhpUnit9) {
46+
// PHPUnit 10.1
47+
$this->registerFailureType(PredictionException::class);
48+
} elseif (\is_string($classOrInterface)) {
49+
// PHPUnit 9
4350
\assert($this instanceof TestCase);
4451
$this->recordDoubledType($classOrInterface);
4552
}

tests/MockFailure.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ require_once __DIR__ . '/run_test.php';
99
--EXPECTF--
1010
PHPUnit %s
1111

12+
Runtime: %s
13+
1214
F %s 1 / 1 (100%)
1315

1416
Time: %s

tests/NoClass.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
A test with a Prophecy called without any argument
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/run_test.php';
7+
8+
\Prophecy\PhpUnit\Tests\runTest('NoClass');
9+
--EXPECTF--
10+
PHPUnit %s
11+
12+
Runtime: %s
13+
14+
. %s 1 / 1 (100%)
15+
16+
Time: %s
17+
18+
OK (1 test, 1 assertion)

tests/NoProphecy.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ require_once __DIR__ . '/run_test.php';
99
--EXPECTF--
1010
PHPUnit %s
1111

12+
Runtime: %s
13+
1214
. %s 1 / 1 (100%)
1315

1416
Time: %s

tests/SpyFailure.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ require_once __DIR__ . '/run_test.php';
99
--EXPECTF--
1010
PHPUnit %s
1111

12+
Runtime: %s
13+
1214
F %s 1 / 1 (100%)
1315

1416
Time: %a
1517

1618
There was 1 failure:
1719

1820
1) Prophecy\PhpUnit\Tests\Fixtures\SpyFailure::testMethod
19-
No calls have been made that match:
21+
%ao calls have been made that match:
2022
Double\DateTime\P1->format(exact("Y-m-d"))
2123
but expected at least one.
2224

23-
%s/tests/run_test.php:%d
25+
%a/tests/run_test.php:%d
2426

2527
FAILURES!
2628
Tests: 1, Assertions: 1, Failures: 1.

tests/Success.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ require_once __DIR__ . '/run_test.php';
99
--EXPECTF--
1010
PHPUnit %s
1111

12+
Runtime: %s
13+
1214
. %s 1 / 1 (100%)
1315

1416
Time: %s

0 commit comments

Comments
 (0)