Skip to content

Commit 0ea2fb4

Browse files
authored
Maintenance: support phpunit v12 & php-text-template v5 (#11)
1 parent 642b288 commit 0ea2fb4

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

Diff for: composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"require": {
2424
"php": ">=5.6",
2525
"php-mock/php-mock": "^2.5",
26-
"phpunit/php-text-template": "^1 || ^2 || ^3 || ^4"
26+
"phpunit/php-text-template": "^1 || ^2 || ^3 || ^4 || ^5"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "^5.7.27 || ^6 || ^7 || ^8 || ^9 || ^10 || ^11"
29+
"phpunit/phpunit": "^5.7.27 || ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12"
3030
},
3131
"archive": {
3232
"exclude": ["/tests"]

Diff for: tests/MockDelegateFunctionBuilderTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public function testSameSignaturesProduceSameClass()
7171
*
7272
* @doesNotPerformAssertions
7373
*/
74+
#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
75+
#[\PHPUnit\Framework\Attributes\DataProvider('provideTestBackupStaticAttributes')]
76+
#[\PHPUnit\Framework\Attributes\BackupStaticProperties(true)]
7477
public function testBackupStaticAttributes()
7578
{
7679
$builder = new MockDelegateFunctionBuilder();
@@ -97,12 +100,14 @@ public static function provideTestBackupStaticAttributes()
97100
*
98101
* @doesNotPerformAssertions
99102
*/
103+
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
104+
#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
100105
public function testDeserializationInNewProcess()
101106
{
102107
$builder = new MockDelegateFunctionBuilder();
103108
$builder->build("min");
104109

105-
$data = serialize($this->getMockForAbstractClass($builder->getFullyQualifiedClassName()));
110+
$data = serialize($this->getMockBuilder($builder->getFullyQualifiedClassName())->getMock());
106111

107112
unserialize($data);
108113
}

Diff for: tests/MockDelegateFunctionTest.php

+26-6
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@ protected function setUpCompat()
3535
*
3636
* @test
3737
*/
38+
#[\PHPUnit\Framework\Attributes\Test]
3839
public function testDelegateReturnsMockResult()
3940
{
40-
$expected = 3;
41-
$mock = $this->getMockForAbstractClass($this->className);
42-
41+
$expected = 3;
42+
$mockBuilder = $this->getMockBuilder($this->className);
43+
44+
// `setMethods` is gone from phpunit 10, alternative is `onlyMethods`
45+
if (method_exists($mockBuilder, 'onlyMethods')) {
46+
$mockBuilder->onlyMethods([MockDelegateFunctionBuilder::METHOD]);
47+
} else {
48+
$mockBuilder->setMethods([MockDelegateFunctionBuilder::METHOD]);
49+
}
50+
51+
$mock = $mockBuilder->getMock();
52+
4353
$mock->expects($this->once())
4454
->method(MockDelegateFunctionBuilder::METHOD)
4555
->willReturn($expected);
@@ -53,14 +63,24 @@ public function testDelegateReturnsMockResult()
5363
*
5464
* @test
5565
*/
66+
#[\PHPUnit\Framework\Attributes\Test]
5667
public function testDelegateForwardsArguments()
5768
{
58-
$mock = $this->getMockForAbstractClass($this->className);
59-
69+
$mockBuilder = $this->getMockBuilder($this->className);
70+
71+
// `setMethods` is gone from phpunit 10, alternative is `onlyMethods`
72+
if (method_exists($mockBuilder, 'onlyMethods')) {
73+
$mockBuilder->onlyMethods([MockDelegateFunctionBuilder::METHOD]);
74+
} else {
75+
$mockBuilder->setMethods([MockDelegateFunctionBuilder::METHOD]);
76+
}
77+
78+
$mock = $mockBuilder->getMock();
79+
6080
$mock->expects($this->once())
6181
->method(MockDelegateFunctionBuilder::METHOD)
6282
->with(1, 2);
63-
83+
6484
call_user_func($mock->getCallable(), 1, 2);
6585
}
6686
}

0 commit comments

Comments
 (0)