setCreatedAtValue(); $context = []; $client = new MockHttpClient([new MockResponse('invalid', ['response_headers' => ['x-akismet-debug-help: Invalid key']])]); $checker = new SpamChecker($client, 'abcde'); $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Unable to check for spam: invalid (Invalid key).'); $checker->getSpamScore($comment, $context); } /** * @dataProvider provideComments */ public function testSpamScore(int $expectedScore, ResponseInterface $response, Comment $comment, array $context) { $client = new MockHttpClient([$response]); $checker = new SpamChecker($client, 'abcde'); $score = $checker->getSpamScore($comment, $context); $this->assertSame($expectedScore, $score); } public static function provideComments(): iterable { $comment = new Comment(); $comment->setCreatedAtValue(); $context = []; $response = new MockResponse('', ['response_headers' => ['x-akismet-pro-tip: discard']]); yield 'blatant_spam' => [2, $response, $comment, $context]; $response = new MockResponse('true'); yield 'spam' => [1, $response, $comment, $context]; $response = new MockResponse('false'); yield 'ham' => [0, $response, $comment, $context]; } }