Skip to content

Commit 1e00df1

Browse files
committed
Replace Phake with Mockery in ResetRememberedWayfControllerTest
# If applied, this commit will... Convert the remaining Phake-based mocking in ResetRememberedWayfControllerTest to Mockery, matching the rest of the test suite. # Why is this change needed? Prior to this change, the test mixed Phake (for CookieService) with Mockery (for LoggerInterface) in the same class. Phake is deprecated in this codebase and only used in a handful of legacy test files, and mixing mocking libraries in one test class adds unnecessary cognitive overhead. # How does it address the issue? This change replaces Phake::mock()/when()/verify() calls with declarative Mockery::mock()->shouldReceive()->with()->andReturn() expectations set up before the action under test runs. The "no interaction expected" case relies on Mockery's default strict behaviour, which throws automatically on any unstubbed method call, so no explicit verification call is needed. # Provide links to any relevant tickets, articles or other resources Addresses review comment on PR #2094.
1 parent 6997c26 commit 1e00df1

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

‎tests/unit/OpenConext/EngineBlockBundle/Controller/ResetRememberedWayfControllerTest.php‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use OpenConext\EngineBlock\Service\TimeProvider\TimeProvider;
2828
use OpenConext\EngineBlock\Service\Wayf\RememberedIdpCookie;
2929
use OpenConext\EngineBlockBundle\Controller\ResetRememberedWayfController;
30-
use Phake;
3130
use PHPUnit\Framework\Attributes\Test;
3231
use PHPUnit\Framework\TestCase;
3332
use Psr\Log\LoggerInterface;
@@ -47,8 +46,18 @@ class ResetRememberedWayfControllerTest extends TestCase
4746
#[Test]
4847
public function cookie_with_valid_entries_is_cleared_and_logged_with_entry_count(): void
4948
{
50-
$cookieService = Phake::mock(CookieService::class);
51-
Phake::when($cookieService)->clearCookieWithSameSite(Phake::anyParameters())->thenReturn(true);
49+
$cookieService = Mockery::mock(CookieService::class);
50+
$cookieService->shouldReceive('clearCookieWithSameSite')
51+
->once()
52+
->with(
53+
RememberedIdpCookie::NAME,
54+
self::COOKIE_PATH,
55+
self::COOKIE_DOMAIN,
56+
true,
57+
true,
58+
'None'
59+
)
60+
->andReturn(true);
5261

5362
$rememberedIdpCookie = $this->buildRememberedIdpCookie($cookieService);
5463
$raw = $rememberedIdpCookie->encode([
@@ -67,21 +76,13 @@ public function cookie_with_valid_entries_is_cleared_and_logged_with_entry_count
6776

6877
$this->assertSame(Response::HTTP_FOUND, $response->getStatusCode());
6978
$this->assertSame(self::REDIRECT_URL, $response->getTargetUrl());
70-
Phake::verify($cookieService)->clearCookieWithSameSite(
71-
RememberedIdpCookie::NAME,
72-
self::COOKIE_PATH,
73-
self::COOKIE_DOMAIN,
74-
true,
75-
true,
76-
'None'
77-
);
7879
}
7980

8081
#[Test]
8182
public function invalid_cookie_is_still_cleared_and_logged_with_zero_entries(): void
8283
{
83-
$cookieService = Phake::mock(CookieService::class);
84-
Phake::when($cookieService)->clearCookieWithSameSite(Phake::anyParameters())->thenReturn(true);
84+
$cookieService = Mockery::mock(CookieService::class);
85+
$cookieService->shouldReceive('clearCookieWithSameSite')->once()->andReturn(true);
8586

8687
$rememberedIdpCookie = $this->buildRememberedIdpCookie($cookieService);
8788

@@ -96,13 +97,12 @@ public function invalid_cookie_is_still_cleared_and_logged_with_zero_entries():
9697

9798
$this->assertSame(Response::HTTP_FOUND, $response->getStatusCode());
9899
$this->assertSame(self::REDIRECT_URL, $response->getTargetUrl());
99-
Phake::verify($cookieService)->clearCookieWithSameSite(Phake::anyParameters());
100100
}
101101

102102
#[Test]
103103
public function missing_cookie_is_not_cleared_or_logged_but_still_redirects(): void
104104
{
105-
$cookieService = Phake::mock(CookieService::class);
105+
$cookieService = Mockery::mock(CookieService::class);
106106
$rememberedIdpCookie = $this->buildRememberedIdpCookie($cookieService);
107107

108108
$logger = Mockery::mock(LoggerInterface::class);
@@ -114,7 +114,6 @@ public function missing_cookie_is_not_cleared_or_logged_but_still_redirects(): v
114114

115115
$this->assertSame(Response::HTTP_FOUND, $response->getStatusCode());
116116
$this->assertSame(self::REDIRECT_URL, $response->getTargetUrl());
117-
Phake::verifyNoInteraction($cookieService);
118117
}
119118

120119
#[Test]
@@ -123,7 +122,7 @@ public function constructor_rejects_an_empty_redirect_url(): void
123122
$this->expectException(InvalidArgumentException::class);
124123

125124
new ResetRememberedWayfController(
126-
$this->buildRememberedIdpCookie(Phake::mock(CookieService::class)),
125+
$this->buildRememberedIdpCookie(Mockery::mock(CookieService::class)),
127126
Mockery::mock(LoggerInterface::class),
128127
''
129128
);

0 commit comments

Comments
 (0)