コード例 #1
0
 /** @dataProvider provideRoles */
 public function testCollectAuthenticationTokenAndRoles(array $roles, array $normalizedRoles)
 {
     $securityContext = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $securityContext->expects($this->once())->method('getToken')->willReturn(new UsernamePasswordToken('hhamon', 'P4$$w0rD', 'provider', $roles));
     $collector = new SecurityDataCollector($securityContext);
     $collector->collect($this->getRequest(), $this->getResponse());
     $this->assertTrue($collector->isEnabled());
     $this->assertTrue($collector->isAuthenticated());
     $this->assertSame('Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken', $collector->getTokenClass());
     $this->assertSame($normalizedRoles, $collector->getRoles());
     $this->assertSame('hhamon', $collector->getUser());
 }
コード例 #2
0
 /** @dataProvider provideRoles */
 public function testCollectAuthenticationTokenAndRoles(array $roles, array $normalizedRoles)
 {
     $tokenStorage = new TokenStorage();
     $tokenStorage->setToken(new UsernamePasswordToken('hhamon', 'P4$$w0rD', 'provider', $roles));
     $collector = new SecurityDataCollector($tokenStorage);
     $collector->collect($this->getRequest(), $this->getResponse());
     $this->assertTrue($collector->isEnabled());
     $this->assertTrue($collector->isAuthenticated());
     $this->assertSame('Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken', $collector->getTokenClass());
     $this->assertSame($normalizedRoles, $collector->getRoles());
     $this->assertSame('hhamon', $collector->getUser());
 }