Search code examples
symfonyphpspec

Phpspec return bad value


I created register service and I want test that method. In the browser var_dump return true and phpspec return false.. Why ? Any Ideas?

Service : http://pastebin.com/9hYX7S14 Phpspec : http://pastebin.com/xm5NLYyG

Please help.


Solution

  • You need to stub (or mock) all your dependencies:

        function it_check_user_exist_in_system(
            Registry $doctrine, 
            ObjectRepository $repository,
            User $user
        )
        {
            $doctrine->getManager()->willReturn($doctrine);
            $doctrine->getRepository('AcmeUserBundle:User')->willReturn($repository)
    
            $repository->findOneBy(array('username'=>'user1'))->willReturn($user);
    
            $this->checkUser('user1')->shouldReturn(true);
        }