Skip to content

Commit 64c98a1

Browse files
committed
Project::close() returns bool instead of string
1 parent 54edbf0 commit 64c98a1

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/Redmine/Api/Project.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,11 @@ public function update($id, array $params)
202202
*
203203
* @param string|int $projectIdentifier project id or identifier
204204
*
205-
* @return string empty string
205+
* @throws InvalidArgumentException if $projectIdentifier is not provided as int or string
206+
*
207+
* @return bool true if the request was successful
206208
*/
207-
public function close($projectIdentifier): string
209+
public function close($projectIdentifier): bool
208210
{
209211
if (! is_int($projectIdentifier) && ! is_string($projectIdentifier)) {
210212
throw new InvalidArgumentException(sprintf(
@@ -213,10 +215,14 @@ public function close($projectIdentifier): string
213215
));
214216
}
215217

216-
return $this->put(
218+
$this->put(
217219
'/projects/' . strval($projectIdentifier) . '/close.xml',
218220
''
219221
);
222+
223+
$lastResponse = $this->getLastResponse();
224+
225+
return ($lastResponse->getStatusCode() === 204);
220226
}
221227

222228
/**

tests/End2End/Project/ClosingProjectTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public function testInteractionWithProject(RedmineVersion $redmineVersion): void
2020

2121
/** @var Project */
2222
$api = $client->getApi('project');
23-
$now = new DateTimeImmutable();
2423

2524
// Create project
2625
$projectName = 'test project';
@@ -41,8 +40,7 @@ public function testInteractionWithProject(RedmineVersion $redmineVersion): void
4140
$this->assertSame('1', $projectData['status'], $projectDataJson);
4241

4342
// Close project
44-
$result = $api->close($projectIdentifier);
45-
$this->assertSame('', $result);
43+
$this->assertTrue($api->close($projectIdentifier));
4644

4745
// Read single project
4846
$projectDetails = $api->show($projectIdentifier);

tests/Unit/Api/Project/CloseTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@ public function testCloseReturnsResponse()
2424
$this->assertSame('/projects/5/close.xml', $path);
2525
$this->assertSame('', $body);
2626

27-
return $this->createConfiguredMock(
28-
Response::class,
29-
[
30-
'getContentType' => 'application/xml',
31-
'getBody' => '',
32-
]
33-
);
27+
return $this->createConfiguredMock(Response::class, [
28+
'getStatusCode' => 204,
29+
'getContentType' => 'application/xml',
30+
'getBody' => '',
31+
]);
3432
})
3533
;
3634

3735
$api = new Project($client);
3836

39-
$this->assertSame('', $api->close(5));
37+
$this->assertTrue($api->close(5));
4038
}
4139

4240
public function testCloseWithoutIntOrStringThrowsInvalidArgumentException()
@@ -48,7 +46,7 @@ public function testCloseWithoutIntOrStringThrowsInvalidArgumentException()
4846
$this->expectException(InvalidArgumentException::class);
4947
$this->expectExceptionMessage('Redmine\Api\Project::close(): Argument #1 ($projectIdentifier) must be of type int or string');
5048

51-
// Perform the tests
49+
// provide a wrong project identifier
5250
$api->close(true);
5351
}
5452
}

0 commit comments

Comments
 (0)