Skip to content

Commit b1e725a

Browse files
committed
Replace Tracker::getIdByName() with Tracker::listNames()
1 parent 70f385b commit b1e725a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/Redmine/Api/Issue.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,11 @@ private function cleanParams(array $params = [])
382382
if (isset($params['tracker'])) {
383383
$trackerApi = $this->getTrackerApi();
384384

385-
$params['tracker_id'] = $trackerApi->getIdByName($params['tracker']);
385+
$params['tracker_id'] = array_search(
386+
$params['tracker'],
387+
$trackerApi->listNames(),
388+
true,
389+
);
386390
unset($params['tracker']);
387391
}
388392

tests/Unit/Api/IssueTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Redmine\Api\IssueCategory;
1010
use Redmine\Api\IssueStatus;
1111
use Redmine\Api\Project;
12+
use Redmine\Api\Tracker;
1213
use Redmine\Client\Client;
1314
use Redmine\Http\HttpClient;
1415
use Redmine\Http\Response;
@@ -150,16 +151,12 @@ public function testCreateWithClientCleansParameters()
150151
'project' => 'Project 1 Name',
151152
'category' => 'Category 5 Name',
152153
'status' => 'Status 6 Name',
153-
'tracker' => 'Tracker Name',
154+
'tracker' => 'Tracker 2 Name',
154155
'assigned_to' => 'Assigned to User Name',
155156
'author' => 'Author Name',
156157
];
157158

158159
// Create the used mock objects
159-
$getIdByNameApi = $this->createMock('Redmine\Api\Tracker');
160-
$getIdByNameApi->expects($this->exactly(1))
161-
->method('getIdByName')
162-
->willReturn('cleanedValue');
163160
$getIdByUsernameApi = $this->createMock('Redmine\Api\User');
164161
$getIdByUsernameApi->expects($this->exactly(2))
165162
->method('getIdByUsername')
@@ -194,6 +191,15 @@ public function testCreateWithClientCleansParameters()
194191
'application/json',
195192
'{"issue_statuses":[{"id":6,"name":"Status 6 Name"}]}',
196193
],
194+
[
195+
'GET',
196+
'/trackers.json',
197+
'application/json',
198+
'',
199+
200,
200+
'application/json',
201+
'{"trackers":[{"id":2,"name":"Tracker 2 Name"}]}',
202+
],
197203
);
198204

199205
$client = $this->createMock(Client::class);
@@ -204,7 +210,7 @@ public function testCreateWithClientCleansParameters()
204210
['project', new Project($httpClient)],
205211
['issue_category', new IssueCategory($httpClient)],
206212
['issue_status', new IssueStatus($httpClient)],
207-
['tracker', $getIdByNameApi],
213+
['tracker', new Tracker($httpClient)],
208214
['user', $getIdByUsernameApi],
209215
],
210216
)
@@ -216,7 +222,7 @@ public function testCreateWithClientCleansParameters()
216222
'/issues.xml',
217223
<<< XML
218224
<?xml version="1.0"?>
219-
<issue><project_id>1</project_id><category_id>5</category_id><status_id>6</status_id><tracker_id>cleanedValue</tracker_id><assigned_to_id>cleanedValue</assigned_to_id><author_id>cleanedValue</author_id></issue>
225+
<issue><project_id>1</project_id><category_id>5</category_id><status_id>6</status_id><tracker_id>2</tracker_id><assigned_to_id>cleanedValue</assigned_to_id><author_id>cleanedValue</author_id></issue>
220226
221227
XML,
222228
)

0 commit comments

Comments
 (0)