From 1706d8d928b9db3acd102a7d0c45ba59e2355022 Mon Sep 17 00:00:00 2001 From: Eduardo Pittol Date: Tue, 2 Jan 2024 19:08:42 -0300 Subject: [PATCH] Add tests to distribution without reference --- .../Controller/RepoControllerTest.php | 31 ++++++++++++++ .../dist/buddy-works/artifact/1.0.0.0.zip | Bin 0 -> 307 bytes tests/Unit/Service/Dist/StorageTest.php | 38 ++++++++++++++++++ .../ComposerPackageSynchronizerTest.php | 5 +++ 4 files changed, 74 insertions(+) create mode 100644 tests/Resources/buddy/dist/buddy-works/artifact/1.0.0.0.zip create mode 100644 tests/Unit/Service/Dist/StorageTest.php diff --git a/tests/Functional/Controller/RepoControllerTest.php b/tests/Functional/Controller/RepoControllerTest.php index fc803fb6..5989a57e 100644 --- a/tests/Functional/Controller/RepoControllerTest.php +++ b/tests/Functional/Controller/RepoControllerTest.php @@ -150,6 +150,37 @@ public function testOrganizationPackageDistDownload(): void self::assertTrue($this->client->getResponse()->isNotFound()); } + public function testOrganizationArtifactPackageDistDownload(): void + { + $this->fixtures->prepareRepoFiles(); + $this->fixtures->createToken( + $this->fixtures->createOrganization('buddy', $this->fixtures->createUser()), + 'secret-org-token' + ); + + $this->contentFromStream(function (): void { + $this->client->request('GET', '/dists/buddy-works/artifact/1.0.0.0/zip', [], [], [ + 'HTTP_HOST' => 'buddy.repo.repman.wip', + 'PHP_AUTH_USER' => 'token', + 'PHP_AUTH_PW' => 'secret-org-token', + ]); + }); + + $response = $this->client->getResponse(); + self::assertTrue($response->isOk(), 'Response code was not 200, it was instead '.$response->getStatusCode()); + self::assertInstanceOf(StreamedResponse::class, $response); + + $this->contentFromStream(function (): void { + $this->client->request('GET', '/dists/vendor/artifact/1.0.0.0/zip', [], [], [ + 'HTTP_HOST' => 'buddy.repo.repman.wip', + 'PHP_AUTH_USER' => 'token', + 'PHP_AUTH_PW' => 'secret-org-token', + ]); + }); + + self::assertTrue($this->client->getResponse()->isNotFound()); + } + public function testOrganizationTrackDownloads(): void { $this->fixtures->createPackage('c75b535f-5817-41a2-9424-e05476e7958f', 'buddy'); diff --git a/tests/Resources/buddy/dist/buddy-works/artifact/1.0.0.0.zip b/tests/Resources/buddy/dist/buddy-works/artifact/1.0.0.0.zip new file mode 100644 index 0000000000000000000000000000000000000000..1e86802107fe4533c4c1ef08984e0a831ea42bc2 GIT binary patch literal 307 zcmWIWW@Zs#-~hr?Io<&bP|yUVc^MQKlJj#5@{3c8^slFA-B0PZgVz z^6YtI2}`jUX0DJ__(=Wdmtq N1j1+_eF(&1000BCRyqIx literal 0 HcmV?d00001 diff --git a/tests/Unit/Service/Dist/StorageTest.php b/tests/Unit/Service/Dist/StorageTest.php new file mode 100644 index 00000000..a8e289ed --- /dev/null +++ b/tests/Unit/Service/Dist/StorageTest.php @@ -0,0 +1,38 @@ +storage = new Storage( + new FakeDownloader(), + new Filesystem(new MemoryAdapter()) + ); + } + + public function testFilename(): void + { + $dist = new Dist('repo', 'package', '1.1.0', '123456', 'zip'); + + self::assertEquals('repo/dist/package/1.1.0_123456.zip', $this->storage->filename($dist)); + } + + public function testArtifactFilename(): void + { + $dist = new Dist('repo', 'package', '1.1.0', '', 'zip'); + self::assertEquals('repo/dist/package/1.1.0.zip', $this->storage->filename($dist)); + } +} diff --git a/tests/Unit/Service/PackageSynchronizer/ComposerPackageSynchronizerTest.php b/tests/Unit/Service/PackageSynchronizer/ComposerPackageSynchronizerTest.php index b3b854d7..aad6fdfd 100644 --- a/tests/Unit/Service/PackageSynchronizer/ComposerPackageSynchronizerTest.php +++ b/tests/Unit/Service/PackageSynchronizer/ComposerPackageSynchronizerTest.php @@ -109,6 +109,11 @@ public function testSynchronizePackageFromArtifacts(): void self::assertContains('replaces-buddy-works/replace-^1.0', $linkStrings); self::assertContains('conflicts-buddy-works/conflict-^1.0', $linkStrings); self::assertContains('suggests-buddy-works/suggests-You really should', $linkStrings); + + $referencestrings = array_map(function (Version $version): string { + return $version->reference(); + }, $package->versions()->toArray()); + self::assertEquals(['', '', '', ''], $referencestrings); } public function testWithMostRecentUnstable(): void