Skip to content

Commit

Permalink
for PHP 8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Mar 4, 2021
1 parent 0869ccd commit d54d9cc
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Spawn/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
if (!defined('IS_LINUX'))
\define('IS_LINUX', ('/' === \DS));

if (!defined('IS_PHP8'))
\define('IS_PHP8', ((float)phpversion() >= 8.0));

if (\IS_WINDOWS && \function_exists('uv_loop_new')) {
/**
* The SIGUSR1 signal is sent to a process to indicate user-defined conditions.
Expand Down
3 changes: 1 addition & 2 deletions Spawn/Launcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,7 @@ public function getOutput()
$cleaned = $this->output;
$replaceWith = $this->getResult();
if (\is_string($cleaned) && \strpos($cleaned, $this->rawLastResult) !== false) {
if ((float)phpversion() >= 8.0) {
print_r($replaceWith);
if (\IS_PHP8) {
$replaceWith = (string) $replaceWith;
}

Expand Down
4 changes: 3 additions & 1 deletion tests/ChanneledTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

class ChanneledTest extends TestCase
{
protected function setUp(): void
protected function setUp(): void
{
if (!\function_exists('uv_loop_new'))
$this->markTestSkipped('Test skipped "uv_loop_new" missing.');
Spawn::setup(null, false, false, true);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ContainerTest extends TestCase
{
protected function setUp(): void
{
if (!\function_exists('uv_loop_new'))
$this->markTestSkipped('Test skipped "uv_loop_new" missing.');
Spawn::setup(null, false, false, true);
}

Expand Down
22 changes: 12 additions & 10 deletions tests/ErrorHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@

class ErrorHandlingTest extends TestCase
{
protected function setUp(): void
protected function setUp(): void
{
if (!\function_exists('uv_loop_new'))
$this->markTestSkipped('Test skipped "uv_loop_new" missing.');
Spawn::setup(null, false, false, true);
}

public function testIt_can_handle_exceptions_via_catch_callback()
{
$process = \spawn(function () {
throw new \Exception('test');
})->catch(function (\Exception $e) {
$this->assertRegExp('/test/', $e->getMessage());
});
throw new \Exception('test');
})->catch(function (\Exception $e) {
$this->assertRegExp('/test/', $e->getMessage());
});

\spawn_run($process);
$this->assertFalse($process->isSuccessful());
Expand All @@ -32,10 +34,10 @@ public function testIt_can_handle_exceptions_via_catch_callback()
public function testIt_can_handle_exceptions_via_catch_callback_yield()
{
$process = spawn(function () {
throw new \Exception('test');
})->catch(function (\Exception $e) {
$this->assertRegExp('/test/', $e->getMessage());
});
throw new \Exception('test');
})->catch(function (\Exception $e) {
$this->assertRegExp('/test/', $e->getMessage());
});

$yield = $process->yielding();
$this->assertInstanceOf(SerializableException::class, $yield->current());
Expand All @@ -49,7 +51,7 @@ public function testIt_handles_stderr_as_Spawn_error()
$process = spawn(function () {
fwrite(\STDERR, 'test');
})->catch(function (SpawnError $error) {
$this->assertStringContainsString('test', $error->getMessage());
$this->assertStringContainsString('test', $error->getMessage());
});

spawn_run($process);
Expand Down
2 changes: 2 additions & 0 deletions tests/SpawnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class SpawnTest extends TestCase
{
protected function setUp(): void
{
if (!\function_exists('uv_loop_new'))
$this->markTestSkipped('Test skipped "uv_loop_new" missing.');
Spawn::setup(null, false, false, true);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/libuv/006-uv_async_init-no-memory-leak.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Check uv_async has no memory leak
--SKIPIF--
<?php if (!extension_loaded("uv")) print "skip"; ?>
--FILE--
<?php
$m = memory_get_usage();
Expand Down
2 changes: 2 additions & 0 deletions tests/libuv/100-uv_async.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Check for uv_async
--SKIPIF--
<?php if (!extension_loaded("uv")) print "skip"; ?>
--FILE--
<?php
$loop = uv_default_loop();
Expand Down
4 changes: 3 additions & 1 deletion tests/libuv/100-uv_check.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Check for uv_check
--SKIPIF--
<?php if (!extension_loaded("uv")) print "skip"; ?>
--FILE--
<?php
$loop = uv_default_loop();
Expand All @@ -10,7 +12,7 @@ $idle = uv_idle_init();
$i = 0;
uv_idle_start($idle, function($stat) use (&$i, $idle, $loop){
$i++;

if ($i > 3) {
uv_idle_stop($idle);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/libuv/100-uv_stop.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Test uv_stop ends loop execution
--SKIPIF--
<?php if (!extension_loaded("uv")) print "skip"; ?>
--FILE--
<?php
$loop = uv_default_loop();
Expand All @@ -23,4 +25,4 @@ count: 0
count: 1
count: 2
count: 3
finished
finished
4 changes: 3 additions & 1 deletion tests/libuv/100-uv_timer.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Check for uv_timer_init and uv_timer_start
--SKIPIF--
<?php if (!extension_loaded("uv")) print "skip"; ?>
--FILE--
<?php
$loop = uv_default_loop();
Expand All @@ -9,7 +11,7 @@ $i = 0;
uv_timer_start($timer, 10, 10, function($timer) use (&$i) {
echo "count: {$i}" . PHP_EOL;
$i++;

if ($i > 3) {
uv_timer_stop($timer);
uv_unref($timer);
Expand Down
4 changes: 3 additions & 1 deletion tests/libuv/101-uv-idle.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Check for uv_idle_init and uv_idle_start
--SKIPIF--
<?php if (!extension_loaded("uv")) print "skip"; ?>
--FILE--
<?php
$loop = uv_default_loop();
Expand All @@ -11,7 +13,7 @@ uv_idle_start($idle, function($stat)

echo "count: {$i}" . PHP_EOL;
$i++;

if ($i > 3) {
uv_idle_stop($idle);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/libuv/800-broken-uv_spawn-issue-79.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Bad uv_spawn must not segfault (issue #79)
--SKIPIF--
<?php if (!extension_loaded("uv")) print "skip"; ?>
--FILE--
<?php
$rt = uv_spawn(
Expand Down
2 changes: 2 additions & 0 deletions tests/libuv/800-uv_stdio_new-issue59.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Test uv_stdio_new doesn't cause segfault #56
--SKIPIF--
<?php if (!extension_loaded("uv")) print "skip"; ?>
--FILE--
<?php

Expand Down
4 changes: 3 additions & 1 deletion tests/libuv/999-uv_cwd.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Check for uv_cwd
--SKIPIF--
<?php if (!extension_loaded("uv")) print "skip"; ?>
--FILE--
<?php
$cwd = uv_cwd();
Expand All @@ -13,4 +15,4 @@ if ($cwd == $expected) {

}
--EXPECT--
OK
OK
2 changes: 2 additions & 0 deletions tests/libuv/999-uv_exepath.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Check for uv_exepath
--SKIPIF--
<?php if (!extension_loaded("uv")) print "skip"; ?>
--FILE--
<?php
$path = uv_exepath();
Expand Down

0 comments on commit d54d9cc

Please sign in to comment.