diff --git a/src/Api/SecurityIssues.php b/src/Api/SecurityIssues.php index a891483..0c2f05a 100644 --- a/src/Api/SecurityIssues.php +++ b/src/Api/SecurityIssues.php @@ -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); + } } diff --git a/tests/Api/SecurityIssuesTest.php b/tests/Api/SecurityIssuesTest.php index 7b3979e..cdb6f02 100644 --- a/tests/Api/SecurityIssuesTest.php +++ b/tests/Api/SecurityIssuesTest.php @@ -13,7 +13,7 @@ class SecurityIssuesTest extends ApiTestCase { - public function testAll() + public function testAll(): void { $expected = [ [ @@ -41,7 +41,7 @@ public function testAll() $this->assertSame($expected, $api->all()); } - public function testAllWithFilters() + public function testAllWithFilters(): void { $expected = [ [ @@ -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; }