Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Types/Harness/Repository/PackageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ public function get(string $package): Package
]);
}

public function getAllPackages(): array
{
$this->importPackagesFromSources();

// $availablePackages = array_keys($this->packages);

// $candidate = null;
// foreach ($availablePackages as $availablePackage) {
// $availableVersions = array_keys($this->packages[$availablePackage]);
// foreach ($availableVersions as $availableVersion) {
// # should I write here the code the print the table of Harnes, version 1.x, Version 2.x , version x.y etc... ?
// }
// }
return $this->packages;
}

public function addPackage(string $name, string $version, array $dist): void
{
$this->mustParseVersionString($version);
Expand Down
18 changes: 15 additions & 3 deletions src/Types/Workspace/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use my127\Workspace\Types\Attribute\Collection as AttributeCollection;
use my127\Workspace\Types\Confd\Definition as ConfdDefinition;
use my127\Workspace\Types\Harness\Definition as HarnessDefinition;
use my127\Workspace\Types\Harness\Repository\PackageRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Filesystem\Path;
use Symfony\Component\Yaml\Yaml;
Expand All @@ -33,6 +34,11 @@ class Builder extends Workspace implements EnvironmentBuilder, EventSubscriberIn
*/
private $workspace;

/**
* @var PackageRepository
*/
private $packageRepository;

/**
* @var PHPExecutor
*/
Expand All @@ -48,13 +54,14 @@ class Builder extends Workspace implements EnvironmentBuilder, EventSubscriberIn
*/
private $expression;

public function __construct(Application $application, Workspace $workspace, PHPExecutor $phpExecutor, AttributeCollection $attributes, Expression $expression)
public function __construct(Application $application, AttributeCollection $attributes, Expression $expression, PackageRepository $packageRepository, PHPExecutor $phpExecutor, Workspace $workspace)
{
$this->application = $application;
$this->workspace = $workspace;
$this->phpExecutor = $phpExecutor;
$this->attributes = $attributes;
$this->expression = $expression;
$this->packageRepository = $packageRepository;
$this->phpExecutor = $phpExecutor;
$this->workspace = $workspace;
}

public function build(Environment $environment, DefinitionCollection $definitions)
Expand Down Expand Up @@ -139,6 +146,11 @@ public function build(Environment $environment, DefinitionCollection $definition
$this->workspace->run('install --step=prepare');
});
}
$this->application->section('harness list')
->usage('harness list')
->action(function (Input $input) {
$this->packageRepository->getAllPackages();
});

$this->application->section('config dump')
->option('--key=<key> Attribute key to dump.')
Expand Down
28 changes: 28 additions & 0 deletions tests/Test/Types/Harness/Repository/PackageRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ public function itGetsAPackage(): void
self::assertEquals('v1.0.0', $package->getVersion());
}

/** @test */
public function itGetsAllPackagesAndVersions(): void
{
$repository = $this->createRepository();
$repository->addPackage('foo/bar', 'v1.0.0', []);
$repository->addPackage('foo/bar2', 'v1.0.0', []);
$repository->addPackage('foo/bar2', 'v2.0.0', []);
$repository->addPackage('foo/bar3', 'v1.0.0', []);
$repository->addPackage('foo/bar3', 'v2.0.0', []);
$repository->addPackage('foo/bar3', 'v3.0.0', []);
$packages = $repository->getAllPackages();

self::assertEquals(true, is_array($packages));
self::assertCount(3, $packages);

$availableVersions = array_keys($packages['foo/bar']);

self::assertCount(1, $availableVersions);

$availableVersions = array_keys($packages['foo/bar2']);

self::assertCount(2, $availableVersions);

$availableVersions = array_keys($packages['foo/bar3']);

self::assertCount(3, $availableVersions);
}

/** @test */
public function itImportsPackageFromSource(): void
{
Expand Down