Completed
Push — master ( aaccd5...c6e65b )
by Jonathan
10s
created

IssueClientTest::testExecuteNullNextUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ChangelogGenerator\Tests;
6
7
use ChangelogGenerator\IssueClient;
8
use GuzzleHttp\Client;
9
use GuzzleHttp\Psr7\Response;
10
use PHPUnit\Framework\TestCase;
11
12
final class IssueClientTest extends TestCase
13
{
14
    /** @var \PHPUnit_Framework_MockObject_MockObject|Client */
15
    private $client;
16
17
    /** @var IssueClient */
18
    private $issueClient;
19
20
    public function testExecute() : void
21
    {
22
        $response = $this->createMock(Response::class);
23
24
        $this->client->expects($this->once())
25
            ->method('request')
26
            ->with('GET', 'https://www.google.com')
27
            ->willReturn($response);
28
29
        $response->expects($this->once())
30
            ->method('getBody')
31
            ->willReturn('{"test": true}');
32
33
        $response->expects($this->once())
34
            ->method('getHeader')
35
            ->with('Link')
36
            ->willReturn(['<https://www.google.com?next>; rel="next", <https://www.google.com?last>; rel="last"']);
37
38
        $response = $this->issueClient->execute('https://www.google.com');
39
40
        self::assertEquals(['test' => true], $response->getBody());
41
        self::assertEquals('https://www.google.com?next', $response->getNextUrl());
42
    }
43
44
    public function testExecuteNullNextUrl() : void
45
    {
46
        $response = $this->createMock(Response::class);
47
48
        $this->client->expects($this->once())
49
            ->method('request')
50
            ->with('GET', 'https://www.google.com')
51
            ->willReturn($response);
52
53
        $response->expects($this->once())
54
            ->method('getBody')
55
            ->willReturn('{"test": true}');
56
57
        $response->expects($this->once())
58
            ->method('getHeader')
59
            ->with('Link')
60
            ->willReturn([]);
61
62
        $response = $this->issueClient->execute('https://www.google.com');
63
64
        self::assertEquals(['test' => true], $response->getBody());
65
        self::assertNull($response->getNextUrl());
66
    }
67
68
    protected function setUp() : void
69
    {
70
        $this->client = $this->createMock(Client::class);
71
72
        $this->issueClient = new IssueClient($this->client);
73
    }
74
}
75