[Stopwatch] added __toString on StopwatchEvent

This commit is contained in:
Damien Alexandre 2014-11-29 12:05:04 +01:00
parent d277c16a27
commit 0b88a23cb8
2 changed files with 20 additions and 0 deletions

View File

@ -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());
}
}

View File

@ -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);
}
}