Skip to content

Commit

Permalink
use snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Aug 1, 2022
1 parent a532ef2 commit 4d125fe
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 70 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"composer/semver": "^1.0|^2.0|^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.4"
"phpunit/phpunit": "^9.4",
"spatie/phpunit-snapshot-assertions": "^4.2"
},
"autoload": {
"psr-4": {
Expand Down
75 changes: 6 additions & 69 deletions tests/Integration/PackagistClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
use PHPUnit\Framework\TestCase;
use Spatie\Packagist\PackagistClient;
use Spatie\Packagist\PackagistUrlGenerator;
use Spatie\Snapshots\MatchesSnapshots;

class PackagistClientTest extends TestCase
{
use MatchesSnapshots;

/** @test */
public function it_can_list_package_names()
{
Expand Down Expand Up @@ -150,51 +153,8 @@ public function it_can_get_advisories_by_package_name()
$result = $client->getAdvisories(['silverstripe/admin']);

$this->assertArrayHasKey('silverstripe/admin', $result);
$advisories = [
[
'advisoryId' => 'PKSA-zmvy-dmwz-zrvp',
'packageName' => 'silverstripe/admin',
'remoteId' => 'silverstripe/admin/CVE-2021-36150.yaml',
'title' => 'CVE-2021-36150 - Insert from files link text - Reflective (self) Cross Site Scripting',
'link' => 'https://www.silverstripe.org/download/security-releases/CVE-2021-36150',
'cve' => 'CVE-2021-36150',
'affectedVersions' => '>=1.0.0,<1.8.1',
'source' => 'FriendsOfPHP/security-advisories',
'reportedAt' => '2021-10-05 05:18:20',
'composerRepository' => 'https://packagist.org',
'sources' => [
[
'name' => 'GitHub',
'remoteId' => 'GHSA-j66h-cc96-c32q',
],
[
'name' => 'FriendsOfPHP/security-advisories',
'remoteId' => 'silverstripe/admin/CVE-2021-36150.yaml',
],
],
],
[
'advisoryId' => 'PKSA-wvzh-yq7r-9q1d',
'packageName' => 'silverstripe/admin',
'remoteId' => 'silverstripe/admin/SS-2018-004-1.yaml',
'title' => 'SS-2018-004: XSS Vulnerability via WYSIWYG editor',
'link' => 'https://www.silverstripe.org/download/security-releases/ss-2018-004/',
'cve' => null,
'affectedVersions' => '>=1.0.3,<1.0.4|>=1.1.0,<1.1.1',
'source' => 'FriendsOfPHP/security-advisories',
'reportedAt' => '2018-02-01 17:33:07',
'composerRepository' => 'https://packagist.org',
'sources' => [
[
'name' => 'FriendsOfPHP/security-advisories',
'remoteId' => 'silverstripe/admin/SS-2018-004-1.yaml',
],
],
],
];
foreach ($advisories as $advisory) {
$this->assertContains($advisory, $result['silverstripe/admin']);
}

$this->assertMatchesJsonSnapshot($result);
}

/** @test */
Expand All @@ -204,30 +164,7 @@ public function it_can_get_filtered_advisories_by_package_name()

$result = $client->getAdvisoriesAffectingVersions(['silverstripe/admin' => '1.5.0']);

$this->assertArrayHasKey('silverstripe/admin', $result);
$advisory = [
'advisoryId' => 'PKSA-zmvy-dmwz-zrvp',
'packageName' => 'silverstripe/admin',
'remoteId' => 'silverstripe/admin/CVE-2021-36150.yaml',
'title' => 'CVE-2021-36150 - Insert from files link text - Reflective (self) Cross Site Scripting',
'link' => 'https://www.silverstripe.org/download/security-releases/CVE-2021-36150',
'cve' => 'CVE-2021-36150',
'affectedVersions' => '>=1.0.0,<1.8.1',
'source' => 'FriendsOfPHP/security-advisories',
'reportedAt' => '2021-10-05 05:18:20',
'composerRepository' => 'https://packagist.org',
'sources' => [
[
'name' => 'GitHub',
'remoteId' => 'GHSA-j66h-cc96-c32q',
],
[
'name' => 'FriendsOfPHP/security-advisories',
'remoteId' => 'silverstripe/admin/CVE-2021-36150.yaml',
],
],
];
$this->assertContains($advisory, $result['silverstripe/admin']);
$this->assertMatchesJsonSnapshot($result);
}

/** @test */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"silverstripe\/admin": [
{
"advisoryId": "PKSA-zmvy-dmwz-zrvp",
"packageName": "silverstripe\/admin",
"remoteId": "silverstripe\/admin\/CVE-2021-36150.yaml",
"title": "CVE-2021-36150 - Insert from files link text - Reflective (self) Cross Site Scripting",
"link": "https:\/\/www.silverstripe.org\/download\/security-releases\/CVE-2021-36150",
"cve": "CVE-2021-36150",
"affectedVersions": ">=1.0.0,<1.8.1",
"source": "FriendsOfPHP\/security-advisories",
"reportedAt": "2021-10-05 05:18:20",
"composerRepository": "https:\/\/packagist.org",
"sources": [
{
"name": "GitHub",
"remoteId": "GHSA-j66h-cc96-c32q"
},
{
"name": "FriendsOfPHP\/security-advisories",
"remoteId": "silverstripe\/admin\/CVE-2021-36150.yaml"
}
]
},
{
"advisoryId": "PKSA-wvzh-yq7r-9q1d",
"packageName": "silverstripe\/admin",
"remoteId": "silverstripe\/admin\/SS-2018-004-1.yaml",
"title": "SS-2018-004: XSS Vulnerability via WYSIWYG editor",
"link": "https:\/\/www.silverstripe.org\/download\/security-releases\/ss-2018-004\/",
"cve": null,
"affectedVersions": ">=1.0.3,<1.0.4|>=1.1.0,<1.1.1",
"source": "FriendsOfPHP\/security-advisories",
"reportedAt": "2018-02-01 17:33:07",
"composerRepository": "https:\/\/packagist.org",
"sources": [
{
"name": "FriendsOfPHP\/security-advisories",
"remoteId": "silverstripe\/admin\/SS-2018-004-1.yaml"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"silverstripe\/admin": [
{
"advisoryId": "PKSA-zmvy-dmwz-zrvp",
"packageName": "silverstripe\/admin",
"remoteId": "silverstripe\/admin\/CVE-2021-36150.yaml",
"title": "CVE-2021-36150 - Insert from files link text - Reflective (self) Cross Site Scripting",
"link": "https:\/\/www.silverstripe.org\/download\/security-releases\/CVE-2021-36150",
"cve": "CVE-2021-36150",
"affectedVersions": ">=1.0.0,<1.8.1",
"source": "FriendsOfPHP\/security-advisories",
"reportedAt": "2021-10-05 05:18:20",
"composerRepository": "https:\/\/packagist.org",
"sources": [
{
"name": "GitHub",
"remoteId": "GHSA-j66h-cc96-c32q"
},
{
"name": "FriendsOfPHP\/security-advisories",
"remoteId": "silverstripe\/admin\/CVE-2021-36150.yaml"
}
]
}
]
}

0 comments on commit 4d125fe

Please sign in to comment.