diff --git a/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php b/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php index 1ba69d19faff..b0e32c962773 100644 --- a/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php +++ b/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php @@ -20,6 +20,8 @@ */ class StopwatchEventTest extends \PHPUnit_Framework_TestCase { + const DELTA = 20; + public function testGetOrigin() { $event = new StopwatchEvent(12); @@ -66,20 +68,18 @@ public function testDuration() { $event = new StopwatchEvent(microtime(true) * 1000); $event->start(); - usleep(20000); + usleep(200000); $event->stop(); - $total = $event->getDuration(); - $this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)'); + $this->assertEquals(200, $event->getDuration(), null, self::DELTA); $event = new StopwatchEvent(microtime(true) * 1000); $event->start(); - usleep(10000); + usleep(100000); $event->stop(); $event->start(); - usleep(10000); + usleep(100000); $event->stop(); - $total = $event->getDuration(); - $this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)'); + $this->assertEquals(200, $event->getDuration(), null, self::DELTA); } /** @@ -96,12 +96,11 @@ public function testEnsureStopped() // this also test overlap between two periods $event = new StopwatchEvent(microtime(true) * 1000); $event->start(); - usleep(10000); + usleep(100000); $event->start(); - usleep(10000); + usleep(100000); $event->ensureStopped(); - $total = $event->getDuration(); - $this->assertTrue($total >= 21 && $total <= 39, $total.' should be 30 (between 21 and 39)'); + $this->assertEquals(300, $event->getDuration(), null, self::DELTA); } public function testStartTime() @@ -116,10 +115,9 @@ public function testStartTime() $event = new StopwatchEvent(microtime(true) * 1000); $event->start(); - usleep(10000); + usleep(100000); $event->stop(); - $start = $event->getStartTime(); - $this->assertTrue($start >= 0 && $start <= 20); + $this->assertEquals(0, $event->getStartTime(), null, self::DELTA); } public function testEndTime() @@ -133,13 +131,12 @@ public function testEndTime() $event = new StopwatchEvent(microtime(true) * 1000); $event->start(); - usleep(10000); + usleep(100000); $event->stop(); $event->start(); - usleep(10000); + usleep(100000); $event->stop(); - $end = $event->getEndTime(); - $this->assertTrue($end >= 11 && $end <= 29, $end.' should be 20 (between 11 and 29)'); + $this->assertEquals(200, $event->getEndTime(), null, self::DELTA); } /** diff --git a/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php b/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php index d1dd2e616bf7..7cb4b64d7915 100644 --- a/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php +++ b/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php @@ -20,6 +20,8 @@ */ class StopwatchTest extends \PHPUnit_Framework_TestCase { + const DELTA = 20; + public function testStart() { $stopwatch = new Stopwatch(); @@ -33,26 +35,24 @@ public function testStop() { $stopwatch = new Stopwatch(); $stopwatch->start('foo', 'cat'); - usleep(20000); + usleep(200000); $event = $stopwatch->stop('foo'); $this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event); - $total = $event->getDuration(); - $this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)'); + $this->assertEquals(200, $event->getDuration(), null, self::DELTA); } public function testLap() { $stopwatch = new Stopwatch(); $stopwatch->start('foo', 'cat'); - usleep(10000); + usleep(100000); $event = $stopwatch->lap('foo'); - usleep(10000); + usleep(100000); $stopwatch->stop('foo'); $this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event); - $total = $event->getDuration(); - $this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)'); + $this->assertEquals(200, $event->getDuration(), null, self::DELTA); } /**