Skip to content

Commit

Permalink
Merge pull request #242 from clue-labs/tests
Browse files Browse the repository at this point in the history
Improve test suite to declare and validate helper variables and support running from meta repository (PHP 8.1)
  • Loading branch information
WyriHaximus committed Feb 5, 2022
2 parents 9f10e11 + 4f641e8 commit e69a8bd
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 9 deletions.
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Expand Up @@ -4,8 +4,9 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResult="false"
colors="true"
cacheResult="false">
convertDeprecationsToExceptions="true">
<testsuites>
<testsuite name="React test suite">
<directory>./tests/</directory>
Expand Down
4 changes: 4 additions & 0 deletions tests/AbstractLoopTest.php
Expand Up @@ -12,8 +12,12 @@ abstract class AbstractLoopTest extends TestCase
*/
protected $loop;

/** @var float */
private $tickTimeout;

/** @var ?string */
private $received;

const PHP_DEFAULT_CHUNK_SIZE = 8192;

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/ExtEventLoopTest.php
Expand Up @@ -6,6 +6,9 @@

class ExtEventLoopTest extends AbstractLoopTest
{
/** @var ?string */
private $fifoPath;

public function createLoop($readStreamCompatible = false)
{
if ('Linux' === PHP_OS && !extension_loaded('posix')) {
Expand All @@ -19,12 +22,23 @@ public function createLoop($readStreamCompatible = false)
return new ExtEventLoop();
}

/**
* @after
*/
public function tearDownFile()
{
if ($this->fifoPath !== null && file_exists($this->fifoPath)) {
unlink($this->fifoPath);
}
}

public function createStream()
{
// Use a FIFO on linux to get around lack of support for disk-based file
// descriptors when using the EPOLL back-end.
if ('Linux' === PHP_OS) {
$this->fifoPath = tempnam(sys_get_temp_dir(), 'react-');
assert(is_string($this->fifoPath));

unlink($this->fifoPath);

Expand Down
4 changes: 3 additions & 1 deletion tests/ExtLibeventLoopTest.php
Expand Up @@ -6,6 +6,7 @@

class ExtLibeventLoopTest extends AbstractLoopTest
{
/** @var ?string */
private $fifoPath;

public function createLoop()
Expand All @@ -26,7 +27,7 @@ public function createLoop()
*/
public function tearDownFile()
{
if (file_exists($this->fifoPath)) {
if ($this->fifoPath !== null && file_exists($this->fifoPath)) {
unlink($this->fifoPath);
}
}
Expand All @@ -38,6 +39,7 @@ public function createStream()
}

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

unlink($this->fifoPath);

Expand Down
3 changes: 2 additions & 1 deletion tests/bin/01-ticks-loop-class.php
Expand Up @@ -2,7 +2,8 @@

use React\EventLoop\Loop;

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

Loop::futureTick(function () {
echo 'b';
Expand Down
3 changes: 2 additions & 1 deletion tests/bin/02-ticks-loop-instance.php
Expand Up @@ -2,7 +2,8 @@

use React\EventLoop\Loop;

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

$loop = Loop::get();

Expand Down
3 changes: 2 additions & 1 deletion tests/bin/03-ticks-loop-stop.php
Expand Up @@ -2,7 +2,8 @@

use React\EventLoop\Loop;

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

$loop = Loop::get();

Expand Down
3 changes: 2 additions & 1 deletion tests/bin/11-uncaught.php
Expand Up @@ -2,7 +2,8 @@

use React\EventLoop\Loop;

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

Loop::addTimer(10.0, function () {
echo 'never';
Expand Down
3 changes: 2 additions & 1 deletion tests/bin/12-undefined.php
Expand Up @@ -2,7 +2,8 @@

use React\EventLoop\Loop;

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

Loop::get()->addTimer(10.0, function () {
echo 'never';
Expand Down
3 changes: 2 additions & 1 deletion tests/bin/21-stop.php
Expand Up @@ -2,7 +2,8 @@

use React\EventLoop\Loop;

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

Loop::addTimer(10.0, function () {
echo 'never';
Expand Down
3 changes: 2 additions & 1 deletion tests/bin/22-stop-uncaught.php
Expand Up @@ -2,7 +2,8 @@

use React\EventLoop\Loop;

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

Loop::addTimer(10.0, function () {
echo 'never';
Expand Down

0 comments on commit e69a8bd

Please sign in to comment.