1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Manavo\DoneDone\Test; |
4
|
|
|
|
5
|
|
|
use Manavo\DoneDone\Client; |
6
|
|
|
use Manavo\DoneDone\Issue; |
7
|
|
|
use Manavo\DoneDone\Project; |
8
|
|
|
use Manavo\DoneDone\ReleaseBuild; |
9
|
|
|
use PHPUnit_Framework_TestCase; |
10
|
|
|
|
11
|
|
|
class ProjectTest extends PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
public function testIssueMethodReturnsIssueObject() |
15
|
|
|
{ |
16
|
|
|
$project = new Project(new Client('team', 'username', 'password'), 0); |
17
|
|
|
$this->assertInstanceOf('Manavo\\DoneDone\\Issue', $project->issue(1)); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function typeOfRequestProvider() |
21
|
|
|
{ |
22
|
|
|
return [ |
23
|
|
|
['people', 'get'], |
24
|
|
|
['issues', 'get'], |
25
|
|
|
['activeIssues', 'get'], |
26
|
|
|
['closedAndFixedIssues', 'get'], |
27
|
|
|
['issuesWaitingOnYou', 'get'], |
28
|
|
|
['issuesWaitingOnThem', 'get'], |
29
|
|
|
['releaseBuilds', 'get'], |
30
|
|
|
//['releaseBuildInfo', 'get'], // TODO response is object of class ReleaseBuildInfo |
31
|
|
|
['filters', 'get'], |
32
|
|
|
]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @dataProvider typeOfRequestProvider |
37
|
|
|
*/ |
38
|
|
|
public function testMethodsMakeCorrectTypeOfRequest($function, $requestType) |
39
|
|
|
{ |
40
|
|
|
$responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response') |
41
|
|
|
->disableOriginalConstructor()->getMock(); |
42
|
|
|
$responseMock->expects($this->once())->method('json') |
43
|
|
|
->willReturn($this->returnValue(true)); |
44
|
|
|
|
45
|
|
|
$guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client') |
46
|
|
|
->disableOriginalConstructor()->getMock(); |
47
|
|
|
$guzzleClientMock->expects($this->once())->method($requestType) |
48
|
|
|
->willReturn($responseMock); |
49
|
|
|
|
50
|
|
|
$client = new Client('team', 'username', 'password'); |
51
|
|
|
$client->setClient($guzzleClientMock); |
52
|
|
|
|
53
|
|
|
$client->project(123)->$function(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function typeOfRequestWithArgumentProvider() |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
['issuesByFilter', 'get', 'argument'], |
60
|
|
|
['addIssue', 'post', new Issue()], |
61
|
|
|
['createReleaseBuild', 'post', new ReleaseBuild()], |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider typeOfRequestWithArgumentProvider |
67
|
|
|
*/ |
68
|
|
|
public function testMethodsWithArgumentMakeCorrectTypeOfRequest( |
69
|
|
|
$function, |
70
|
|
|
$requestType, |
71
|
|
|
$argument |
72
|
|
|
) { |
73
|
|
|
$responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response') |
74
|
|
|
->disableOriginalConstructor()->getMock(); |
75
|
|
|
$responseMock->expects($this->once())->method('json') |
76
|
|
|
->willReturn($this->returnValue(true)); |
77
|
|
|
|
78
|
|
|
$guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client') |
79
|
|
|
->disableOriginalConstructor()->getMock(); |
80
|
|
|
$guzzleClientMock->expects($this->once())->method($requestType) |
81
|
|
|
->willReturn($responseMock); |
82
|
|
|
|
83
|
|
|
$client = new Client('team', 'username', 'password'); |
84
|
|
|
$client->setClient($guzzleClientMock); |
85
|
|
|
|
86
|
|
|
$client->project(123)->$function($argument); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|