Closed kenjis closed 12 years ago
I don't think those can be tested because they return a value relative to the machine you run the tests on.
How about this?
$start = microtime(true);
exec('sleep 2');
$stop = microtime(true);
$time = $stop - $start;
//echo $time, PHP_EOL;
$this->assertEquals(2, round($time));
Edited: I changed (int) to round().
That isn't all that usefull and seriously slows down testing. In this case all you'd test is whether the output is of the expected type (float) and larger than 0. Everything else is environmental and indeed not testable.
Current test code is below:
$start = time();
exec('sleep 2');
$stop = time();
$this->assertEquals($start + 2, $stop);
Why does my proposal seriously slow down testing? Only I do is to loose the test condition.
In current code, If start time were 1337499484.999, and it took 2.001 sec, then the test failed.
Of course, I don't think my proposal is good test. Just reduce the probability of fails. I don't know what should this test method test.
Up ... I think that the CLI speed is not testable, depends on the machine ...
On my netbook sometimes it fail
Test_Cli::test_exec_speed() and test_spawn_speed() fails in rare cases.
I've got a report on Mac OS X and I have failed once on Windows.