Contao\CoreBundle\Test\EventListener\UserSessionListenerTest::testSessionReplacedOnKernelRequest PHP Method

testSessionReplacedOnKernelRequest() public method

Tests that the session is replaced upon kernel.request.
public testSessionReplacedOnKernelRequest ( string $scope, string $userClass, string $sessionBagName )
$scope string
$userClass string
$sessionBagName string
    public function testSessionReplacedOnKernelRequest($scope, $userClass, $sessionBagName)
    {
        $sessionValuesToBeSet = ['foo' => 'bar', 'lonesome' => 'looser'];
        $responseEvent = new GetResponseEvent($this->mockKernel(), new Request(), HttpKernelInterface::MASTER_REQUEST);
        $session = $this->mockSession();
        $user = $this->getMockBuilder($userClass)->setMethods(['__get'])->getMock();
        $user->expects($this->any())->method('__get')->with($this->equalTo('session'))->willReturn($sessionValuesToBeSet);
        $token = $this->getMock('Contao\\CoreBundle\\Security\\Authentication\\ContaoToken', [], [], '', false);
        $token->expects($this->any())->method('getUser')->willReturn($user);
        $tokenStorage = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface');
        $tokenStorage->expects($this->any())->method('getToken')->willReturn($token);
        $listener = $this->getListener($session, null, $tokenStorage);
        $listener->setContainer($this->mockContainerWithContaoScopes($scope));
        $listener->onKernelRequest($responseEvent);
        /** @var AttributeBagInterface $bag */
        $bag = $session->getBag($sessionBagName);
        $this->assertSame($sessionValuesToBeSet, $bag->all());
    }