Skip to content

Commit 2c0d606

Browse files
committed
Update for setErrorHandler() & getWatcherId + new test with stop()
1 parent e8fb716 commit 2c0d606

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"license": "MIT",
66
"require": {
77
"php": ">=5.5.0",
8-
"async-interop/event-loop": "^0.3",
8+
"async-interop/event-loop": "^0.4|dev-master",
99
"phpunit/phpunit": "^4|^5"
1010
},
1111
"autoload": {
1212
"psr-4": {
1313
"Interop\\Async\\Loop\\": "src"
1414
}
1515
}
16-
}
16+
}

src/Test.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,12 @@ function testSignalExecutionOrder()
612612
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
613613
function testExceptionOnEnableNonexistentWatcher()
614614
{
615-
$this->loop->enable("nonexistentWatcher");
615+
try {
616+
$this->loop->enable("nonexistentWatcher");
617+
} catch (Loop\InvalidWatcherException $e) {
618+
$this->assertEquals("nonexistentWatcher", $e->getWatcherId());
619+
throw $e;
620+
}
616621
}
617622

618623
function testSuccessOnDisableNonexistentWatcher()
@@ -628,13 +633,23 @@ function testSuccessOnCancelNonexistentWatcher()
628633
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
629634
function testExceptionOnReferenceNonexistentWatcher()
630635
{
631-
$this->loop->reference("nonexistentWatcher");
636+
try {
637+
$this->loop->reference("nonexistentWatcher");
638+
} catch (Loop\InvalidWatcherException $e) {
639+
$this->assertEquals("nonexistentWatcher", $e->getWatcherId());
640+
throw $e;
641+
}
632642
}
633643

634644
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
635645
function testExceptionOnUnreferenceNonexistentWatcher()
636646
{
637-
$this->loop->unreference("nonexistentWatcher");
647+
try {
648+
$this->loop->unreference("nonexistentWatcher");
649+
} catch (Loop\InvalidWatcherException $e) {
650+
$this->assertEquals("nonexistentWatcher", $e->getWatcherId());
651+
throw $e;
652+
}
638653
}
639654

640655
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
@@ -860,9 +875,11 @@ function testLoopAllowsExceptionToBubbleUpFromRepeatingAlarmDuringStart()
860875
function testErrorHandlerCapturesUncaughtException()
861876
{
862877
$msg = "";
863-
$this->loop->setErrorHandler(function(\Exception $error) use (&$msg) {
878+
$this->loop->setErrorHandler($f = function() {});
879+
$oldErrorHandler = $this->loop->setErrorHandler(function(\Exception $error) use (&$msg) {
864880
$msg = $error->getMessage();
865881
});
882+
$this->assertEquals($d, $oldErrorHandler);
866883
$this->start(function(Driver $loop) {
867884
$loop->defer(function() {
868885
throw new \Exception("loop error");
@@ -1130,6 +1147,20 @@ function testOptionalCallbackDataPassedOnInvocation()
11301147
$this->assertTrue($callbackData->onWritable);
11311148
}
11321149

1150+
function testLoopStopPreventsTimerExecution()
1151+
{
1152+
$t = microtime(1);
1153+
$this->start(function(Driver $loop) {
1154+
$loop->delay($msDelay = 10000, function () {
1155+
$this->fail("Timer was executed despite stopped loop");
1156+
});
1157+
$loop->defer(function () use ($loop) {
1158+
$loop->stop();
1159+
});
1160+
});
1161+
$this->assertTrue($t + 0.1 > microtime(1));
1162+
}
1163+
11331164
// getState and setState are final, but test it here again to be sure
11341165
function testRegistry() {
11351166
$this->assertNull($this->loop->getState("foo"));

0 commit comments

Comments
 (0)