private function save(array $data) { $path = $_SERVER['REQUEST_URI']; $path = explode('/', $path); $path = array_filter($path); $path = array_slice($path, 0, 2); $path = implode('/', $path); $body = ['commenter' => ['name' => $data['name'], 'email' => $data['email'], 'website' => $data['website']], 'body' => $data['comment'], 'should_notify' => isset($data['notify']) && $data['notify'] == 'check', 'domain' => URLDecode::getSite() == 'blog' ? 'blog.jacobemerick.com' : 'waterfallsofthekeweenaw.com', 'path' => $path, 'url' => "{$this->fullPath}#comment-{{id}}", 'thread' => 'comments', 'reply_to' => $data['type'] == 'new' ? 0 : $data['type'], 'ip_address' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER']]; global $container; $repository = new ServiceCommentRepository($container['comment_service_api']); try { $response = $repository->createComment($body); } catch (Exception $e) { $container['logger']->warning("CommentService | Create | {$e->getMessage()}"); return null; } return $response['id']; }
/** * @expectedException Jacobemerick\CommentService\ApiException */ public function testGetCommentsFailure() { $apiException = new ApiException(); $defaultApi = $this->getMockBuilder(DefaultApi::class)->getMock(); $defaultApi->method('getComments')->will($this->throwException($apiException)); $repository = new ServiceCommentRepository($defaultApi); $repository->getComments(); }