Skip to content

Commit

Permalink
Adjusted tests to no longer rely on deprecated PHPUnit 9.x functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Aug 7, 2023
1 parent 1abedda commit 497403a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/FlashMessageMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testProcessUsesConfiguredClassAndSessionKeyAndAttributeKeyToCrea
self::assertSame('non-standard-flash-next', $flash->sessionKey);
return true;
})
)->will(self::returnSelf());
)->willReturnSelf();

$response = $this->createMock(ResponseInterface::class);

Expand Down
28 changes: 26 additions & 2 deletions test/FlashMessagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ public function testProlongFlashAddsCurrentMessagesToNextSession(): void
],
];

$invocationCounter = new class {
public int $count = 0;
};

$this->session
->expects(self::once())
->method('has')
Expand All @@ -207,7 +211,15 @@ public function testProlongFlashAddsCurrentMessagesToNextSession(): void

return true;
}))
->willReturnOnConsecutiveCalls($messages, []);
->willReturnCallback(static function () use ($messages, $invocationCounter) {
$invocationCounter->count += 1;

if ($invocationCounter->count === 1) {
return $messages;
}

return [];
});
$this->session
->expects(self::once())
->method('unset')
Expand Down Expand Up @@ -262,6 +274,10 @@ public function testProlongFlashDoesNotReFlashMessagesThatAlreadyHaveMoreHops():
$messagesExpected['test']['hops'] = 2;
$messagesExpected['test-2']['hops'] = 1;

$invocationCounter = new class {
public int $count = 0;
};

$this->session
->expects(self::once())
->method('has')
Expand All @@ -274,7 +290,15 @@ public function testProlongFlashDoesNotReFlashMessagesThatAlreadyHaveMoreHops():
self::identicalTo(FlashMessagesInterface::FLASH_NEXT),
self::callback(fn ($arg): bool => in_array($arg, [null, []], true)),
)
->willReturnOnConsecutiveCalls($messages, $messagesExpected);
->willReturnCallback(static function () use ($messagesExpected, $messages, $invocationCounter) {
$invocationCounter->count += 1;

if ($invocationCounter->count === 1) {
return $messages;
}

return $messagesExpected;
});
$this->session
->expects(self::once())
->method('set')
Expand Down

0 comments on commit 497403a

Please sign in to comment.