diff --git a/src/Symfony/Component/Stopwatch/StopwatchEvent.php b/src/Symfony/Component/Stopwatch/StopwatchEvent.php index 453437f011..81140421ed 100644 --- a/src/Symfony/Component/Stopwatch/StopwatchEvent.php +++ b/src/Symfony/Component/Stopwatch/StopwatchEvent.php @@ -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()); + } } diff --git a/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php b/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php index 1881f8afeb..fb7183d5e4 100644 --- a/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php +++ b/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php @@ -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); + } }