From 0675476ff28d6a4b5b995b3a69c27e7ee890a5db Mon Sep 17 00:00:00 2001 From: Daniel Burger <48986191+danielburger1337@users.noreply.github.com> Date: Mon, 15 Jan 2024 21:50:19 +0100 Subject: [PATCH] Mock TwoFactorDeciderInterface in TwoFactorProviderInitiatorTest --- .../Provider/TwoFactorProviderInitiatorTest.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/Security/TwoFactor/Provider/TwoFactorProviderInitiatorTest.php b/tests/Security/TwoFactor/Provider/TwoFactorProviderInitiatorTest.php index 24b2c7b9..98ce7be4 100644 --- a/tests/Security/TwoFactor/Provider/TwoFactorProviderInitiatorTest.php +++ b/tests/Security/TwoFactor/Provider/TwoFactorProviderInitiatorTest.php @@ -8,7 +8,7 @@ use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenFactory; use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenFactoryInterface; use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface; -use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderDecider; +use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderDeciderInterface; use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderInitiator; use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderInterface; use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistry; @@ -19,6 +19,7 @@ class TwoFactorProviderInitiatorTest extends AbstractAuthenticationContextTestCa private MockObject|TwoFactorTokenFactoryInterface $twoFactorTokenFactory; private MockObject|TwoFactorProviderInterface $provider1; private MockObject|TwoFactorProviderInterface $provider2; + private MockObject|TwoFactorProviderDeciderInterface $providerDecider; private TwoFactorProviderInitiator $initiator; protected function setUp(): void @@ -37,7 +38,9 @@ protected function setUp(): void $this->twoFactorTokenFactory = $this->createMock(TwoFactorTokenFactory::class); - $this->initiator = new TwoFactorProviderInitiator($providerRegistry, $this->twoFactorTokenFactory, new TwoFactorProviderDecider()); + $this->providerDecider = $this->createMock(TwoFactorProviderDeciderInterface::class); + + $this->initiator = new TwoFactorProviderInitiator($providerRegistry, $this->twoFactorTokenFactory, $this->providerDecider); } private function createTwoFactorToken(): MockObject|TwoFactorTokenInterface @@ -77,6 +80,14 @@ private function stubTwoFactorTokenFactoryReturns(MockObject $token): void ->willReturn($token); } + private function stubTwoFactorProviderDeciderReturns(string|null $preferredProvider): void + { + $this->providerDecider + ->expects($this->once()) + ->method('getPreferredTwoFactorProvider') + ->willReturn($preferredProvider); + } + /** * @test */ @@ -142,6 +153,7 @@ public function beginAuthentication_hasPreferredProvider_setThatProviderPreferre $context = $this->createAuthenticationContext(null, $originalToken, $user); $this->stubProvidersReturn(true, true); $this->stubTwoFactorTokenFactoryReturns($twoFactorToken); + $this->stubTwoFactorProviderDeciderReturns('preferredProvider'); $twoFactorToken ->expects($this->once())