Hello,
How do you spec your controller, when besides other things, security is envolved?
My code and all my behat features are ok, but I have problems with my specs when security is envolved.
First, I have an entry point class, that is redirect to acess_denied route, for anonymous user for every route that is under acess_control that requires ROLE_USER in my security.yml file.
Second I have also acl enabled.
But when I try to modify my controller spec, yes I know, it should be first spec then code, I got 2 exception, which broke my specs. I believe that because the collaborator object are somehow different from the real objects.
First exception: " Symfony\Component\Security\Acl\Exception\InvalidDomainObjectException("$domainObject must either implement the DomainObjectInterface, or have a method named "getId".") " from this code " $objectIdentity = ObjectIdentity::fromDomainObject($book);" where $book is double/collaborator of my entity.
Second exception: " InvalidArgumentException("$user must be an instanceof UserInterface, an object implementing a __toString method, or a primitive string.") " from this code: " $token = new UsernamePasswordToken($reader, $reader->getPassword(), 'readers', array('ROLE_USER')); " where $reader is double/collaborator of my if entity.
If you have some working example on how to handle security whit phpspec for symfony2 controller, please let me know. Any advice, are welcome.
Thank you.