Skip to content

Commit

Permalink
Project::close() returns bool instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Jan 18, 2024
1 parent 54edbf0 commit 64c98a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
12 changes: 9 additions & 3 deletions src/Redmine/Api/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ public function update($id, array $params)
*
* @param string|int $projectIdentifier project id or identifier
*
* @return string empty string
* @throws InvalidArgumentException if $projectIdentifier is not provided as int or string
*
* @return bool true if the request was successful
*/
public function close($projectIdentifier): string
public function close($projectIdentifier): bool
{
if (! is_int($projectIdentifier) && ! is_string($projectIdentifier)) {
throw new InvalidArgumentException(sprintf(
Expand All @@ -213,10 +215,14 @@ public function close($projectIdentifier): string
));
}

return $this->put(
$this->put(
'/projects/' . strval($projectIdentifier) . '/close.xml',
''
);

$lastResponse = $this->getLastResponse();

return ($lastResponse->getStatusCode() === 204);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions tests/End2End/Project/ClosingProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function testInteractionWithProject(RedmineVersion $redmineVersion): void

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

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

// Close project
$result = $api->close($projectIdentifier);
$this->assertSame('', $result);
$this->assertTrue($api->close($projectIdentifier));

// Read single project
$projectDetails = $api->show($projectIdentifier);
Expand Down
16 changes: 7 additions & 9 deletions tests/Unit/Api/Project/CloseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ public function testCloseReturnsResponse()
$this->assertSame('/projects/5/close.xml', $path);
$this->assertSame('', $body);

return $this->createConfiguredMock(
Response::class,
[
'getContentType' => 'application/xml',
'getBody' => '',
]
);
return $this->createConfiguredMock(Response::class, [
'getStatusCode' => 204,
'getContentType' => 'application/xml',
'getBody' => '',
]);
})
;

$api = new Project($client);

$this->assertSame('', $api->close(5));
$this->assertTrue($api->close(5));
}

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

// Perform the tests
// provide a wrong project identifier
$api->close(true);
}
}

0 comments on commit 64c98a1

Please sign in to comment.