/** * Ensures that if the deleteUser method is called and user_id is an * admin, but the delete fails, then an exception is thrown * * @return void */ public function testDeleteUserWithAdminAccessDeletesSuccesfully() { define('UNIT_TEST', 1); $request = new \Request([], ['REQUEST_URI' => "http://api.dev.joind.in/v2.1/users/3", 'REQUEST_METHOD' => 'DELETE']); $request->user_id = 1; $usersController = new \UsersController(); // Please see below for explanation of why we're mocking a "mock" PDO // class $db = $this->getMockBuilder('\\JoindinTest\\Inc\\mockPDO')->getMock(); $userMapper = $this->getMockBuilder('\\UserMapper')->setConstructorArgs(array($db, $request))->getMock(); $userMapper->expects($this->once())->method('thisUserHasAdminOn')->will($this->returnValue(true)); $userMapper->expects($this->once())->method('delete')->will($this->returnValue(true)); $usersController->setUserMapper($userMapper); $this->assertTrue($usersController->deleteUser($request, $db)); }