1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TogglJiraTest\Jira; |
5
|
|
|
|
6
|
|
|
use chobie\Jira\Api\Authentication\AuthenticationInterface; |
7
|
|
|
use chobie\Jira\Api\Client\ClientInterface; |
8
|
|
|
use chobie\Jira\Api\Result; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use TogglJira\Jira\Api; |
11
|
|
|
|
12
|
|
|
class ApiTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @return void |
16
|
|
|
*/ |
17
|
|
|
public function testAddWorkLogEntry(): void |
18
|
|
|
{ |
19
|
|
|
$endPoint = 'http://www.example.com'; |
20
|
|
|
|
21
|
|
|
$authenticationMock = \Mockery::mock(AuthenticationInterface::class); |
22
|
|
|
$clientMock = \Mockery::mock(ClientInterface::class); |
23
|
|
|
$clientMock->shouldReceive('sendRequest') |
24
|
|
|
->with( |
25
|
|
|
Api::REQUEST_POST, |
26
|
|
|
"/rest/api/2/issue/DVA-42/worklog?adjustEstimate=auto", |
27
|
|
|
[ |
28
|
|
|
'timeSpentSeconds' => 9001, |
29
|
|
|
'author' => [ |
30
|
|
|
'accountId' => 'D-Va', |
31
|
|
|
], |
32
|
|
|
'comment' => 'Nerf this!', |
33
|
|
|
'started' => '2017-04-15T23:35:00+02:00', |
34
|
|
|
], |
35
|
|
|
'http://www.example.com', |
36
|
|
|
$authenticationMock, |
37
|
|
|
false, |
38
|
|
|
false |
39
|
|
|
) |
40
|
|
|
->andReturn('{}'); |
41
|
|
|
|
42
|
|
|
$clientMock->shouldReceive('sendRequest') |
43
|
|
|
->with( |
44
|
|
|
Api::REQUEST_GET, |
45
|
|
|
"/rest/api/2/issue/DVA-42/worklog", |
46
|
|
|
[], |
47
|
|
|
'http://www.example.com', |
48
|
|
|
$authenticationMock, |
49
|
|
|
false, |
50
|
|
|
false |
51
|
|
|
) |
52
|
|
|
->andReturn('{}'); |
53
|
|
|
|
54
|
|
|
$api = new Api($endPoint, $authenticationMock, $clientMock); |
55
|
|
|
|
56
|
|
|
$result = $api->addWorkLogEntry( |
57
|
|
|
'DVA-42', |
58
|
|
|
9001, |
59
|
|
|
'D-Va', |
60
|
|
|
'Nerf this!', |
61
|
|
|
'2017-04-15T23:35:00+02:00' |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$this->assertInstanceOf(Result::class, $result); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function testUpdateWorkLogEntry(): void |
71
|
|
|
{ |
72
|
|
|
$endPoint = 'http://www.example.com'; |
73
|
|
|
|
74
|
|
|
$authenticationMock = \Mockery::mock(AuthenticationInterface::class); |
75
|
|
|
$clientMock = \Mockery::mock(ClientInterface::class); |
76
|
|
|
$clientMock->shouldReceive('sendRequest') |
77
|
|
|
->with( |
78
|
|
|
Api::REQUEST_PUT, |
79
|
|
|
"/rest/api/2/issue/DVA-42/worklog/42?adjustEstimate=auto", |
80
|
|
|
[ |
81
|
|
|
'timeSpentSeconds' => 9001, |
82
|
|
|
], |
83
|
|
|
'http://www.example.com', |
84
|
|
|
$authenticationMock, |
85
|
|
|
false, |
86
|
|
|
false |
87
|
|
|
) |
88
|
|
|
->andReturn('{}'); |
89
|
|
|
|
90
|
|
|
$clientMock->shouldReceive('sendRequest') |
91
|
|
|
->with( |
92
|
|
|
Api::REQUEST_GET, |
93
|
|
|
"/rest/api/2/issue/DVA-42/worklog", |
94
|
|
|
[], |
95
|
|
|
'http://www.example.com', |
96
|
|
|
$authenticationMock, |
97
|
|
|
false, |
98
|
|
|
false |
99
|
|
|
) |
100
|
|
|
->andReturn('{"worklogs": [{"id": 42, "started": "2017-04-15", "author":{"accountId":"D-Va"}}]}'); |
101
|
|
|
|
102
|
|
|
$api = new Api($endPoint, $authenticationMock, $clientMock); |
103
|
|
|
|
104
|
|
|
$result = $api->addWorkLogEntry( |
105
|
|
|
'DVA-42', |
106
|
|
|
9001, |
107
|
|
|
'D-Va', |
108
|
|
|
'Nerf this!', |
109
|
|
|
'2017-04-15T23:35:00+02:00' |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
$this->assertInstanceOf(Result::class, $result); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
|
|
public function testGetUser(): void |
119
|
|
|
{ |
120
|
|
|
$endPoint = 'http://www.example.com'; |
121
|
|
|
|
122
|
|
|
$authenticationMock = \Mockery::mock(AuthenticationInterface::class); |
123
|
|
|
$clientMock = \Mockery::mock(ClientInterface::class); |
124
|
|
|
$clientMock->shouldReceive('sendRequest') |
125
|
|
|
->with( |
126
|
|
|
Api::REQUEST_GET, |
127
|
|
|
"/rest/api/2/user", |
128
|
|
|
[ |
129
|
|
|
'username' => 'D-Va', |
130
|
|
|
], |
131
|
|
|
'http://www.example.com', |
132
|
|
|
$authenticationMock, |
133
|
|
|
false, |
134
|
|
|
false |
135
|
|
|
) |
136
|
|
|
->andReturn('{"accountId":"42"}'); |
137
|
|
|
|
138
|
|
|
$api = new Api($endPoint, $authenticationMock, $clientMock); |
139
|
|
|
|
140
|
|
|
$user = $api->getUser('D-Va'); |
141
|
|
|
|
142
|
|
|
$this->assertEquals('42', $user['accountId']); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|