Skip to content

Commit

Permalink
[Tests] Remove occurrences of withConsecutive()
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois authored and nicolas-grekas committed Mar 10, 2023
1 parent bd1cad2 commit 0462d7f
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions Tests/Extension/StopwatchExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\StopwatchExtension;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent;
use Twig\Environment;
use Twig\Error\RuntimeError;
use Twig\Loader\ArrayLoader;
Expand Down Expand Up @@ -67,12 +68,29 @@ protected function getStopwatch($events = [])
$expectedStopCalls[] = [$this->equalTo($eventName)];
}

$startInvocationMocker = $stopwatch->expects($this->exactly($expectedCalls))
->method('start');
\call_user_func_array([$startInvocationMocker, 'withConsecutive'], $expectedStartCalls);
$stopInvocationMocker = $stopwatch->expects($this->exactly($expectedCalls))
->method('stop');
\call_user_func_array([$stopInvocationMocker, 'withConsecutive'], $expectedStopCalls);
$stopwatch
->expects($this->exactly($expectedCalls))
->method('start')
->willReturnCallback(function (string $name, string $category) use (&$expectedStartCalls) {
[$expectedName, $expectedCategory] = array_shift($expectedStartCalls);

$expectedName->evaluate($name);
$this->assertSame($expectedCategory, $category);

return $this->createMock(StopwatchEvent::class);
})
;

$stopwatch
->expects($this->exactly($expectedCalls))
->method('stop')
->willReturnCallback(function (string $name) use (&$expectedStopCalls) {
[$expectedName] = array_shift($expectedStopCalls);
$expectedName->evaluate($name);

return $this->createMock(StopwatchEvent::class);
})
;

return $stopwatch;
}
Expand Down

0 comments on commit 0462d7f

Please sign in to comment.