Skip to content

Commit abedaeb

Browse files
committed
feat: new command loader with compilable commands.
1 parent a0f1bb5 commit abedaeb

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
declare( strict_types = 1 );
3+
4+
namespace TheWebSolver\Codegarage\Cli\Adapter;
5+
6+
use TheWebSolver\Codegarage\Cli\CommandLoader;
7+
use TheWebSolver\Codegarage\Generator\ArrayPhpFile;
8+
9+
class CompilableCommandLoader extends CommandLoader {
10+
private ArrayPhpFile $file;
11+
12+
protected function initialize(): void {
13+
$this->file = new ArrayPhpFile();
14+
}
15+
16+
public function getArrayFile(): ArrayPhpFile {
17+
return $this->file;
18+
}
19+
20+
protected function useFoundCommand( string $classname, callable $command, string $commandName ): void {
21+
$this->file->addCallable( $classname, $command ); // @phpstan-ignore-line -- $command is always callable.
22+
23+
parent::useFoundCommand( $classname, $command, $commandName );
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
declare( strict_types = 1 );
3+
4+
namespace TheWebSolver\Codegarage\Test\Adapter;
5+
6+
use Composer\InstalledVersions;
7+
use PHPUnit\Framework\TestCase;
8+
use TheWebSolver\Codegarage\Cli\Cli;
9+
use Psr\Container\ContainerInterface;
10+
use PHPUnit\Framework\Attributes\Test;
11+
use TheWebSolver\Codegarage\Iso\Cli\Iso3166Command;
12+
use TheWebSolver\Codegarage\Iso\Cli\Iso4217Command;
13+
use TheWebSolver\Codegarage\Cli\Adapter\CompilableCommandLoader;
14+
15+
class CompilableCommandLoaderTest extends TestCase {
16+
#[Test]
17+
public function createsCompilableCommandsForIsoPackage(): void {
18+
$isoCli = InstalledVersions::getInstallPath( 'thewebsolver/iso-cli' );
19+
$loader = CompilableCommandLoader::start()
20+
->inDirectory( "{$isoCli}/Src", 'TheWebSolver\Codegarage\Iso\Cli' )
21+
->load( $this->getContainerMock() );
22+
23+
$this->assertArrayHasKey( Iso3166Command::class, $loader->getArrayFile()->getContent() );
24+
$this->assertArrayHasKey( Iso4217Command::class, $loader->getArrayFile()->getContent() );
25+
}
26+
27+
private function getContainerMock(): ContainerInterface {
28+
( $container = $this->createMock( Container::class ) )
29+
->method( 'get' )
30+
->with( Cli::class )
31+
->willReturn( $this->createStub( Cli::class ) );
32+
33+
return $container;
34+
}
35+
}
36+
37+
// phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
38+
39+
class Container implements ContainerInterface {
40+
public function set( string $id ): void {}
41+
public function get( string $id ): mixed {
42+
return null;
43+
}
44+
public function has( string $id ): bool {
45+
return false;
46+
}
47+
}

phpunit.xml.dist

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" colors="true" bootstrap="./vendor/autoload.php" failOnWarning="false" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" stopOnRisky="false" backupGlobals="false" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false" beStrictAboutCoverageMetadata="true">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" colors="true" bootstrap="./vendor/autoload.php" failOnWarning="false" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" stopOnRisky="false" backupGlobals="false" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false" beStrictAboutCoverageMetadata="true" defaultTestSuite="Tests">
33
<testsuites>
44
<testsuite name="Tests">
55
<directory suffix="Test.php">Tests</directory>
6+
<exclude>Tests/Adapter</exclude>
7+
</testsuite>
8+
<testsuite name="AdapterTests">
9+
<directory suffix="Test.php">Tests/Adapter</directory>
610
</testsuite>
711
</testsuites>
812
</phpunit>

0 commit comments

Comments
 (0)