@@ -612,7 +612,12 @@ function testSignalExecutionOrder()
612
612
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
613
613
function testExceptionOnEnableNonexistentWatcher ()
614
614
{
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
+ }
616
621
}
617
622
618
623
function testSuccessOnDisableNonexistentWatcher ()
@@ -628,13 +633,23 @@ function testSuccessOnCancelNonexistentWatcher()
628
633
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
629
634
function testExceptionOnReferenceNonexistentWatcher ()
630
635
{
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
+ }
632
642
}
633
643
634
644
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
635
645
function testExceptionOnUnreferenceNonexistentWatcher ()
636
646
{
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
+ }
638
653
}
639
654
640
655
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
@@ -860,9 +875,11 @@ function testLoopAllowsExceptionToBubbleUpFromRepeatingAlarmDuringStart()
860
875
function testErrorHandlerCapturesUncaughtException ()
861
876
{
862
877
$ 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 ) {
864
880
$ msg = $ error ->getMessage ();
865
881
});
882
+ $ this ->assertEquals ($ d , $ oldErrorHandler );
866
883
$ this ->start (function (Driver $ loop ) {
867
884
$ loop ->defer (function () {
868
885
throw new \Exception ("loop error " );
@@ -1130,6 +1147,20 @@ function testOptionalCallbackDataPassedOnInvocation()
1130
1147
$ this ->assertTrue ($ callbackData ->onWritable );
1131
1148
}
1132
1149
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
+
1133
1164
// getState and setState are final, but test it here again to be sure
1134
1165
function testRegistry () {
1135
1166
$ this ->assertNull ($ this ->loop ->getState ("foo " ));
0 commit comments