Skip to content

Commit

Permalink
minor #54768 Remove calls to onConsecutiveCalls() (alexandre-daubois)
Browse files Browse the repository at this point in the history
This PR was merged into the 5.4 branch.

Discussion
----------

Remove calls to `onConsecutiveCalls()`

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

cc `@OskarStark` as we did a lot of stuff on tests migration last year

Commits
-------

4118849d86 Remove calls to `onConsecutiveCalls()`
  • Loading branch information
nicolas-grekas committed Apr 30, 2024
2 parents 96e9ede + aa6a398 commit 51ffc08
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
20 changes: 10 additions & 10 deletions Tests/EventListener/SessionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SessionListenerTest extends TestCase
public function testSessionCookieOptions(array $phpSessionOptions, array $sessionOptions, array $expectedSessionOptions)
{
$session = $this->createMock(Session::class);
$session->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->method('getUsageIndex')->willReturn(0, 1);
$session->method('getId')->willReturn('123456');
$session->method('getName')->willReturn('PHPSESSID');
$session->method('save');
Expand Down Expand Up @@ -398,7 +398,7 @@ public function testSessionUsesFactory()
public function testResponseIsPrivateIfSessionStarted()
{
$session = $this->createMock(Session::class);
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);

$container = new Container();
$container->set('initialized_session', $session);
Expand All @@ -423,7 +423,7 @@ public function testResponseIsPrivateIfSessionStarted()
public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent()
{
$session = $this->createMock(Session::class);
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);

$container = new Container();
$container->set('initialized_session', $session);
Expand All @@ -450,7 +450,7 @@ public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent()
public function testSessionSaveAndResponseHasSessionCookie()
{
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);
$session->expects($this->exactly(1))->method('getId')->willReturn('123456');
$session->expects($this->exactly(1))->method('getName')->willReturn('PHPSESSID');
$session->expects($this->exactly(1))->method('save');
Expand Down Expand Up @@ -535,7 +535,7 @@ public function testUninitializedSessionWithoutInitializedSession()
public function testResponseHeadersMaxAgeAndExpiresNotBeOverridenIfSessionStarted()
{
$session = $this->createMock(Session::class);
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);

$container = new Container();
$container->set('initialized_session', $session);
Expand Down Expand Up @@ -565,7 +565,7 @@ public function testResponseHeadersMaxAgeAndExpiresNotBeOverridenIfSessionStarte
public function testResponseHeadersMaxAgeAndExpiresDefaultValuesIfSessionStarted()
{
$session = $this->createMock(Session::class);
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);

$container = new Container();
$container->set('initialized_session', $session);
Expand Down Expand Up @@ -618,7 +618,7 @@ public function testSurrogateMainRequestIsPublic()
{
$session = $this->createMock(Session::class);
$session->expects($this->exactly(1))->method('getName')->willReturn('PHPSESSID');
$session->expects($this->exactly(4))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1, 1, 1));
$session->expects($this->exactly(4))->method('getUsageIndex')->willReturn(0, 1, 1, 1);

$container = new Container();
$container->set('initialized_session', $session);
Expand Down Expand Up @@ -715,7 +715,7 @@ public function testGetSessionSetsSessionOnMainRequest()
public function testSessionUsageExceptionIfStatelessAndSessionUsed()
{
$session = $this->createMock(Session::class);
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);

$container = new Container();
$container->set('initialized_session', $session);
Expand All @@ -734,7 +734,7 @@ public function testSessionUsageExceptionIfStatelessAndSessionUsed()
public function testSessionUsageLogIfStatelessAndSessionUsed()
{
$session = $this->createMock(Session::class);
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);

$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->exactly(1))->method('warning');
Expand All @@ -759,7 +759,7 @@ public function testSessionIsSavedWhenUnexpectedSessionExceptionThrown()
$session->expects($this->exactly(1))->method('getId')->willReturn('123456');
$session->expects($this->exactly(1))->method('getName')->willReturn('PHPSESSID');
$session->method('isStarted')->willReturn(true);
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);
$session->expects($this->exactly(1))->method('save');

$container = new Container();
Expand Down
15 changes: 11 additions & 4 deletions Tests/Fragment/InlineFragmentRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,17 @@ public function testRenderExceptionIgnoreErrors()

public function testRenderExceptionIgnoreErrorsWithAlt()
{
$strategy = new InlineFragmentRenderer($this->getKernel($this->onConsecutiveCalls(
$this->throwException(new \RuntimeException('foo')),
$this->returnValue(new Response('bar'))
)));
$strategy = new InlineFragmentRenderer($this->getKernel($this->returnCallback(function () {
static $firstCall = true;

if ($firstCall) {
$firstCall = false;

throw new \RuntimeException('foo');
}

return new Response('bar');
})));

$this->assertEquals('bar', $strategy->render('/', Request::create('/'), ['ignore_errors' => true, 'alt' => '/foo'])->getContent());
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/HttpCache/EsiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ protected function getCache($request, $response)
if (\is_array($response)) {
$cache->expects($this->any())
->method('handle')
->will($this->onConsecutiveCalls(...$response))
->willReturn(...$response)
;
} else {
$cache->expects($this->any())
Expand Down
2 changes: 1 addition & 1 deletion Tests/HttpCache/SsiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected function getCache($request, $response)
if (\is_array($response)) {
$cache->expects($this->any())
->method('handle')
->will($this->onConsecutiveCalls(...$response))
->willReturn(...$response)
;
} else {
$cache->expects($this->any())
Expand Down

0 comments on commit 51ffc08

Please sign in to comment.