/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->conn = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock(); $this->conn->expects($this->any())->method('getDatabase')->will($this->returnValue('myDatabase')); /* @var $platform AbstractPlatform */ $platform = $this->getMockForAbstractClass('Doctrine\\DBAL\\Platforms\\AbstractPlatform'); $this->conn->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform)); $this->em->expects($this->any())->method('getConnection')->will($this->returnValue($this->conn)); /* @var $meta ClassMetadata */ $meta = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock(); $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($meta)); $this->sc = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\SecurityContextInterface')->getMock(); $this->token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')->getMock(); $this->sc->expects($this->any())->method('getToken')->will($this->returnValue($this->token)); $this->rh = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Role\\RoleHierarchyInterface')->getMock(); $this->object = new AclNativeHelper($this->em, $this->sc, $this->rh); }
/** * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper::getAllowedEntityIds * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper::getPermittedAclIdsSQLForUser */ public function testGetAllowedEntityIds() { $roles = array(new Role('ROLE_KING')); $allRoles = array($roles[0], new Role('ROLE_SUBJECT')); $this->token->expects($this->once())->method('getRoles')->will($this->returnValue($roles)); $this->rh->expects($this->once())->method('getReachableRoles')->with($roles)->will($this->returnValue($allRoles)); $user = $this->getMockBuilder('FOS\\UserBundle\\Model\\UserInterface')->getMock(); $user->expects($this->any())->method('getUsername')->will($this->returnValue('MyUser')); $this->token->expects($this->any())->method('getUser')->will($this->returnValue($user)); $hydrator = $this->getMockBuilder('Doctrine\\ORM\\Internal\\Hydration\\ScalarHydrator')->disableOriginalConstructor()->getMock(); $rows = array(array('id' => 1), array('id' => 9)); $hydrator->expects($this->once())->method('hydrateAll')->will($this->returnValue($rows)); $this->em->expects($this->any())->method('newHydrator')->will($this->returnValue($hydrator)); /* @var $query NativeQuery */ $query = new NativeQuery($this->em); $this->em->expects($this->once())->method('createNativeQuery')->will($this->returnValue($query)); $permissionDef = new PermissionDefinition(array('view'), 'Kunstmaan\\NodeBundle\\Entity\\Node', 'n'); /* @var $result array */ $result = $this->object->getAllowedEntityIds($permissionDef); $this->assertEquals(array(1, 9), $result); }
/** * @test */ public function it_should_retrieve_all_listings_by_channel() { $channel = new Channel("MNB", 'mnb.png'); $this->entityManager->expects($this->once())->method('findBy')->with($this->equalTo(Listing::class))->willReturn(array()); $this->assertEquals(array(), $this->repo->findBy($channel)); }
/** * @test */ public function it_should_find_video_proxy_by_uuid() { $this->entityManager->expects($this->once())->method('findOneBy'); $this->repo->find("fake_uuid"); }