public function testPostArraySerialization()
 {
     $post = new Post();
     $post->setUrl('http://jrnv.nl/')->setAuthor('Jeroen Visser')->setAuthorEmail('*****@*****.**')->setContent('A beautiful message');
     $expected = ['blog' => 'http://jrnv.nl/', 'comment_type' => 'comment', 'comment_author' => 'Jeroen Visser', 'comment_author_email' => '*****@*****.**', 'comment_content' => 'A beautiful message', 'comment_date_gmt' => (new \DateTime())->format('c'), 'comment_post_modified_gmt' => (new \DateTime())->format('c')];
     $this->assertEquals($expected, $post->toArray(), 'Post serialization is not correct.');
 }
Exemple #2
0
 /**
  * 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()));
             }
         }
     }
 }