55/**
66 * Abstract test class with methods for creating callbacks and asserting runtimes.
77 */
8- abstract class TestCase extends \PHPUnit \Framework \TestCase {
8+ abstract class TestCase extends \PHPUnit \Framework \TestCase
9+ {
910 const RUNTIME_PRECISION = 2 ; // Number of decimals to use in runtime calculations/comparisons.
1011
1112 /**
@@ -16,7 +17,8 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
1617 * @return callable|\PHPUnit_Framework_MockObject_MockObject Object that is callable and expects to be called the
1718 * given number of times.
1819 */
19- public function createCallback (int $ count ): callable {
20+ public function createCallback (int $ count ): callable
21+ {
2022 $ mock = $ this ->createMock (CallbackStub::class);
2123
2224 $ mock ->expects ($ this ->exactly ($ count ))
@@ -30,33 +32,24 @@ public function createCallback(int $count): callable {
3032 *
3133 * @param callable $callback
3234 * @param int $maxRunTime Max runtime allowed for the test to pass.
33- * @param mixed[] $args Function arguments.
35+ * @param mixed[] $args Function arguments.
3436 */
35- public function assertRunTimeLessThan (callable $ callback , int $ maxRunTime , array $ args = []) {
37+ public function assertRunTimeLessThan (callable $ callback , int $ maxRunTime , array $ args = [])
38+ {
3639 $ this ->assertRunTimeBetween ($ callback , 0 , $ maxRunTime , $ args );
3740 }
3841
39- /**
40- * Asserts that the given callback takes more than $minRunTime to run.
41- *
42- * @param callable $callback
43- * @param int $minRunTime Minimum runtime allowed for the test to pass.
44- * @param mixed[] $args Function arguments.
45- */
46- public function assertRunTimeGreaterThan (callable $ callback , int $ minRunTime , array $ args = []) {
47- $ this ->assertRunTimeBetween ($ callback , $ minRunTime , 0 , $ args );
48- }
49-
5042 /**
5143 * Asserts that the given callback takes between $minRunTime and $maxRunTime to execute.
5244 * Rounds to the nearest 100 ms.
5345 *
5446 * @param callable $callback
5547 * @param int $minRunTime Minimum runtime allowed for the test to pass.
5648 * @param int $maxRunTime Max runtime allowed for the test to pass.
57- * @param mixed[] $args Function arguments.
49+ * @param mixed[] $args Function arguments.
5850 */
59- public function assertRunTimeBetween (callable $ callback , int $ minRunTime , int $ maxRunTime , array $ args = []) {
51+ public function assertRunTimeBetween (callable $ callback , int $ minRunTime , int $ maxRunTime , array $ args = [])
52+ {
6053 $ start = \microtime (true );
6154
6255 $ callback (...$ args );
@@ -80,14 +73,27 @@ public function assertRunTimeBetween(callable $callback, int $minRunTime, int $m
8073 }
8174 }
8275
76+ /**
77+ * Asserts that the given callback takes more than $minRunTime to run.
78+ *
79+ * @param callable $callback
80+ * @param int $minRunTime Minimum runtime allowed for the test to pass.
81+ * @param mixed[] $args Function arguments.
82+ */
83+ public function assertRunTimeGreaterThan (callable $ callback , int $ minRunTime , array $ args = [])
84+ {
85+ $ this ->assertRunTimeBetween ($ callback , $ minRunTime , 0 , $ args );
86+ }
87+
8388 /**
8489 * Runs the given callback in a separate fork.
8590 *
8691 * @param callable $function
8792 *
8893 * @return int
8994 */
90- final protected function doInFork (callable $ function ) {
95+ final protected function doInFork (callable $ function )
96+ {
9197 switch ($ pid = \pcntl_fork ()) {
9298 case -1 :
9399 $ this ->fail ('Failed to fork process. ' );
0 commit comments