Skip to content

Commit 5753a55

Browse files
author
Greg Bowler
committed
Test halting a loop
1 parent 3654b6f commit 5753a55

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

test/phpunit/LoopTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,30 @@ public function testRunWithTimerNoNextRunTime() {
130130

131131
self::assertEquals(0, $sut->getTriggerCount());
132132
}
133+
134+
public function testHalt() {
135+
$epoch = microtime(true);
136+
$tickCount = 0;
137+
138+
$sut = new Loop();
139+
140+
$timer = self::createMock(Timer::class);
141+
$timer->method("isScheduled")
142+
->willReturn(true);
143+
$timer->method("getNextRunTime")
144+
->willReturn($epoch);
145+
$timer->method("tick")
146+
->willReturnCallback(function() use($sut, &$tickCount) {
147+
$tickCount++;
148+
149+
if($tickCount === 10) {
150+
$sut->halt();
151+
}
152+
return true;
153+
});
154+
155+
$sut->addTimer($timer);
156+
$sut->run();
157+
self::assertEquals(10, $tickCount);
158+
}
133159
}

0 commit comments

Comments
 (0)