Symfony phpunit测试getUser()

时间:2017-01-17 11:15:20

标签: symfony mocking phpunit

如何在测试中设置

$this->getUser();

我尝试这样做:

 $token = $this->getMockBuilder(Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)
                ->disableOriginalConstructor()
                ->setMethods(['getUser'])
                ->getMock();      
        $token->expects($this->any())                                                          
              ->method('getUser')                                                               
              ->willReturn($user); 

        $service = $this->getMockBuilder('Symfony\Component\Security\Core\SecurityContextInterface')
              ->disableOriginalConstructor()                                                    
              ->getMock();  
        $service->expects($this->any())                                                        
              ->method('getToken')                                                         
              ->willReturn($token);     

        $client4->getContainer()
            ->set('security.token_storage', $token);

我试试谷歌,但没有任何帮助我...

0 个答案:

没有答案