Skip to content

Commit 355db9a

Browse files
minor #49621 [Tests] Remove occurrences of withConsecutive() (alexandre-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()`
2 parents beb4caf + 0462d7f commit 355db9a

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

Tests/Extension/StopwatchExtensionTest.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\Twig\Extension\StopwatchExtension;
1616
use Symfony\Component\Stopwatch\Stopwatch;
17+
use Symfony\Component\Stopwatch\StopwatchEvent;
1718
use Twig\Environment;
1819
use Twig\Error\RuntimeError;
1920
use Twig\Loader\ArrayLoader;
@@ -67,12 +68,29 @@ protected function getStopwatch($events = [])
6768
$expectedStopCalls[] = [$this->equalTo($eventName)];
6869
}
6970

70-
$startInvocationMocker = $stopwatch->expects($this->exactly($expectedCalls))
71-
->method('start');
72-
\call_user_func_array([$startInvocationMocker, 'withConsecutive'], $expectedStartCalls);
73-
$stopInvocationMocker = $stopwatch->expects($this->exactly($expectedCalls))
74-
->method('stop');
75-
\call_user_func_array([$stopInvocationMocker, 'withConsecutive'], $expectedStopCalls);
71+
$stopwatch
72+
->expects($this->exactly($expectedCalls))
73+
->method('start')
74+
->willReturnCallback(function (string $name, string $category) use (&$expectedStartCalls) {
75+
[$expectedName, $expectedCategory] = array_shift($expectedStartCalls);
76+
77+
$expectedName->evaluate($name);
78+
$this->assertSame($expectedCategory, $category);
79+
80+
return $this->createMock(StopwatchEvent::class);
81+
})
82+
;
83+
84+
$stopwatch
85+
->expects($this->exactly($expectedCalls))
86+
->method('stop')
87+
->willReturnCallback(function (string $name) use (&$expectedStopCalls) {
88+
[$expectedName] = array_shift($expectedStopCalls);
89+
$expectedName->evaluate($name);
90+
91+
return $this->createMock(StopwatchEvent::class);
92+
})
93+
;
7694

7795
return $stopwatch;
7896
}

0 commit comments

Comments
 (0)