1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 20:15:00 +01:00

Update for setErrorHandler() & getWatcherId + new test with stop()

This commit is contained in:
Bob Weinand 2016-12-23 01:43:09 +01:00
parent e8fb7169d4
commit 2c0d6064af
2 changed files with 37 additions and 6 deletions

View File

@ -5,7 +5,7 @@
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": ">=5.5.0", "php": ">=5.5.0",
"async-interop/event-loop": "^0.3", "async-interop/event-loop": "^0.4|dev-master",
"phpunit/phpunit": "^4|^5" "phpunit/phpunit": "^4|^5"
}, },
"autoload": { "autoload": {
@ -13,4 +13,4 @@
"Interop\\Async\\Loop\\": "src" "Interop\\Async\\Loop\\": "src"
} }
} }
} }

View File

@ -612,7 +612,12 @@ abstract class Test extends \PHPUnit_Framework_TestCase {
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */ /** @expectedException \Interop\Async\Loop\InvalidWatcherException */
function testExceptionOnEnableNonexistentWatcher() function testExceptionOnEnableNonexistentWatcher()
{ {
$this->loop->enable("nonexistentWatcher"); try {
$this->loop->enable("nonexistentWatcher");
} catch (Loop\InvalidWatcherException $e) {
$this->assertEquals("nonexistentWatcher", $e->getWatcherId());
throw $e;
}
} }
function testSuccessOnDisableNonexistentWatcher() function testSuccessOnDisableNonexistentWatcher()
@ -628,13 +633,23 @@ abstract class Test extends \PHPUnit_Framework_TestCase {
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */ /** @expectedException \Interop\Async\Loop\InvalidWatcherException */
function testExceptionOnReferenceNonexistentWatcher() 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 */ /** @expectedException \Interop\Async\Loop\InvalidWatcherException */
function testExceptionOnUnreferenceNonexistentWatcher() 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 */ /** @expectedException \Interop\Async\Loop\InvalidWatcherException */
@ -860,9 +875,11 @@ abstract class Test extends \PHPUnit_Framework_TestCase {
function testErrorHandlerCapturesUncaughtException() function testErrorHandlerCapturesUncaughtException()
{ {
$msg = ""; $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(); $msg = $error->getMessage();
}); });
$this->assertEquals($d, $oldErrorHandler);
$this->start(function(Driver $loop) { $this->start(function(Driver $loop) {
$loop->defer(function() { $loop->defer(function() {
throw new \Exception("loop error"); throw new \Exception("loop error");
@ -1130,6 +1147,20 @@ abstract class Test extends \PHPUnit_Framework_TestCase {
$this->assertTrue($callbackData->onWritable); $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 // getState and setState are final, but test it here again to be sure
function testRegistry() { function testRegistry() {
$this->assertNull($this->loop->getState("foo")); $this->assertNull($this->loop->getState("foo"));