anonymous//tests/RequestFactoryTest.php$0
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 1
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 0
c 1
b 0
f 0
dl 0
loc 1
ccs 1
cts 1
cp 1
1
<?php
2
3
namespace Pomopult\Dadata\Tests;
4
5
use GuzzleHttp\Client;
6
use PHPUnit\Framework\TestCase;
7
use Promopult\Dadata\Credentials;
8
use Promopult\Dadata\Service;
9
10
class RequestFactoryTest extends TestCase
11
{
12 4
    private $factory;
13
14 4
    public function setUp(): void
15 4
    {
16
        $credentials = $this->createMock(Credentials::class);
17 1
        $credentials->method('getSecret')->willReturn('secret1234');
18
        $credentials->method('getToken')->willReturn('token1234');
19 1
20
        $httpClient = $this->createMock(Client::class);
21 1
22 1
        $this->factory = new class($credentials, $httpClient)  extends Service {};
23
    }
24 1
25
    public function testRequestFactoryMustCreateRequestInterface()
26 1
    {
27
        $request = $this->factory->createRequest('POST', 'https://example.com');
28 1
29 1
        $this->assertInstanceOf(\Psr\Http\Message\RequestInterface::class, $request);
30 1
    }
31
32 1
    public function testRequestHeadersMustContainsCredentials()
33
    {
34 1
        $req = $this->factory->createRequest('POST', 'https://example.com');
35
36 1
        $this->assertEquals(['secret1234'], $req->getHeader('X-Secret'));
37 1
        $this->assertEquals(['Token token1234'], $req->getHeader('Authorization'));
38 1
    }
39
40 1
    public function testRequestHeadersMustContainsAcceptAndContentTypeHeaders()
41
    {
42 1
        $req = $this->factory->createRequest('POST', 'https://example.com');
43
44 1
        $this->assertEquals(['application/json'], $req->getHeader('Accept'));
45 1
        $this->assertEquals(['application/json'], $req->getHeader('Content-Type'));
46
    }
47
48
    public function testRequestMustContainsJsonBodyWithCorrectData()
49
    {
50
        $req = $this->factory->createRequest('POST', 'https://example.com', ['query' => 'test']);
51
52
        $this->assertJsonStringEqualsJsonFile(__DIR__.'/resources/body.json', $req->getBody()->getContents());
53
    }
54
}
55