public function testDeclineFriendship() { $userService = new UsersService(); $userEntity = $userService->findRandUser(); $friendUserEntity = $userService->findRandUser(); $userId = $userEntity->getId(); $friendId = $friendUserEntity->getId(); $url = '/users/' . $userId . '/friends'; $params = ['friend_id' => $friendId]; $response = $this->load($url, 'POST', $params); $this->assertSuccessResponse($response); $url = '/users/' . $userId . '/friends/' . $friendId; $params = ['accept' => false]; $response = $this->load($url, 'PUT', $params); $this->assertSuccessResponse($response); $url = '/users/' . $userId . '/friends'; $response = $this->load($url); $this->assertSuccessResponse($response); $this->assertArrayHasKey("user", $response['result'], 'User was not found in result'); $this->assertArrayHasKey("user_id", $response['result']['user'], 'User id was not found in result'); $this->assertArrayHasKey('friends', $response['result']['user'], 'Friends list was not found in result'); $this->assertNotContains($friendId, $response['result']['user']['friends']); $this->assertEquals($userId, $response['result']['user']['user_id']); $url = '/users/' . $userId . '/friends-requests'; $response = $this->load($url); $this->assertSuccessResponse($response); $this->assertArrayHasKey("user", $response['result'], 'User was not found in result'); $this->assertArrayHasKey("user_id", $response['result']['user'], 'User id was not found in result'); $this->assertArrayHasKey('friends_requests', $response['result']['user'], 'Friends list was not found in result'); $this->assertNotContains($friendId, $response['result']['user']['friends_requests']); $this->assertEquals($userId, $response['result']['user']['user_id']); }
public function friendshipAction() { $userId = $this->dispatcher->getParam('user_id'); $friendId = $this->dispatcher->getParam('friend_id'); $acceptFriendship = $this->request->getPut('accept'); /** * for unit test, becuse with phalcon framework it's not ease emulate PUT request */ if ($acceptFriendship === null) { $acceptFriendship = $_REQUEST['accept']; } $service = new UsersService(); $service->acceptFriendRequest($userId, $friendId, (bool) $acceptFriendship); $result = ['']; return $this->returnResult($result); }