/** * @test * @covers \Xicrow\PhpDebug\Timer::reset * @covers \Xicrow\PhpDebug\Timer::add * @covers \Xicrow\PhpDebug\Timer::start * @covers \Xicrow\PhpDebug\Timer::stop * @covers \Xicrow\PhpDebug\Timer::callback */ public function testCallback() { Timer::reset(); $expected = time(); $result = Timer::callback(null, 'time'); $this->assertEquals($expected, $result); $expected = strpos('Hello world', 'world'); $result = Timer::callback(null, 'strpos', 'Hello world', 'world'); $this->assertEquals($expected, $result); $expected = array_sum([1, 2, 3, 4, 5, 6, 7, 8, 9]); $result = Timer::callback(null, 'array_sum', [1, 2, 3, 4, 5, 6, 7, 8, 9]); $this->assertEquals($expected, $result); $expected = min([1, 2, 3, 4, 5, 6, 7, 8, 9]); $result = Timer::callback(null, 'min', [1, 2, 3, 4, 5, 6, 7, 8, 9]); $this->assertEquals($expected, $result); $expected = max([1, 2, 3, 4, 5, 6, 7, 8, 9]); $result = Timer::callback(null, 'max', [1, 2, 3, 4, 5, 6, 7, 8, 9]); $this->assertEquals($expected, $result); $expected = 'Xicrow\\PhpDebug\\Debugger::getCalledFrom()'; $result = Timer::callback(null, ['Xicrow\\PhpDebug\\Debugger', 'getCalledFrom']); $this->assertEquals($expected, $result); $dateTime = new DateTime(); $dateTime->setTimezone(new DateTimeZone('Europe/Copenhagen')); $dateTime->setDate(2016, 01, 01); $dateTime->setTime(00, 00, 00); $expected = '2016-01-01 00:00:00'; $result = Timer::callback(null, [$dateTime, 'format'], 'Y-m-d H:i:s'); $this->assertEquals($expected, $result); $expected = true; $result = Timer::callback(null, function () { return true; }); $this->assertEquals($expected, $result); $expected = false; $result = Timer::callback(null, function () { return false; }); $this->assertEquals($expected, $result); $expected = false; $result = Timer::callback(null, 'non_existing_function'); $this->assertEquals($expected, $result); }
for ($k = 1; $k <= 2; $k++) { Timer::start('Loop level 3'); Timer::stop(); } Timer::stop(); } Timer::stop(); } // Callback test Timer::callback(null, 'time'); Timer::callback(null, 'strpos', 'Hello world', 'world'); Timer::callback(null, 'array_sum', [1, 2, 3, 4, 5, 6, 7, 8, 9]); Timer::callback(null, 'array_rand', [1, 2, 3, 4, 5, 6, 7, 8, 9]); Timer::callback(null, 'min', [1, 2, 3, 4, 5, 6, 7, 8, 9]); Timer::callback(null, 'max', [1, 2, 3, 4, 5, 6, 7, 8, 9]); Timer::callback(null, ['Xicrow\\PhpDebug\\Debugger', 'getDebugInformation'], [1, 2, 3]); Timer::callback(null, function () { return false; }); // Custom test Timer::custom('5 seconds', time(), time() + 5); Timer::custom('5 minutes', time(), time() + 5 * 60); Timer::custom('5 hours ', time(), time() + 5 * 60 * 60); Timer::custom('5 days ', time(), time() + 5 * 60 * 60 * 24); Timer::custom('5 weeks ', time(), time() + 5 * 60 * 60 * 24 * 7); // Show all timers Timer::showAll(); ?> </body> </html>