Skip to content

Commit e69a8bd

Browse files
authored
Merge pull request #242 from clue-labs/tests
Improve test suite to declare and validate helper variables and support running from meta repository (PHP 8.1)
2 parents 9f10e11 + 4f641e8 commit e69a8bd

11 files changed

+37
-9
lines changed

phpunit.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
66
bootstrap="vendor/autoload.php"
7+
cacheResult="false"
78
colors="true"
8-
cacheResult="false">
9+
convertDeprecationsToExceptions="true">
910
<testsuites>
1011
<testsuite name="React test suite">
1112
<directory>./tests/</directory>

tests/AbstractLoopTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ abstract class AbstractLoopTest extends TestCase
1212
*/
1313
protected $loop;
1414

15+
/** @var float */
1516
private $tickTimeout;
1617

18+
/** @var ?string */
19+
private $received;
20+
1721
const PHP_DEFAULT_CHUNK_SIZE = 8192;
1822

1923
/**

tests/ExtEventLoopTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
class ExtEventLoopTest extends AbstractLoopTest
88
{
9+
/** @var ?string */
10+
private $fifoPath;
11+
912
public function createLoop($readStreamCompatible = false)
1013
{
1114
if ('Linux' === PHP_OS && !extension_loaded('posix')) {
@@ -19,12 +22,23 @@ public function createLoop($readStreamCompatible = false)
1922
return new ExtEventLoop();
2023
}
2124

25+
/**
26+
* @after
27+
*/
28+
public function tearDownFile()
29+
{
30+
if ($this->fifoPath !== null && file_exists($this->fifoPath)) {
31+
unlink($this->fifoPath);
32+
}
33+
}
34+
2235
public function createStream()
2336
{
2437
// Use a FIFO on linux to get around lack of support for disk-based file
2538
// descriptors when using the EPOLL back-end.
2639
if ('Linux' === PHP_OS) {
2740
$this->fifoPath = tempnam(sys_get_temp_dir(), 'react-');
41+
assert(is_string($this->fifoPath));
2842

2943
unlink($this->fifoPath);
3044

tests/ExtLibeventLoopTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class ExtLibeventLoopTest extends AbstractLoopTest
88
{
9+
/** @var ?string */
910
private $fifoPath;
1011

1112
public function createLoop()
@@ -26,7 +27,7 @@ public function createLoop()
2627
*/
2728
public function tearDownFile()
2829
{
29-
if (file_exists($this->fifoPath)) {
30+
if ($this->fifoPath !== null && file_exists($this->fifoPath)) {
3031
unlink($this->fifoPath);
3132
}
3233
}
@@ -38,6 +39,7 @@ public function createStream()
3839
}
3940

4041
$this->fifoPath = tempnam(sys_get_temp_dir(), 'react-');
42+
assert(is_string($this->fifoPath));
4143

4244
unlink($this->fifoPath);
4345

tests/bin/01-ticks-loop-class.php

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

33
use React\EventLoop\Loop;
44

5-
require __DIR__ . '/../../vendor/autoload.php';
5+
// autoload for local project development or project installed as dependency for reactphp/reactphp
6+
(@include __DIR__ . '/../../vendor/autoload.php') || require __DIR__ . '/../../../../autoload.php';
67

78
Loop::futureTick(function () {
89
echo 'b';

tests/bin/02-ticks-loop-instance.php

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

33
use React\EventLoop\Loop;
44

5-
require __DIR__ . '/../../vendor/autoload.php';
5+
// autoload for local project development or project installed as dependency for reactphp/reactphp
6+
(@include __DIR__ . '/../../vendor/autoload.php') || require __DIR__ . '/../../../../autoload.php';
67

78
$loop = Loop::get();
89

tests/bin/03-ticks-loop-stop.php

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

33
use React\EventLoop\Loop;
44

5-
require __DIR__ . '/../../vendor/autoload.php';
5+
// autoload for local project development or project installed as dependency for reactphp/reactphp
6+
(@include __DIR__ . '/../../vendor/autoload.php') || require __DIR__ . '/../../../../autoload.php';
67

78
$loop = Loop::get();
89

tests/bin/11-uncaught.php

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

33
use React\EventLoop\Loop;
44

5-
require __DIR__ . '/../../vendor/autoload.php';
5+
// autoload for local project development or project installed as dependency for reactphp/reactphp
6+
(@include __DIR__ . '/../../vendor/autoload.php') || require __DIR__ . '/../../../../autoload.php';
67

78
Loop::addTimer(10.0, function () {
89
echo 'never';

tests/bin/12-undefined.php

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

33
use React\EventLoop\Loop;
44

5-
require __DIR__ . '/../../vendor/autoload.php';
5+
// autoload for local project development or project installed as dependency for reactphp/reactphp
6+
(@include __DIR__ . '/../../vendor/autoload.php') || require __DIR__ . '/../../../../autoload.php';
67

78
Loop::get()->addTimer(10.0, function () {
89
echo 'never';

tests/bin/21-stop.php

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

33
use React\EventLoop\Loop;
44

5-
require __DIR__ . '/../../vendor/autoload.php';
5+
// autoload for local project development or project installed as dependency for reactphp/reactphp
6+
(@include __DIR__ . '/../../vendor/autoload.php') || require __DIR__ . '/../../../../autoload.php';
67

78
Loop::addTimer(10.0, function () {
89
echo 'never';

0 commit comments

Comments
 (0)