Skip to content

Commit

Permalink
Improve test suite to declare and validate helper variables (PHP 8.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Feb 4, 2022
1 parent ae621e4 commit 4f641e8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 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

0 comments on commit 4f641e8

Please sign in to comment.