Skip to content

Commit 8732b93

Browse files
committed
Run tests on PHPUnit 9
1 parent fb8c5f2 commit 8732b93

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
"react/stream": "^1.0 || ^0.7.6"
3333
},
3434
"require-dev": {
35-
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35",
35+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
3636
"react/socket": "^1.0",
37-
"sebastian/environment": "^3.0 || ^2.0 || ^1.0"
37+
"sebastian/environment": "^5.0 || ^3.0 || ^2.0 || ^1.0"
3838
},
3939
"autoload": {
4040
"psr-4": { "React\\ChildProcess\\": "src" }

tests/AbstractProcessTest.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,15 @@ public function testStartWithCustomPipesWillAssignPipes()
8484
$this->assertInstanceOf('React\Stream\WritableStreamInterface', $process->pipes[3]);
8585
}
8686

87-
/**
88-
* @expectedException RuntimeException
89-
* @expectedExceptionMessage No such file or directory
90-
*/
9187
public function testStartWithInvalidFileDescriptorPathWillThrow()
9288
{
9389
$fds = array(
9490
4 => array('file', '/dev/does-not-exist', 'r')
9591
);
9692

9793
$process = new Process('exit 0', null, null, $fds);
94+
95+
$this->setExpectedException('RuntimeException', 'No such file or directory');
9896
$process->start($this->createLoop());
9997
}
10098

@@ -130,7 +128,7 @@ public function testStartWithExcessiveNumberOfFileDescriptorsWillThrow()
130128
// clear dummy files handles to make some room again (avoid fatal errors for autoloader)
131129
$fds = array();
132130

133-
$this->assertContains('Too many open files', $e->getMessage());
131+
$this->assertContainsString('Too many open files', $e->getMessage());
134132
}
135133
}
136134

@@ -631,9 +629,6 @@ public function testStartInvalidProcess()
631629
$this->assertNotEmpty($output);
632630
}
633631

634-
/**
635-
* @expectedException RuntimeException
636-
*/
637632
public function testStartAlreadyRunningProcess()
638633
{
639634
if (DIRECTORY_SEPARATOR === '\\') {
@@ -645,6 +640,8 @@ public function testStartAlreadyRunningProcess()
645640
//var_dump($process);
646641

647642
$process->start($this->createLoop());
643+
644+
$this->setExpectedException('RuntimeException');
648645
$process->start($this->createLoop());
649646
}
650647

@@ -873,4 +870,32 @@ private function getPhpBinary()
873870

874871
return $runtime->getBinary();
875872
}
873+
874+
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
875+
{
876+
if (method_exists($this, 'expectException')) {
877+
// PHPUnit 5.2+
878+
$this->expectException($exception);
879+
if ($exceptionMessage !== '') {
880+
$this->expectExceptionMessage($exceptionMessage);
881+
}
882+
if ($exceptionCode !== null) {
883+
$this->expectExceptionCode($exceptionCode);
884+
}
885+
} else {
886+
// legacy PHPUnit 4 - PHPUnit 5.1
887+
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
888+
}
889+
}
890+
891+
public function assertContainsString($needle, $haystack)
892+
{
893+
if (method_exists($this, 'assertStringContainsString')) {
894+
// PHPUnit 7.5+
895+
$this->assertStringContainsString($needle, $haystack);
896+
} else {
897+
// legacy PHPUnit 4 - PHPUnit 7.5
898+
$this->assertContains($needle, $haystack);
899+
}
900+
}
876901
}

0 commit comments

Comments
 (0)