Skip to content

Commit

Permalink
Add tests to distribution without reference
Browse files Browse the repository at this point in the history
  • Loading branch information
edpittol committed Jan 2, 2024
1 parent 019780d commit 1706d8d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/Functional/Controller/RepoControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Binary file not shown.
38 changes: 38 additions & 0 deletions tests/Unit/Service/Dist/StorageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Buddy\Repman\Tests\Unit\Service\Dist;

use Buddy\Repman\Service\Dist;
use Buddy\Repman\Service\Dist\Storage;
use Buddy\Repman\Tests\Doubles\FakeDownloader;
use League\Flysystem\Filesystem;
use League\Flysystem\Memory\MemoryAdapter;
use PHPUnit\Framework\TestCase;

final class StorageTest extends TestCase
{
private Storage $storage;

public function setUp(): void
{
$this->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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1706d8d

Please sign in to comment.