/ */ namespace P4Test\OutputHandler; use P4Test\TestCase; use P4\OutputHandler\Limit; class Test extends TestCase { public function testWasCancelled() { $handler = new Limit; $this->assertFalse($handler->wasCancelled()); // need a couple of entries to test the following for ($i = 0; $i < 10; $i++) { $this->p4->run('counter', array('test' . $i, $i)); } // test without exceeding max $handler->setMax(99); $this->p4->runHandler($handler, 'counters'); $this->assertFalse($handler->wasCancelled()); // test with exceeding max $handler->setMax(1); $this->p4->runHandler($handler, 'counters'); $this->assertTrue($handler->wasCancelled()); $handler->setMax(null); // reset should clear 'cancelled' flag $handler->reset(); $this->assertFalse($handler->wasCancelled()); // test with an output callback that doesn't cancel $handler->setOutputCallback( function () { return Limit::HANDLER_HANDLED; } ); $this->p4->runHandler($handler, 'counters'); $this->assertFalse($handler->wasCancelled()); // test with an output callback that does cancel $handler->setOutputCallback( function () { return Limit::HANDLER_CANCEL; } ); $this->p4->runHandler($handler, 'counters'); $this->assertTrue($handler->wasCancelled()); } }