Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Stopwatch] Fix volatile tests #14597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ public function testEnsureStopped()
$event->start();
usleep(100000);
$event->ensureStopped();
$this->assertEquals(300, $event->getDuration(), null, self::DELTA);
$duration = $event->getDuration();
usleep(100000);
$this->assertEquals($duration, $event->getDuration());
}

public function testStartTime()
Expand Down
9 changes: 4 additions & 5 deletions src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*/
class StopwatchTest extends \PHPUnit_Framework_TestCase
{
const DELTA = 20;

public function testStart()
{
$stopwatch = new Stopwatch();
Expand Down Expand Up @@ -71,11 +69,12 @@ public function testStop()
{
$stopwatch = new Stopwatch();
$stopwatch->start('foo', 'cat');
usleep(200000);
usleep(100000);
$event = $stopwatch->stop('foo');

$duration = $event->getDuration();
usleep(100000);
$this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event);
$this->assertEquals(200, $event->getDuration(), null, self::DELTA);
$this->assertEquals($duration, $event->getDuration());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I always return 0 or null in getDuration (removing the return statement for instance), this test will pass. This means that it is not testing the method anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i don't understand, removing the return statement into the component?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof he is just saying that you are not testing the method anymore with your changes. And indeed, it looks wrong to me. You just call getDuration() twice, and the second time, you check it returns the same as the first call. That does not test if the returned value is actually correct.

}

/**
Expand Down