/** * Tests a periodic timer. */ public function testPeriodic() { $total = 10; $count = 0; Vertx::setPeriodic(10, function ($timer_id) use(&$count, $total) { $this->assertNotNull($timer_id); $count += 1; if ($count == $total) { Vertx::cancelTimer($timer_id); Vertx::setTimer(10, function () { $this->complete(); }); } else { if ($count > $total) { $this->assertTrue(FALSE, 'Counter went off too many times!'); } } }); }
/** * Tests sending a message to an unregistering handler. */ public function testSendUnregisterSend() { $this->currentHandlerId = $this->eventBus->registerHandler(self::TEST_ADDRESS, function ($message) { $this->assertNotNull($message->replyAddress); if ($this->received) { $this->assertTrue(FALSE, 'Handler was already called.'); } $this->assertEquals($message->body['message'], self::$jsonMessage['message']); $this->eventBus->unregisterHandler($this->currentHandlerId); $this->received = TRUE; Vertx::setTimer(100, function () { $this->complete(); }); }); $this->assertNotNull($this->currentHandlerId); $this->eventBus->send(self::TEST_ADDRESS, self::$jsonMessage); $this->eventBus->send(self::TEST_ADDRESS, self::$jsonMessage); }