Completed
Push — master ( 861a0b...569933 )
by Philip
03:02
created

ClientTest::typeOfRequestWithArgumentProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Manavo\DoneDone\Test;
4
5
use Manavo\DoneDone\Client;
6
use Manavo\DoneDone\Company;
7
use PHPUnit_Framework_TestCase;
8
9
class ClientTest extends PHPUnit_Framework_TestCase
10
{
11
12
    /**
13
     * @var Client
14
     */
15
    private $client;
16
17
    public function setUp()
18
    {
19
        $this->client = new Client('team', 'username', 'password');
20
    }
21
22
    public function tearDown()
23
    {
24
        $this->client = null;
25
    }
26
27
    public function testProjectMethodReturnsIssueObject()
28
    {
29
        $this->assertInstanceOf(
30
            'Manavo\\DoneDone\\Project', $this->client->project(1)
31
        );
32
    }
33
34
    public function testCompanyMethodReturnsIssueObject()
35
    {
36
        $this->assertInstanceOf(
37
            'Manavo\\DoneDone\\Company', $this->client->company(1)
38
        );
39
    }
40
41
    public function typeOfRequestProvider()
42
    {
43
        return [
44
            ['priorityLevels', 'get'],
45
            ['projects', 'get'],
46
            ['companies', 'get'],
47
            ['issues', 'get'],
48
            ['activeIssues', 'get'],
49
            ['closedAndFixedIssues', 'get'],
50
            ['issuesWaitingOnYou', 'get'],
51
            ['issuesWaitingOnThem', 'get'],
52
            ['globalFilters', 'get'],
53
            ['issueCreationTypes', 'get'],
54
            ['issueSortTypes', 'get'],
55
        ];
56
    }
57
58
    /**
59
     * @dataProvider typeOfRequestProvider
60
     */
61
    public function testMethodsMakeCorrectTypeOfRequest($function, $requestType)
62
    {
63
        $responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response')
64
            ->disableOriginalConstructor()->getMock();
65
        $responseMock->expects($this->once())->method('json')
66
            ->willReturn($this->returnValue(true));
67
68
        $guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client')
69
            ->disableOriginalConstructor()->getMock();
70
        $guzzleClientMock->expects($this->once())->method($requestType)
71
            ->willReturn($responseMock);
72
73
        $this->client->setClient($guzzleClientMock);
74
75
        $this->client->$function();
76
    }
77
78
    public function typeOfRequestWithArgumentProvider()
79
    {
80
        return [
81
            ['issuesByFilter', 'get', 'argument'],
82
            ['createCompany', 'post', new Company()],
83
        ];
84
    }
85
86
    /**
87
     * @dataProvider typeOfRequestWithArgumentProvider
88
     */
89
    public function testMethodsWithArgumentMakeCorrectTypeOfRequest(
90
        $function,
91
        $requestType,
92
        $argument
93
    ) {
94
        $responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response')
95
            ->disableOriginalConstructor()->getMock();
96
        $responseMock->expects($this->once())->method('json')
97
            ->willReturn($this->returnValue(true));
98
99
        $guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client')
100
            ->disableOriginalConstructor()->getMock();
101
        $guzzleClientMock->expects($this->once())->method($requestType)
102
            ->willReturn($responseMock);
103
104
        $this->client->setClient($guzzleClientMock);
105
106
        $this->client->$function($argument);
107
    }
108
109
}
110