Passed
Push — master ( 170ab0...f3a34d )
by Dmitry
01:14
created

RequestFactoryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 37
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testRequestMustContainsJsonBodyWithCorrectData() 0 5 1
A testRequestHeadersMustContainsAcceptAndContentTypeHeaders() 0 6 1
A testRequestHeadersMustContainsCredentials() 0 6 1
A setUp() 0 3 1
A testRequestFactoryMustCreateRequestInterface() 0 5 1
1
<?php
2
3
namespace Pomopult\Dadata\Tests;
4
5
use Promopult\Dadata\RequestFactory;
6
use PHPUnit\Framework\TestCase;
7
8
class RequestFactoryTest extends TestCase
9
{
10
    private $factory;
11
12 4
    public function setUp(): void
13
    {
14 4
        $this->factory = new RequestFactory('token1234', 'secret1234');
15 4
    }
16
17 1
    public function testRequestFactoryMustCreateRequestInterface()
18
    {
19 1
        $request = $this->factory->createRequest('POST', 'https://example.com');
20
21 1
        $this->assertInstanceOf(\Psr\Http\Message\RequestInterface::class, $request);
22 1
    }
23
24 1
    public function testRequestHeadersMustContainsCredentials()
25
    {
26 1
        $req = $this->factory->createRequest('POST', 'https://example.com');
27
28 1
        $this->assertEquals(['secret1234'], $req->getHeader('X-Secret'));
29 1
        $this->assertEquals(['Token token1234'], $req->getHeader('Authorization'));
30 1
    }
31
32 1
    public function testRequestHeadersMustContainsAcceptAndContentTypeHeaders()
33
    {
34 1
        $req = $this->factory->createRequest('POST', 'https://example.com');
35
36 1
        $this->assertEquals(['application/json'], $req->getHeader('Accept'));
37 1
        $this->assertEquals(['application/json'], $req->getHeader('Content-Type'));
38 1
    }
39
40 1
    public function testRequestMustContainsJsonBodyWithCorrectData()
41
    {
42 1
        $req = $this->factory->createRequest('POST', 'https://example.com', ['query' => 'test']);
43
44 1
        $this->assertJsonStringEqualsJsonFile(__DIR__.'/resources/body.json', $req->getBody()->getContents());
45 1
    }
46
}
47