Skip to content

Commit ab60b38

Browse files
committed
Run tests on PHPUnit 9
1 parent dcaa8f9 commit ab60b38

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
},
2323
"require-dev": {
2424
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
25-
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.7 || ^4.8.35"
25+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
2626
}
2727
}

tests/DecoderTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ class DecoderTest extends TestCase
1010
private $input;
1111
private $decoder;
1212

13-
public function setUp()
13+
/**
14+
* @before
15+
*/
16+
public function setUpDecoder()
1417
{
1518
$this->input = new ThroughStream();
1619
$this->decoder = new Decoder($this->input);
@@ -76,7 +79,7 @@ public function testEmitDataErrorWillForwardError()
7679
$this->input->emit('data', array("invalid\n"));
7780

7881
$this->assertInstanceOf('RuntimeException', $error);
79-
$this->assertContains('Syntax error', $error->getMessage());
82+
$this->assertContainsString('Syntax error', $error->getMessage());
8083
$this->assertEquals(JSON_ERROR_SYNTAX, $error->getCode());
8184
}
8285

tests/EncoderTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ class EncoderTest extends TestCase
1010
private $output;
1111
private $encoder;
1212

13-
public function setUp()
13+
/**
14+
* @before
15+
*/
16+
public function setUpEncoder()
1417
{
1518
$stream = fopen('php://temp', 'r+');
1619
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
@@ -19,15 +22,13 @@ public function setUp()
1922
$this->encoder = new Encoder($this->output);
2023
}
2124

22-
/**
23-
* @expectedException InvalidArgumentException
24-
*/
2525
public function testPrettyPrintDoesNotMakeSenseForNDJson()
2626
{
2727
if (!defined('JSON_PRETTY_PRINT')) {
2828
$this->markTestSkipped('Const JSON_PRETTY_PRINT only available in PHP 5.4+');
2929
}
3030

31+
$this->setExpectedException('InvalidArgumentException');
3132
$this->encoder = new Encoder($this->output, JSON_PRETTY_PRINT);
3233
}
3334

@@ -77,11 +78,11 @@ public function testWriteInfiniteWillEmitErrorAndClose()
7778
$this->assertInstanceOf('RuntimeException', $error);
7879
if (PHP_VERSION_ID >= 50500) {
7980
// PHP 5.5+ reports error with proper code
80-
$this->assertContains('Inf and NaN cannot be JSON encoded', $error->getMessage());
81+
$this->assertContainsString('Inf and NaN cannot be JSON encoded', $error->getMessage());
8182
$this->assertEquals(JSON_ERROR_INF_OR_NAN, $error->getCode());
8283
} else {
8384
// PHP < 5.5 reports error message without code
84-
$this->assertContains('double INF does not conform to the JSON spec', $error->getMessage());
85+
$this->assertContainsString('double INF does not conform to the JSON spec', $error->getMessage());
8586
$this->assertEquals(0, $error->getCode());
8687
}
8788
}
@@ -109,7 +110,7 @@ public function testWriteInvalidUtf8WillEmitErrorAndClose()
109110
$this->assertInstanceOf('RuntimeException', $error);
110111
if (PHP_VERSION_ID >= 50500) {
111112
// PHP 5.5+ reports error with proper code
112-
$this->assertContains('Malformed UTF-8 characters, possibly incorrectly encoded', $error->getMessage());
113+
$this->assertContainsString('Malformed UTF-8 characters, possibly incorrectly encoded', $error->getMessage());
113114
$this->assertEquals(JSON_ERROR_UTF8, $error->getCode());
114115
} elseif (PHP_VERSION_ID >= 50303) {
115116
// PHP 5.3.3+ reports error with proper code (const JSON_ERROR_UTF8 added in PHP 5.3.3)

tests/TestCase.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,32 @@ protected function createCallableMock()
4141
{
4242
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
4343
}
44+
45+
public function assertContainsString($needle, $haystack)
46+
{
47+
if (method_exists($this, 'assertStringContainsString')) {
48+
// PHPUnit 7.5+
49+
$this->assertStringContainsString($needle, $haystack);
50+
} else {
51+
// legacy PHPUnit 4 - PHPUnit 7.5
52+
$this->assertContains($needle, $haystack);
53+
}
54+
}
55+
56+
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
57+
{
58+
if (method_exists($this, 'expectException')) {
59+
// PHPUnit 5+
60+
$this->expectException($exception);
61+
if ($exceptionMessage !== '') {
62+
$this->expectExceptionMessage($exceptionMessage);
63+
}
64+
if ($exceptionCode !== null) {
65+
$this->expectExceptionCode($exceptionCode);
66+
}
67+
} else {
68+
// legacy PHPUnit 4
69+
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
70+
}
71+
}
4472
}

0 commit comments

Comments
 (0)