public function testPostIsHam() { $client = $this->getClient(); $post = new Post(); $post->setUrl('http://jrnv.nl/')->setUserIp('127.0.0.1')->setUserRole('administrator'); $result = $client->check($post); $this->assertFalse($result, 'Post with role "administrator" should always be a ham, but was not.'); }
/** * Checks a post if it's spam. * * Returns true if it's spam, false if it's ham. * * @param Post $post * * @return bool * @throws InvalidResponseException * @throws InvalidArgumentException */ public function check(Post $post) { $data = $post->toArray(); $response = $this->client->request('comment-check', $data); if ((string) $response->getBody() === 'true') { return true; } else { if ((string) $response->getBody() === 'false') { return false; } else { if ((string) $response->getBody() === 'invalid') { throw new InvalidArgumentException(sprintf('Request wasn\'t accepted by Akismet. (%s)', $response->getHeader('X-akismet-debug-help'))); } else { throw new InvalidResponseException(sprintf('Response did not contain either valid or invalid. (%s)', (string) $response->getBody())); } } } }