-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSymfonyClientRequestMethodTest.php
More file actions
51 lines (43 loc) · 1.93 KB
/
SymfonyClientRequestMethodTest.php
File metadata and controls
51 lines (43 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Beelab\Recaptcha2Bundle\Tests\Recaptcha;
use Beelab\Recaptcha2Bundle\Recaptcha\SymfonyClientRequestMethod;
use PHPUnit\Framework\TestCase;
use ReCaptcha\RequestParameters;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
final class SymfonyClientRequestMethodTest extends TestCase
{
/** @var \PHPUnit\Framework\MockObject\MockObject|HttpClientInterface */
protected $client;
protected function setUp(): void
{
$this->client = $this->createMock(HttpClientInterface::class);
}
public function testServiceNotInjected(): void
{
$method = new SymfonyClientRequestMethod();
$this->expectException(\UnexpectedValueException::class);
$method->submit(new RequestParameters('', ''));
}
public function testRequestFailure(): void
{
$method = new SymfonyClientRequestMethod();
$method->setClient($this->client);
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->once())->method('getStatusCode')->willReturn(404);
$this->client->expects($this->once())->method('request')->willReturn($response);
$content = $method->submit(new RequestParameters('', ''));
self::assertEquals('{"success": false, "error-codes": ["connection-failed"]}', $content);
}
public function testRequestSuccess(): void
{
$method = new SymfonyClientRequestMethod();
$method->setClient($this->client);
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->once())->method('getStatusCode')->willReturn(200);
$response->expects($this->once())->method('getContent')->willReturn('"OK"');
$this->client->expects($this->once())->method('request')->willReturn($response);
$content = $method->submit(new RequestParameters('', ''));
self::assertEquals('"OK"', $content);
}
}