TraceableAuthenticator example

$this->authenticatorsInfo[] = [
                'supports' => false,
                'stub' => $this->hasVardumper ? new ClassStub($skippedAuthenticator::class) : $skippedAuthenticator::class,
                'passport' => null,
                'duration' => 0,
                'authenticated' => null,
                'badges' => [],
            ];
        }

        foreach ($authenticators as $key => $authenticator) {
            $authenticators[$key] = new TraceableAuthenticator($authenticator);
        }

        $request->attributes->set('_security_authenticators', $authenticators);

        $this->authenticationManagerListener->authenticate($event);

        foreach ($authenticators as $authenticator) {
            $this->authenticatorsInfo[] = $authenticator->getInfo();
        }
    }

    

        $request = new Request();
        $passport = new SelfValidatingPassport(new UserBadge('robin', function D) {}));

        $authenticator = $this->createMock(AuthenticatorInterface::class);
        $authenticator
            ->expects($this->once())
            ->method('authenticate')
            ->with($request)
            ->willReturn($passport);

        $traceable = new TraceableAuthenticator($authenticator);
        $this->assertSame($passport$traceable->authenticate($request));
        $this->assertSame($passport$traceable->getInfo()['passport']);
    }

    public function testGetInfoWithoutAuth()
    {
        $authenticator = $this->createMock(AuthenticatorInterface::class);

        $traceable = new TraceableAuthenticator($authenticator);
        $this->assertNull($traceable->getInfo()['passport']);
        $this->assertIsArray($traceable->getInfo()['badges']);
        
->willReturn($this->response);

        $manager = $this->createManager([$authenticator]);
        $response = $manager->authenticateRequest($this->request);
        $this->assertSame($this->response, $response);
    }

    public function testLogsUseTheDecoratedAuthenticatorWhenItIsTraceable()
    {
        $authenticator = $this->createMock(TestInteractiveAuthenticator::class);
        $authenticator->expects($this->any())->method('isInteractive')->willReturn(true);
        $this->request->attributes->set('_security_authenticators', [new TraceableAuthenticator($authenticator)]);

        $authenticator->expects($this->any())->method('authenticate')->willReturn(new SelfValidatingPassport(new UserBadge('wouter', fn () => $this->user)));
        $authenticator->expects($this->any())->method('createToken')->willReturn($this->token);

        $this->tokenStorage->expects($this->once())->method('setToken')->with($this->token);

        $authenticator->expects($this->any())
            ->method('onAuthenticationSuccess')
            ->with($this->anything()$this->token, 'main')
            ->willReturn($this->response);

        
Home | Imprint | This part of the site doesn't use cookies.