Skip to content

Commit

Permalink
minor #49621 [Tests] Remove occurrences of withConsecutive() (alexa…
Browse files Browse the repository at this point in the history
…ndre-daubois)

This PR was merged into the 5.4 branch.

Discussion
----------

[Tests] Remove occurrences of `withConsecutive()`

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

`withConsecutive()` has been deprecated in PHPUnit 9.6 and removed in PHP 10 (sebastianbergmann/phpunit#4564). This PR aims at starting the work to remove these occurrences. There is unfortunately no given migration path, and this requires manual work.

I'll create a meta issue referencing remaining occurrences if this one's merged, to keep track. Some seems pretty hard to remove.

cc `@OskarStark` this might interest you, as we worked a lot on tests lately 😄

Commits
-------

2047763649 [Tests] Remove occurrences of `withConsecutive()`
  • Loading branch information
nicolas-grekas committed Mar 10, 2023
2 parents beb4caf + 0462d7f commit 355db9a
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 355db9a

Please sign in to comment.