Skip to content

Commit

Permalink
Add tests for exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Oct 9, 2023
1 parent 3155355 commit 0ef7eb5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Unit/Api/News/ListByProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use PHPUnit\Framework\TestCase;
use Redmine\Api\News;
use Redmine\Client\Client;
use Redmine\Tests\Fixtures\MockClient;
use stdClass;

/**
* Tests for News::listByProject()
Expand Down Expand Up @@ -75,4 +77,31 @@ public function testListByProjectWithParametersReturnsResponse()
// Perform the tests
$this->assertSame($expectedReturn, $api->listByProject($projectId, $parameters));
}

/**
* @covers \Redmine\Api\News::listByProject
*
* @dataProvider getInvalidProjectIdentifiers
*/
public function testListByProjectWithWrongProjectIdentifierThrowsException($projectIdentifier)
{
$api = new News(MockClient::create());

$this->expectException(InvalidParameterException::class);
$this->expectExceptionMessage('Redmine\Api\News::listByProject(): Argument #1 ($projectIdentifier) must be of type int or string');

$api->listByProject($projectIdentifier);
}

public static function getInvalidProjectIdentifiers(): array
{
return [
'null' => [null],
'true' => [true],
'false' => [false],
'float' => [0.0],
'array' => [[]],
'object' => [new stdClass()],
];
}
}

0 comments on commit 0ef7eb5

Please sign in to comment.