diff --git a/.travis.yml b/.travis.yml index 4e946173..fe9bd21c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ php: - 7.1 - 7.2 - 7.3 - - hhvm # ignore errors, see below +# - hhvm # requires legacy phpunit & ignore errors, see below # lock distro so new future defaults will not break the build dist: trusty @@ -18,6 +18,8 @@ matrix: include: - php: 5.3 dist: precise + - php: hhvm + install: composer require phpunit/phpunit:^5 --dev --no-interaction allow_failures: - php: hhvm diff --git a/composer.json b/composer.json index f6517df4..cc6abf06 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=5.3.0" }, "require-dev": { - "phpunit/phpunit": "~4.8.35 || ^5.7 || ^6.4" + "phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35" }, "suggest": { "ext-event": "~1.0 for ExtEventLoop", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cba6d4dd..04d426b5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,8 +8,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" - bootstrap="tests/bootstrap.php" + bootstrap="vendor/autoload.php" > diff --git a/tests/AbstractLoopTest.php b/tests/AbstractLoopTest.php index 3d844382..83f5756b 100644 --- a/tests/AbstractLoopTest.php +++ b/tests/AbstractLoopTest.php @@ -491,10 +491,13 @@ function () { public function testRemoveSignalNotRegisteredIsNoOp() { - $this->loop->removeSignal(SIGINT, function () { }); + $this->loop->removeSignal(2, function () { }); $this->assertTrue(true); } + /** + * @requires extension pcntl + */ public function testSignal() { if (!function_exists('posix_kill') || !function_exists('posix_getpid')) { @@ -528,6 +531,9 @@ public function testSignal() $this->assertTrue($calledShouldNot); } + /** + * @requires extension pcntl + */ public function testSignalMultipleUsagesForTheSameListener() { $funcCallCount = 0; @@ -552,6 +558,9 @@ public function testSignalMultipleUsagesForTheSameListener() $this->assertSame(1, $funcCallCount); } + /** + * @requires extension pcntl + */ public function testSignalsKeepTheLoopRunning() { $loop = $this->loop; @@ -565,6 +574,9 @@ public function testSignalsKeepTheLoopRunning() $this->assertRunSlowerThan(1.5); } + /** + * @requires extension pcntl + */ public function testSignalsKeepTheLoopRunningAndRemovingItStopsTheLoop() { $loop = $this->loop; diff --git a/tests/SignalsHandlerTest.php b/tests/SignalsHandlerTest.php index f8b7df3d..a8cc4221 100644 --- a/tests/SignalsHandlerTest.php +++ b/tests/SignalsHandlerTest.php @@ -6,6 +6,9 @@ final class SignalsHandlerTest extends TestCase { + /** + * @requires extension pcntl + */ public function testEmittedEventsAndCallHandling() { $callCount = 0; diff --git a/tests/StreamSelectLoopTest.php b/tests/StreamSelectLoopTest.php index bd19e1cd..2eb388f0 100644 --- a/tests/StreamSelectLoopTest.php +++ b/tests/StreamSelectLoopTest.php @@ -49,13 +49,10 @@ public function signalProvider() /** * Test signal interrupt when no stream is attached to the loop * @dataProvider signalProvider + * @requires extension pcntl */ public function testSignalInterruptNoStream($signal) { - if (!extension_loaded('pcntl')) { - $this->markTestSkipped('"pcntl" extension is required to run this test.'); - } - // dispatch signal handler every 10ms for 0.1s $check = $this->loop->addPeriodicTimer(0.01, function() { pcntl_signal_dispatch(); @@ -80,13 +77,10 @@ public function testSignalInterruptNoStream($signal) /** * Test signal interrupt when a stream is attached to the loop * @dataProvider signalProvider + * @requires extension pcntl */ public function testSignalInterruptWithStream($signal) { - if (!extension_loaded('pcntl')) { - $this->markTestSkipped('"pcntl" extension is required to run this test.'); - } - // dispatch signal handler every 10ms $this->loop->addPeriodicTimer(0.01, function() { pcntl_signal_dispatch(); diff --git a/tests/Timer/AbstractTimerTest.php b/tests/Timer/AbstractTimerTest.php index 294e683f..11187b31 100644 --- a/tests/Timer/AbstractTimerTest.php +++ b/tests/Timer/AbstractTimerTest.php @@ -22,8 +22,28 @@ public function testAddTimerReturnsNonPeriodicTimerInstance() $this->assertFalse($timer->isPeriodic()); } + /** + * @depends testPlatformHasHighAccuracy + */ public function testAddTimerWillBeInvokedOnceAndBlocksLoopWhenRunning() { + // Make no strict assumptions about actual time interval. Common + // environments usually provide millisecond accuracy (or better), but + // Travis and other CI systems are slow. + // We try to compensate for this by skipping accurate tests when the + // current platform is known to be inaccurate. We test this by sleeping + // 3x1ms and then measure the time for each iteration before running the + // actual test. + for ($i = 0; $i < 3; ++$i) { + $start = microtime(true); + usleep(1000); + $time = microtime(true) - $start; + + if ($time < 0.001 || $time > 0.002) { + $this->markTestSkipped('Platform provides insufficient accuracy (' . $time . ' s)'); + } + } + $loop = $this->createLoop(); $loop->addTimer(0.001, $this->expectCallableOnce()); @@ -32,10 +52,8 @@ public function testAddTimerWillBeInvokedOnceAndBlocksLoopWhenRunning() $loop->run(); $end = microtime(true); - // make no strict assumptions about actual time interval. - // must be at least 0.001s (1ms) and should not take longer than 0.1s $this->assertGreaterThanOrEqual(0.001, $end - $start); - $this->assertLessThan(0.1, $end - $start); + $this->assertLessThan(0.002, $end - $start); } public function testAddPeriodicTimerReturnsPeriodicTimerInstance() diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index aeb44352..00000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,9 +0,0 @@ -