[Stopwatch] added __toString on StopwatchEvent
This commit is contained in:
parent
d277c16a27
commit
0b88a23cb8
|
@ -234,4 +234,12 @@ class StopwatchEvent
|
|||
|
||||
return round($time, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('%s: %.2F MiB - %d ms', $this->getCategory(), $this->getMemory() / 1024 / 1024, $this->getDuration());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,4 +156,16 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
new StopwatchEvent("abc");
|
||||
}
|
||||
|
||||
public function testHumanRepresentation()
|
||||
{
|
||||
$event = new StopwatchEvent(microtime(true) * 1000);
|
||||
$this->assertEquals('default: 0.00 MiB - 0 ms', (string) $event);
|
||||
$event->start();
|
||||
$event->stop();
|
||||
$this->assertEquals(1, preg_match('/default: [0-9\.]+ MiB - [0-9]+ ms/', (string) $event));
|
||||
|
||||
$event = new StopwatchEvent(microtime(true) * 1000, 'foo');
|
||||
$this->assertEquals('foo: 0.00 MiB - 0 ms', (string) $event);
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue