Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Api/SecurityIssues.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,19 @@ public function all(array $filters = [])
{
return $this->get('/security-issues/', $filters);
}

public function show(int $issueId): array
{
return $this->get('/security-issues/' . $issueId);
}

public function open(int $issueId): array
{
return $this->post('/security-issues/' . $issueId . '/open');
}

public function close(int $issueId, string $state): array
{
return $this->post('/security-issues/' . $issueId . '/close/' . $state);
}
}
84 changes: 81 additions & 3 deletions tests/Api/SecurityIssuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class SecurityIssuesTest extends ApiTestCase
{
public function testAll()
public function testAll(): void
{
$expected = [
[
Expand Down Expand Up @@ -41,7 +41,7 @@ public function testAll()
$this->assertSame($expected, $api->all());
}

public function testAllWithFilters()
public function testAllWithFilters(): void
{
$expected = [
[
Expand Down Expand Up @@ -73,7 +73,85 @@ public function testAllWithFilters()
$this->assertSame($expected, $api->all($filters));
}

protected function getApiClass()
public function testShow(): void
{
$expected = [
'packageName' => 'acme-website/package',
'state' => 'open',
'branch' => 'dev-master',
'installedPackage' => 'acme/library',
'installedVersion' => '1.0.0',
'advisory' => [
'title' => 'CVE-1999: Remote code execution',
'link' =>'https://acme.website/security-advisories',
'cve' => 'CVE-1999',
'affectedVersions' => '>=1.0',
],
];

/** @var SecurityIssues&MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->equalTo('/security-issues/12'))
->willReturn($expected);

$this->assertSame($expected, $api->show(12));
}

public function testOpen(): void
{
$expected = [
'packageName' => 'acme-website/package',
'state' => 'open',
'branch' => 'dev-master',
'installedPackage' => 'acme/library',
'installedVersion' => '1.0.0',
'advisory' => [
'title' => 'CVE-1999: Remote code execution',
'link' =>'https://acme.website/security-advisories',
'cve' => 'CVE-1999',
'affectedVersions' => '>=1.0',
],
];

/** @var SecurityIssues&MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with($this->equalTo('/security-issues/12/open'))
->willReturn($expected);

$this->assertSame($expected, $api->open(12));
}

public function testClose(): void
{
$expected = [
'packageName' => 'acme-website/package',
'state' => SecurityIssues::STATE_IN_PROGRESS,
'branch' => 'dev-master',
'installedPackage' => 'acme/library',
'installedVersion' => '1.0.0',
'advisory' => [
'title' => 'CVE-1999: Remote code execution',
'link' =>'https://acme.website/security-advisories',
'cve' => 'CVE-1999',
'affectedVersions' => '>=1.0',
],
];

/** @var SecurityIssues&MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with($this->equalTo('/security-issues/12/close/' . SecurityIssues::STATE_IN_PROGRESS))
->willReturn($expected);

$this->assertSame($expected, $api->close(12, SecurityIssues::STATE_IN_PROGRESS));
}

protected function getApiClass(): string
{
return SecurityIssues::class;
}
Expand Down