|
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¬ifyUsers=true", |
|
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
|
|
|
false |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertInstanceOf(Result::class, $result); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testUpdateWorkLogEntry(): void |
|
72
|
|
|
{ |
|
73
|
|
|
$endPoint = 'http://www.example.com'; |
|
74
|
|
|
|
|
75
|
|
|
$authenticationMock = \Mockery::mock(AuthenticationInterface::class); |
|
76
|
|
|
$clientMock = \Mockery::mock(ClientInterface::class); |
|
77
|
|
|
$clientMock->shouldReceive('sendRequest') |
|
78
|
|
|
->with( |
|
79
|
|
|
Api::REQUEST_PUT, |
|
80
|
|
|
"/rest/api/2/issue/DVA-42/worklog/42?adjustEstimate=auto¬ifyUsers=true", |
|
81
|
|
|
[ |
|
82
|
|
|
'timeSpentSeconds' => 9001, |
|
83
|
|
|
'author' => ['accountId' => 'D-Va'], |
|
84
|
|
|
'comment' => 'Nerf this!', |
|
85
|
|
|
'started' => '2017-04-15T23:35:00+02:00' |
|
86
|
|
|
], |
|
87
|
|
|
'http://www.example.com', |
|
88
|
|
|
$authenticationMock, |
|
89
|
|
|
false, |
|
90
|
|
|
false |
|
91
|
|
|
) |
|
92
|
|
|
->andReturn('{}'); |
|
93
|
|
|
|
|
94
|
|
|
$clientMock->shouldReceive('sendRequest') |
|
95
|
|
|
->with( |
|
96
|
|
|
Api::REQUEST_GET, |
|
97
|
|
|
"/rest/api/2/issue/DVA-42/worklog", |
|
98
|
|
|
[], |
|
99
|
|
|
'http://www.example.com', |
|
100
|
|
|
$authenticationMock, |
|
101
|
|
|
false, |
|
102
|
|
|
false |
|
103
|
|
|
) |
|
104
|
|
|
->andReturn('{"worklogs": [{"id": 42, "started": "2017-04-15", "author":{"accountId":"D-Va"}}]}'); |
|
105
|
|
|
|
|
106
|
|
|
$api = new Api($endPoint, $authenticationMock, $clientMock); |
|
107
|
|
|
|
|
108
|
|
|
$result = $api->addWorkLogEntry( |
|
109
|
|
|
'DVA-42', |
|
110
|
|
|
9001, |
|
111
|
|
|
'D-Va', |
|
112
|
|
|
'Nerf this!', |
|
113
|
|
|
'2017-04-15T23:35:00+02:00', |
|
114
|
|
|
false |
|
115
|
|
|
); |
|
116
|
|
|
|
|
117
|
|
|
$this->assertInstanceOf(Result::class, $result); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return void |
|
122
|
|
|
*/ |
|
123
|
|
|
public function testGetUser(): void |
|
124
|
|
|
{ |
|
125
|
|
|
$endPoint = 'http://www.example.com'; |
|
126
|
|
|
|
|
127
|
|
|
$authenticationMock = \Mockery::mock(AuthenticationInterface::class); |
|
128
|
|
|
$clientMock = \Mockery::mock(ClientInterface::class); |
|
129
|
|
|
$clientMock->shouldReceive('sendRequest') |
|
130
|
|
|
->with( |
|
131
|
|
|
Api::REQUEST_GET, |
|
132
|
|
|
"/rest/api/2/user", |
|
133
|
|
|
[ |
|
134
|
|
|
'username' => 'D-Va', |
|
135
|
|
|
], |
|
136
|
|
|
'http://www.example.com', |
|
137
|
|
|
$authenticationMock, |
|
138
|
|
|
false, |
|
139
|
|
|
false |
|
140
|
|
|
) |
|
141
|
|
|
->andReturn('{"accountId":"42"}'); |
|
142
|
|
|
|
|
143
|
|
|
$api = new Api($endPoint, $authenticationMock, $clientMock); |
|
144
|
|
|
|
|
145
|
|
|
$user = $api->getUser('D-Va'); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertEquals('42', $user['accountId']); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|