Skip to content

Commit 4dddac4

Browse files
committed
Replace Project::getIdByName() with listNames()
1 parent 516115e commit 4dddac4

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

src/Redmine/Api/Issue.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,12 @@ private function cleanParams(array $params = [])
348348
if (isset($params['project'])) {
349349
$projectApi = $this->getProjectApi();
350350

351-
$params['project_id'] = $projectApi->getIdByName($params['project']);
351+
// TODO: project names are not unique; there could be collisions
352+
$params['project_id'] = array_search(
353+
$params['project'],
354+
$projectApi->listNames(),
355+
true,
356+
);
352357
unset($params['project']);
353358
}
354359

tests/Unit/Api/Issue/CreateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public function testCreateWithHttpClientRetrievesProjectId()
299299
$this,
300300
[
301301
'GET',
302-
'/projects.json',
302+
'/projects.json?limit=100&offset=0',
303303
'application/json',
304304
'',
305305
200,
@@ -450,7 +450,7 @@ public function testCreateWithClientCleansParameters()
450450
$this,
451451
[
452452
'GET',
453-
'/projects.json',
453+
'/projects.json?limit=100&offset=0',
454454
'application/json',
455455
'',
456456
200,

tests/Unit/Api/Issue/UpdateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function testUpdateCleansParameters()
119119
$this,
120120
[
121121
'GET',
122-
'/projects.json',
122+
'/projects.json?limit=100&offset=0',
123123
'application/json',
124124
'',
125125
200,

tests/Unit/Api/IssueTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Redmine\Api\Issue;
99
use Redmine\Api\IssueCategory;
1010
use Redmine\Api\IssueStatus;
11+
use Redmine\Api\Project;
1112
use Redmine\Client\Client;
1213
use Redmine\Http\HttpClient;
1314
use Redmine\Http\Response;
@@ -146,7 +147,7 @@ public function testCreateWithClientCleansParameters()
146147
// Test values
147148
$response = '<?xml version="1.0"?><issue></issue>';
148149
$parameters = [
149-
'project' => 'Project Name',
150+
'project' => 'Project 1 Name',
150151
'category' => 'Category 5 Name',
151152
'status' => 'Status 6 Name',
152153
'tracker' => 'Tracker Name',
@@ -155,10 +156,6 @@ public function testCreateWithClientCleansParameters()
155156
];
156157

157158
// Create the used mock objects
158-
$projectApi = $this->createMock('Redmine\Api\Project');
159-
$projectApi->expects($this->exactly(1))
160-
->method('getIdByName')
161-
->willReturn(1);
162159
$getIdByNameApi = $this->createMock('Redmine\Api\Tracker');
163160
$getIdByNameApi->expects($this->exactly(1))
164161
->method('getIdByName')
@@ -170,6 +167,15 @@ public function testCreateWithClientCleansParameters()
170167

171168
$httpClient = AssertingHttpClient::create(
172169
$this,
170+
[
171+
'GET',
172+
'/projects.json?limit=100&offset=0',
173+
'application/json',
174+
'',
175+
200,
176+
'application/json',
177+
'{"projects":[{"id":1,"name":"Project 1 Name"},{"id":2,"name":"Project 1 Name"}]}',
178+
],
173179
[
174180
'GET',
175181
'/projects/1/issue_categories.json',
@@ -195,7 +201,7 @@ public function testCreateWithClientCleansParameters()
195201
->method('getApi')
196202
->willReturnMap(
197203
[
198-
['project', $projectApi],
204+
['project', new Project($httpClient)],
199205
['issue_category', new IssueCategory($httpClient)],
200206
['issue_status', new IssueStatus($httpClient)],
201207
['tracker', $getIdByNameApi],

0 commit comments

Comments
 (0)