Skip to content

Commit

Permalink
Mock TwoFactorDeciderInterface in TwoFactorProviderInitiatorTest
Browse files Browse the repository at this point in the history
  • Loading branch information
danielburger1337 committed Jan 15, 2024
1 parent c858536 commit 0675476
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 0675476

Please sign in to comment.