/** * tests setRoles() with a non array as argument */ public function testGetRolesShouldBeArray() { $this->user->setRoles('test'); $this->assertEquals(array('test'), $this->user->getRoles()); }
/** * tests the formdelAction with an existing user */ public function testFormdelActionExistingUser() { $user = new User(); $user->setId('someId'); $user->setEmail('*****@*****.**'); $user->setRoles('ROLE_USER'); $this->loadMongoContainer(); $request = $this->getMockBuilder("Symfony\\Component\\HttpFoundation\\Request")->disableOriginalConstructor()->getMock(); $postMock = $this->getMockBuilder("Symfony\\Component\\HttpFoundation\\ParameterBag")->disableOriginalConstructor()->getMock(); $postArray = array('formtype' => 'user', 'id' => $user->getId()); $postMock->expects($this->once())->method("all")->will($this->returnValue($postArray)); $request->request = $postMock; $this->repository->expects($this->once())->method('find')->with($user->getId())->will($this->returnValue($user)); $dm = $this->getMockBuilder('Doctrine\\ODM\\MongoDB\\DocumentManager')->disableOriginalConstructor()->getMock(); $this->service->expects($this->once())->method('getManager')->will($this->returnValue($dm)); $dm->expects($this->once())->method('remove')->with($user); $dm->expects($this->once())->method('flush'); $controller = new DefaultController(); $controller->setContainer($this->container); /* @var $response \Symfony\Component\HttpFoundation\Response */ $response = $controller->formdelAction($request); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response); $json = $response->getContent(); $this->assertJson($json); $json = json_decode($json); $this->assertFalse($json->error); }