mirror of
https://github.com/php/pie.git
synced 2026-03-23 23:12:17 +01:00
Added a basic VO to be expanded upon to represent an installable package
This commit is contained in:
27
src/DependencyResolver/Package.php
Normal file
27
src/DependencyResolver/Package.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Php\Pie\DependencyResolver;
|
||||
|
||||
use Composer\Package\CompletePackageInterface;
|
||||
|
||||
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
|
||||
final class Package
|
||||
{
|
||||
private function __construct(
|
||||
public readonly string $name,
|
||||
public readonly string $version,
|
||||
public readonly string|null $downloadUrl,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function fromComposerCompletePackage(CompletePackageInterface $completePackage): self
|
||||
{
|
||||
return new self(
|
||||
$completePackage->getPrettyName(),
|
||||
$completePackage->getPrettyVersion(),
|
||||
$completePackage->getDistUrl(),
|
||||
);
|
||||
}
|
||||
}
|
||||
25
test/unit/DependencyResolver/PackageTest.php
Normal file
25
test/unit/DependencyResolver/PackageTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Php\PieUnitTest\DependencyResolver;
|
||||
|
||||
use Composer\Package\CompletePackage;
|
||||
use Php\Pie\DependencyResolver\Package;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(Package::class)]
|
||||
final class PackageTest extends TestCase
|
||||
{
|
||||
public function testFromComposerCompletePackage(): void
|
||||
{
|
||||
$package = Package::fromComposerCompletePackage(
|
||||
new CompletePackage('foo', '1.2.3.0', '1.2.3'),
|
||||
);
|
||||
|
||||
self::assertSame('foo', $package->name);
|
||||
self::assertSame('1.2.3', $package->version);
|
||||
self::assertNull($package->downloadUrl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user