Skip to content

Commit 3711b0e

Browse files
committed
Update to PHPUnit 7.5+
1 parent 330e730 commit 3711b0e

File tree

4 files changed

+16
-27
lines changed

4 files changed

+16
-27
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"react/promise": "^2.8 || ^1.2.1"
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": "^9.3 || ^5.7"
34+
"phpunit/phpunit": "^9.3 || ^7.5"
3535
},
3636
"autoload": {
3737
"files": [

phpunit.xml.legacy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
66
bootstrap="vendor/autoload.php"
77
colors="true">
88
<testsuites>

tests/AwaitTest.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public function testAwaitThrowsExceptionWhenPromiseIsRejectedWithException()
1414
throw new \Exception('test');
1515
});
1616

17-
$this->setExpectedException('Exception', 'test');
17+
$this->expectException(\Exception::class);
18+
$this->expectExceptionMessage('test');
1819
React\Async\await($promise);
1920
}
2021

@@ -28,7 +29,8 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith
2829
$reject(false);
2930
});
3031

31-
$this->setExpectedException('UnexpectedValueException', 'Promise rejected with unexpected value of type bool');
32+
$this->expectException(\UnexpectedValueException::class);
33+
$this->expectExceptionMessage('Promise rejected with unexpected value of type bool');
3234
React\Async\await($promise);
3335
}
3436

@@ -42,7 +44,8 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith
4244
$reject(null);
4345
});
4446

45-
$this->setExpectedException('UnexpectedValueException', 'Promise rejected with unexpected value of type NULL');
47+
$this->expectException(\UnexpectedValueException::class);
48+
$this->expectExceptionMessage('Promise rejected with unexpected value of type NULL');
4649
React\Async\await($promise);
4750
}
4851

@@ -52,7 +55,9 @@ public function testAwaitThrowsErrorWhenPromiseIsRejectedWithError()
5255
throw new \Error('Test', 42);
5356
});
5457

55-
$this->setExpectedException('Error', 'Test', 42);
58+
$this->expectException(\Error::class);
59+
$this->expectExceptionMessage('Test');
60+
$this->expectExceptionCode(42);
5661
React\Async\await($promise);
5762
}
5863

@@ -141,21 +146,4 @@ public function testAwaitShouldNotCreateAnyGarbageReferencesForPromiseRejectedWi
141146

142147
$this->assertEquals(0, gc_collect_cycles());
143148
}
144-
145-
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
146-
{
147-
if (method_exists($this, 'expectException')) {
148-
// PHPUnit 5+
149-
$this->expectException($exception);
150-
if ($exceptionMessage !== '') {
151-
$this->expectExceptionMessage($exceptionMessage);
152-
}
153-
if ($exceptionCode !== null) {
154-
$this->expectExceptionCode($exceptionCode);
155-
}
156-
} else {
157-
// legacy PHPUnit 4
158-
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
159-
}
160-
}
161149
}

tests/TestCase.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace React\Tests\Async;
44

5+
use PHPUnit\Framework\MockObject\MockBuilder;
56
use PHPUnit\Framework\TestCase as BaseTestCase;
67

78
class TestCase extends BaseTestCase
@@ -39,12 +40,12 @@ protected function expectCallableNever()
3940

4041
protected function createCallableMock()
4142
{
42-
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
43+
if (method_exists(MockBuilder::class, 'addMethods')) {
4344
// PHPUnit 9+
44-
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
45+
return $this->getMockBuilder(\stdClass::class)->addMethods(['__invoke'])->getMock();
4546
} else {
46-
// legacy PHPUnit 4 - PHPUnit 8
47-
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
47+
// PHPUnit < 9
48+
return $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock();
4849
}
4950
}
5051
}

0 commit comments

Comments
 (0)