diff --git a/composer.json b/composer.json index 1f43653..9145074 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "license": "MIT", "require": { "php": ">=5.5.0", - "async-interop/event-loop": "^0.3", + "async-interop/event-loop": "^0.4|dev-master", "phpunit/phpunit": "^4|^5" }, "autoload": { @@ -13,4 +13,4 @@ "Interop\\Async\\Loop\\": "src" } } -} \ No newline at end of file +} diff --git a/src/Test.php b/src/Test.php index 02f638c..3f89e59 100644 --- a/src/Test.php +++ b/src/Test.php @@ -612,7 +612,12 @@ abstract class Test extends \PHPUnit_Framework_TestCase { /** @expectedException \Interop\Async\Loop\InvalidWatcherException */ function testExceptionOnEnableNonexistentWatcher() { - $this->loop->enable("nonexistentWatcher"); + try { + $this->loop->enable("nonexistentWatcher"); + } catch (Loop\InvalidWatcherException $e) { + $this->assertEquals("nonexistentWatcher", $e->getWatcherId()); + throw $e; + } } function testSuccessOnDisableNonexistentWatcher() @@ -628,13 +633,23 @@ abstract class Test extends \PHPUnit_Framework_TestCase { /** @expectedException \Interop\Async\Loop\InvalidWatcherException */ function testExceptionOnReferenceNonexistentWatcher() { - $this->loop->reference("nonexistentWatcher"); + try { + $this->loop->reference("nonexistentWatcher"); + } catch (Loop\InvalidWatcherException $e) { + $this->assertEquals("nonexistentWatcher", $e->getWatcherId()); + throw $e; + } } /** @expectedException \Interop\Async\Loop\InvalidWatcherException */ function testExceptionOnUnreferenceNonexistentWatcher() { - $this->loop->unreference("nonexistentWatcher"); + try { + $this->loop->unreference("nonexistentWatcher"); + } catch (Loop\InvalidWatcherException $e) { + $this->assertEquals("nonexistentWatcher", $e->getWatcherId()); + throw $e; + } } /** @expectedException \Interop\Async\Loop\InvalidWatcherException */ @@ -860,9 +875,11 @@ abstract class Test extends \PHPUnit_Framework_TestCase { function testErrorHandlerCapturesUncaughtException() { $msg = ""; - $this->loop->setErrorHandler(function(\Exception $error) use (&$msg) { + $this->loop->setErrorHandler($f = function() {}); + $oldErrorHandler = $this->loop->setErrorHandler(function(\Exception $error) use (&$msg) { $msg = $error->getMessage(); }); + $this->assertEquals($d, $oldErrorHandler); $this->start(function(Driver $loop) { $loop->defer(function() { throw new \Exception("loop error"); @@ -1130,6 +1147,20 @@ abstract class Test extends \PHPUnit_Framework_TestCase { $this->assertTrue($callbackData->onWritable); } + function testLoopStopPreventsTimerExecution() + { + $t = microtime(1); + $this->start(function(Driver $loop) { + $loop->delay($msDelay = 10000, function () { + $this->fail("Timer was executed despite stopped loop"); + }); + $loop->defer(function () use ($loop) { + $loop->stop(); + }); + }); + $this->assertTrue($t + 0.1 > microtime(1)); + } + // getState and setState are final, but test it here again to be sure function testRegistry() { $this->assertNull($this->loop->getState("foo"));