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

RequestFactoryTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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