From d85927d3e4379a9482cae12d4d421a551eed25b7 Mon Sep 17 00:00:00 2001 From: Felipe Martins <6557756+fefas@users.noreply.github.com> Date: Fri, 30 Apr 2021 09:22:21 +0200 Subject: [PATCH 1/8] Rename and move classes --- README.md | 28 ++++++++-------- src/{CliApplication.php => Cli.php} | 12 ++++--- .../Extractor.php} | 13 ++++---- src/Cli/{CommandId.php => Attribute/Name.php} | 4 +-- src/Cli/Command.php | 19 ++++++----- src/Cli/Entrypoint.php | 8 +++++ src/{CliInput.php => Cli/Input.php} | 12 +++---- src/{CliOutput.php => Cli/Output.php} | 4 +-- src/Cli/Processor.php | 8 ++--- src/Cli/{ => Processor}/CommandCollection.php | 13 ++++---- src/Cli/Processor/Handler.php | 9 ++---- src/Cli/Processor/HandlerFactory.php | 17 +++++----- ...ypointExecutor.php => CommandExecutor.php} | 10 +++--- ...nDelegator.php => MiddlewareDelegator.php} | 12 +++---- src/Cli/Processor/Middleware.php | 11 +++++++ .../CouldNotLoadFromPsrContainer.php | 2 +- src/Cli/{ => PsrContainer}/LazyEntrypoint.php | 14 ++++---- src/Cli/{ => PsrContainer}/LazyMiddleware.php | 14 ++++---- src/CliEntrypoint.php | 8 ----- src/CliMiddleware.php | 10 ------ ...pplicationSettings.php => CliSettings.php} | 20 ++++++------ tests/Cli/CommandTest.php | 32 ++++++++++--------- tests/{CliInputTest.php => Cli/InputTest.php} | 10 +++--- .../{CliOutputTest.php => Cli/OutputTest.php} | 12 +++---- .../{ => Processor}/CommandCollectionTest.php | 25 ++++++++------- .../{ => PsrContainer}/LazyEntrypointTest.php | 14 ++++---- .../{ => PsrContainer}/LazyMiddlewareTest.php | 2 +- ...onSettingsTest.php => CliSettingsTest.php} | 24 +++++++------- tests/{CliApplicationTest.php => CliTest.php} | 18 +++++------ .../AnotherSampleCliEntrypoint.php | 17 ---------- .../Entrypoints/AnotherSampleEntrypoint.php | 17 ++++++++++ .../Entrypoints/SampleCliEntrypoint.php | 17 ---------- .../Doubles/Entrypoints/SampleEntrypoint.php | 17 ++++++++++ .../Middlewares/MiddlewareThatDoesNothing.php | 10 +++--- .../MiddlewareThatWritesInOutput.php | 10 +++--- tests/DoublesTrait.php | 12 ++++--- 36 files changed, 245 insertions(+), 240 deletions(-) rename src/{CliApplication.php => Cli.php} (58%) rename src/Cli/{CommandAttributeExtractor.php => Attribute/Extractor.php} (68%) rename src/Cli/{CommandId.php => Attribute/Name.php} (85%) create mode 100644 src/Cli/Entrypoint.php rename src/{CliInput.php => Cli/Input.php} (71%) rename src/{CliOutput.php => Cli/Output.php} (92%) rename src/Cli/{ => Processor}/CommandCollection.php (74%) rename src/Cli/Processor/Handlers/{EntrypointExecutor.php => CommandExecutor.php} (61%) rename src/Cli/Processor/Handlers/{MiddlewareChainDelegator.php => MiddlewareDelegator.php} (53%) create mode 100644 src/Cli/Processor/Middleware.php rename src/Cli/{ => PsrContainer}/CouldNotLoadFromPsrContainer.php (92%) rename src/Cli/{ => PsrContainer}/LazyEntrypoint.php (73%) rename src/Cli/{ => PsrContainer}/LazyMiddleware.php (67%) delete mode 100644 src/CliEntrypoint.php delete mode 100644 src/CliMiddleware.php rename src/{CliApplicationSettings.php => CliSettings.php} (72%) rename tests/{CliInputTest.php => Cli/InputTest.php} (54%) rename tests/{CliOutputTest.php => Cli/OutputTest.php} (84%) rename tests/Cli/{ => Processor}/CommandCollectionTest.php (69%) rename tests/Cli/{ => PsrContainer}/LazyEntrypointTest.php (83%) rename tests/Cli/{ => PsrContainer}/LazyMiddlewareTest.php (98%) rename tests/{CliApplicationSettingsTest.php => CliSettingsTest.php} (76%) rename tests/{CliApplicationTest.php => CliTest.php} (74%) delete mode 100644 tests/Doubles/Entrypoints/AnotherSampleCliEntrypoint.php create mode 100644 tests/Doubles/Entrypoints/AnotherSampleEntrypoint.php delete mode 100644 tests/Doubles/Entrypoints/SampleCliEntrypoint.php create mode 100644 tests/Doubles/Entrypoints/SampleEntrypoint.php diff --git a/README.md b/README.md index 6d186f9..333ddd3 100644 --- a/README.md +++ b/README.md @@ -3,34 +3,34 @@ ```php write("my entrypoing\n"); } } -class MyCliMiddleware implements CliMiddleware +class MyCliMiddleware implements Middleware { - public function execute(CliInput $input,CliOutput $output, Handler $next): void + public function execute(Input $input,Output $output, Handler $next): void { $output->write("my middleware\n"); $next->execute($input, $output); } } -$settings = CliApplicationSettings::default() +$settings = CliSettings::default() ->withOutput('/var/tmp/file') // default is php://stdout ->withEntrypoints( new MyCliEntrypoint(), @@ -39,7 +39,7 @@ $settings = CliApplicationSettings::default() new MyCliMiddleware(), ); -$cliApplication = CliApplication::bootstrap($settings); +$cliApplication = Cli::bootstrap($settings); $cliApplication->run('./bin', 'command-id'); // it could be $cliApplication->run($_SERVER['argv']); ``` \ No newline at end of file diff --git a/src/CliApplication.php b/src/Cli.php similarity index 58% rename from src/CliApplication.php rename to src/Cli.php index 0eb9374..6a4ab11 100644 --- a/src/CliApplication.php +++ b/src/Cli.php @@ -2,27 +2,29 @@ namespace Bauhaus; +use Bauhaus\Cli\Input; +use Bauhaus\Cli\Output; use Bauhaus\Cli\Processor; -final class CliApplication +final class Cli { private function __construct( - private CliOutput $output, + private Output $output, private Processor $processor, ) { } - public static function bootstrap(CliApplicationSettings $settings): self + public static function bootstrap(CliSettings $settings): self { return new self( - CliOutput::to($settings->output()), + Output::to($settings->output()), Processor::build($settings), ); } public function run(string ...$argv): void { - $input = CliInput::fromArgv(...$argv); + $input = Input::fromArgv(...$argv); $this->processor->execute($input, $this->output); } diff --git a/src/Cli/CommandAttributeExtractor.php b/src/Cli/Attribute/Extractor.php similarity index 68% rename from src/Cli/CommandAttributeExtractor.php rename to src/Cli/Attribute/Extractor.php index 82bdb32..f715606 100644 --- a/src/Cli/CommandAttributeExtractor.php +++ b/src/Cli/Attribute/Extractor.php @@ -1,18 +1,19 @@ className(); @@ -21,9 +22,9 @@ public function __construct(CliEntrypoint $entrypoint) $this->reflection = new ReflectionClass($entrypoint); } - public function id(): CommandId + public function id(): Name { - return $this->attributeInstance(CommandId::class); + return $this->attributeInstance(Name::class); } /** diff --git a/src/Cli/CommandId.php b/src/Cli/Attribute/Name.php similarity index 85% rename from src/Cli/CommandId.php rename to src/Cli/Attribute/Name.php index 6f21b76..a08ed08 100644 --- a/src/Cli/CommandId.php +++ b/src/Cli/Attribute/Name.php @@ -1,11 +1,11 @@ extractEntrypointAttributes(); } - public static function fromEntrypoint(CliEntrypoint $entrypoint): self + public static function fromEntrypoint(Entrypoint $entrypoint): self { return new self($entrypoint); } - public function id(): CommandId + public function id(): Name { return $this->id; } - public function execute(CliInput $input, CliOutput $output): void + public function execute(Input $input, Output $output): void { $this->entrypoint->execute($input, $output); } - public function match(CliInput $input): bool + public function match(Input $input): bool { return $this->id->equalTo($input->commandId()); } private function extractEntrypointAttributes(): void { - $attributeExtractor = new CommandAttributeExtractor($this->entrypoint); + $attributeExtractor = new Extractor($this->entrypoint); $this->id = $attributeExtractor->id(); } diff --git a/src/Cli/Entrypoint.php b/src/Cli/Entrypoint.php new file mode 100644 index 0000000..fdfd11b --- /dev/null +++ b/src/Cli/Entrypoint.php @@ -0,0 +1,8 @@ +commandId; } private function parseInput(): void { - $this->commandId = new CommandId($this->argv[1]); + $this->commandId = new Name($this->argv[1]); } } diff --git a/src/CliOutput.php b/src/Cli/Output.php similarity index 92% rename from src/CliOutput.php rename to src/Cli/Output.php index 108a466..8e5aa54 100644 --- a/src/CliOutput.php +++ b/src/Cli/Output.php @@ -1,10 +1,10 @@ handler->execute($input, $output); } diff --git a/src/Cli/CommandCollection.php b/src/Cli/Processor/CommandCollection.php similarity index 74% rename from src/Cli/CommandCollection.php rename to src/Cli/Processor/CommandCollection.php index fd759fd..65dd3fd 100644 --- a/src/Cli/CommandCollection.php +++ b/src/Cli/Processor/CommandCollection.php @@ -1,10 +1,11 @@ sort(); } - public static function fromEntrypoints(CliEntrypoint ...$entrypoints): self + public static function fromEntrypoints(Entrypoint ...$entrypoints): self { $commands = array_map( - fn (CliEntrypoint $e) => Command::fromEntrypoint($e), + fn (Entrypoint $e) => Command::fromEntrypoint($e), $entrypoints, ); @@ -36,7 +37,7 @@ public function getIterator() return new ArrayIterator($this->commands); } - public function findMatch(CliInput $input): ?Command + public function findMatch(Input $input): ?Command { foreach ($this->commands as $command) { if ($command->match($input)) { diff --git a/src/Cli/Processor/Handler.php b/src/Cli/Processor/Handler.php index 1c43349..b965a63 100644 --- a/src/Cli/Processor/Handler.php +++ b/src/Cli/Processor/Handler.php @@ -2,13 +2,10 @@ namespace Bauhaus\Cli\Processor; -use Bauhaus\CliInput; -use Bauhaus\CliOutput; +use Bauhaus\Cli\Input; +use Bauhaus\Cli\Output; -/** - * @internal - */ interface Handler { - public function execute(CliInput $input, CliOutput $output): void; + public function execute(Input $input, Output $output): void; } diff --git a/src/Cli/Processor/HandlerFactory.php b/src/Cli/Processor/HandlerFactory.php index c16bc02..61f7d9e 100644 --- a/src/Cli/Processor/HandlerFactory.php +++ b/src/Cli/Processor/HandlerFactory.php @@ -2,10 +2,9 @@ namespace Bauhaus\Cli\Processor; -use Bauhaus\Cli\CommandCollection; -use Bauhaus\Cli\Processor\Handlers\EntrypointExecutor; -use Bauhaus\Cli\Processor\Handlers\MiddlewareChainDelegator; -use Bauhaus\CliApplicationSettings; +use Bauhaus\Cli\Processor\Handlers\CommandExecutor; +use Bauhaus\Cli\Processor\Handlers\MiddlewareDelegator; +use Bauhaus\CliSettings; /** * @internal @@ -15,12 +14,12 @@ class HandlerFactory private CommandCollection $commands; private function __construct( - private CliApplicationSettings $settings, + private CliSettings $settings, ) { $this->commands = CommandCollection::fromEntrypoints(...$settings->entrypoints()); } - public static function build(CliApplicationSettings $settings): Handler + public static function build(CliSettings $settings): Handler { $factory = new self($settings); @@ -29,9 +28,9 @@ public static function build(CliApplicationSettings $settings): Handler return $factory->buildMiddlewareChain($entrypointExecutor); } - private function buildEntrypointExecutor(): EntrypointExecutor + private function buildEntrypointExecutor(): CommandExecutor { - return new EntrypointExecutor($this->commands); + return new CommandExecutor($this->commands); } private function buildMiddlewareChain(Handler $next): Handler @@ -39,7 +38,7 @@ private function buildMiddlewareChain(Handler $next): Handler $middlewares = array_reverse($this->settings->middlewares()); foreach ($middlewares as $middleware) { - $next = new MiddlewareChainDelegator($middleware, $next); + $next = new MiddlewareDelegator($middleware, $next); } return $next; diff --git a/src/Cli/Processor/Handlers/EntrypointExecutor.php b/src/Cli/Processor/Handlers/CommandExecutor.php similarity index 61% rename from src/Cli/Processor/Handlers/EntrypointExecutor.php rename to src/Cli/Processor/Handlers/CommandExecutor.php index 9f0d542..593f4e7 100644 --- a/src/Cli/Processor/Handlers/EntrypointExecutor.php +++ b/src/Cli/Processor/Handlers/CommandExecutor.php @@ -2,22 +2,22 @@ namespace Bauhaus\Cli\Processor\Handlers; -use Bauhaus\Cli\CommandCollection; +use Bauhaus\Cli\Processor\CommandCollection; use Bauhaus\Cli\Processor\Handler; -use Bauhaus\CliInput; -use Bauhaus\CliOutput; +use Bauhaus\Cli\Input; +use Bauhaus\Cli\Output; /** * @internal */ -class EntrypointExecutor implements Handler +class CommandExecutor implements Handler { public function __construct( private CommandCollection $commands, ) { } - public function execute(CliInput $input, CliOutput $output): void + public function execute(Input $input, Output $output): void { $command = $this->commands->findMatch($input); diff --git a/src/Cli/Processor/Handlers/MiddlewareChainDelegator.php b/src/Cli/Processor/Handlers/MiddlewareDelegator.php similarity index 53% rename from src/Cli/Processor/Handlers/MiddlewareChainDelegator.php rename to src/Cli/Processor/Handlers/MiddlewareDelegator.php index d17b658..077a67a 100644 --- a/src/Cli/Processor/Handlers/MiddlewareChainDelegator.php +++ b/src/Cli/Processor/Handlers/MiddlewareDelegator.php @@ -3,22 +3,22 @@ namespace Bauhaus\Cli\Processor\Handlers; use Bauhaus\Cli\Processor\Handler; -use Bauhaus\CliInput; -use Bauhaus\CliMiddleware; -use Bauhaus\CliOutput; +use Bauhaus\Cli\Input; +use Bauhaus\Cli\Processor\Middleware; +use Bauhaus\Cli\Output; /** * @internal */ -class MiddlewareChainDelegator implements Handler +class MiddlewareDelegator implements Handler { public function __construct( - private CliMiddleware $middleware, + private Middleware $middleware, private Handler $next, ) { } - public function execute(CliInput $input, CliOutput $output): void + public function execute(Input $input, Output $output): void { $this->middleware->execute($input, $output, $this->next); } diff --git a/src/Cli/Processor/Middleware.php b/src/Cli/Processor/Middleware.php new file mode 100644 index 0000000..2ba9f58 --- /dev/null +++ b/src/Cli/Processor/Middleware.php @@ -0,0 +1,11 @@ +load()->execute($input, $output); } - private function load(): CliEntrypoint + private function load(): Entrypoint { try { return $this->container->get($this->entrypointClass); diff --git a/src/Cli/LazyMiddleware.php b/src/Cli/PsrContainer/LazyMiddleware.php similarity index 67% rename from src/Cli/LazyMiddleware.php rename to src/Cli/PsrContainer/LazyMiddleware.php index f50ab50..1f7eedb 100644 --- a/src/Cli/LazyMiddleware.php +++ b/src/Cli/PsrContainer/LazyMiddleware.php @@ -1,18 +1,18 @@ load()->execute($input, $output, $next); } - private function load(): CliMiddleware + private function load(): Middleware { try { return $this->container->get($this->middlewareClass); diff --git a/src/CliEntrypoint.php b/src/CliEntrypoint.php deleted file mode 100644 index aa281dc..0000000 --- a/src/CliEntrypoint.php +++ /dev/null @@ -1,8 +0,0 @@ - is_string($e) ? new LazyEntrypoint($this->container, $e) : $e, + fn ($e): Entrypoint => is_string($e) ? new LazyEntrypoint($this->container, $e) : $e, $entrypoints ); @@ -76,10 +78,10 @@ public function withEntrypoints(CliEntrypoint|string ...$entrypoints): self return $new; } - public function withMiddlewares(CliMiddleware|string ...$middlewares): self + public function withMiddlewares(Middleware|string ...$middlewares): self { $middlewares = array_map( - fn ($m): CliMiddleware => is_string($m) ? new LazyMiddleware($this->container, $m) : $m, + fn ($m): Middleware => is_string($m) ? new LazyMiddleware($this->container, $m) : $m, $middlewares ); diff --git a/tests/Cli/CommandTest.php b/tests/Cli/CommandTest.php index 92e939f..b35ce39 100644 --- a/tests/Cli/CommandTest.php +++ b/tests/Cli/CommandTest.php @@ -2,10 +2,12 @@ namespace Bauhaus\Cli; -use Bauhaus\CliEntrypoint; -use Bauhaus\CliInput; -use Bauhaus\Doubles\Entrypoints\AnotherSampleCliEntrypoint; -use Bauhaus\Doubles\Entrypoints\SampleCliEntrypoint; +use Bauhaus\Cli\Attribute\Name; +use Bauhaus\Cli\PsrContainer\LazyEntrypoint; +use Bauhaus\Cli\Entrypoint; +use Bauhaus\Cli\Input; +use Bauhaus\Doubles\Entrypoints\AnotherSampleEntrypoint; +use Bauhaus\Doubles\Entrypoints\SampleEntrypoint; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface as PsrContainer; @@ -17,16 +19,16 @@ public function entrypointsWithExpectedCommandIds(): array return [ [ - new SampleCliEntrypoint(), - new CommandId('sample-id'), + new SampleEntrypoint(), + new Name('sample-id'), ], [ - new AnotherSampleCliEntrypoint(), - new CommandId('another-sample-id'), + new AnotherSampleEntrypoint(), + new Name('another-sample-id'), ], [ - new LazyEntrypoint($container, AnotherSampleCliEntrypoint::class), - new CommandId('another-sample-id'), + new LazyEntrypoint($container, AnotherSampleEntrypoint::class), + new Name('another-sample-id'), ], ]; } @@ -35,7 +37,7 @@ public function entrypointsWithExpectedCommandIds(): array * @test * @dataProvider entrypointsWithExpectedCommandIds */ - public function extractIdFromEntrypoint(CliEntrypoint $entrypoint, CommandId $expected): void + public function extractIdFromEntrypoint(Entrypoint $entrypoint, Name $expected): void { $command = Command::fromEntrypoint($entrypoint); @@ -49,8 +51,8 @@ public function extractIdFromEntrypoint(CliEntrypoint $entrypoint, CommandId $ex */ public function matchIfInputCommandIdIsEqual(): void { - $input = CliInput::fromString('./bin sample-id'); - $command = Command::fromEntrypoint(new SampleCliEntrypoint()); + $input = Input::fromString('./bin sample-id'); + $command = Command::fromEntrypoint(new SampleEntrypoint()); $result = $command->match($input); @@ -62,8 +64,8 @@ public function matchIfInputCommandIdIsEqual(): void */ public function doNotMatchIfInputCommandIdIsNotEqual(): void { - $input = CliInput::fromString('./bin another-sample-id'); - $command = Command::fromEntrypoint(new SampleCliEntrypoint()); + $input = Input::fromString('./bin another-sample-id'); + $command = Command::fromEntrypoint(new SampleEntrypoint()); $result = $command->match($input); diff --git a/tests/CliInputTest.php b/tests/Cli/InputTest.php similarity index 54% rename from tests/CliInputTest.php rename to tests/Cli/InputTest.php index cea3658..f9aff39 100644 --- a/tests/CliInputTest.php +++ b/tests/Cli/InputTest.php @@ -1,20 +1,20 @@ commandId(); $this->assertEquals($expected, $commandId); diff --git a/tests/CliOutputTest.php b/tests/Cli/OutputTest.php similarity index 84% rename from tests/CliOutputTest.php rename to tests/Cli/OutputTest.php index d9641ce..594a9d9 100644 --- a/tests/CliOutputTest.php +++ b/tests/Cli/OutputTest.php @@ -1,6 +1,6 @@ expectException(CannotWrite::class); $this->expectExceptionMessage("Provided output is a directory: $dir"); - CliOutput::to($dir); + Output::to($dir); } /** @@ -37,7 +37,7 @@ public function throwExceptionIfOutputIsADirectory(): void */ public function writeByAppendingStringToOutput(): void { - $output = CliOutput::to(self::OUTPUT); + $output = Output::to(self::OUTPUT); $output->write('foo'); $output->write('bar'); @@ -50,7 +50,7 @@ public function writeByAppendingStringToOutput(): void */ public function cannotWriteInStreamAfterOutputIsDestructed(): void { - $output = CliOutput::to(self::OUTPUT); + $output = Output::to(self::OUTPUT); $stream = $this->extractStream($output); unset($output); @@ -59,7 +59,7 @@ public function cannotWriteInStreamAfterOutputIsDestructed(): void $stream->write('foo'); } - private function extractStream(CliOutput $output): Stream + private function extractStream(Output $output): Stream { $r = new ReflectionClass($output); $p = $r->getProperty('stream'); diff --git a/tests/Cli/CommandCollectionTest.php b/tests/Cli/Processor/CommandCollectionTest.php similarity index 69% rename from tests/Cli/CommandCollectionTest.php rename to tests/Cli/Processor/CommandCollectionTest.php index b472838..c091423 100644 --- a/tests/Cli/CommandCollectionTest.php +++ b/tests/Cli/Processor/CommandCollectionTest.php @@ -1,11 +1,12 @@ collection = CommandCollection::fromEntrypoints( - new SampleCliEntrypoint(), - new AnotherSampleCliEntrypoint(), + new SampleEntrypoint(), + new AnotherSampleEntrypoint(), ); } @@ -25,7 +26,7 @@ protected function setUp(): void */ public function returnNullIfNoCommandMatchesInput(): void { - $input = CliInput::fromString('./bin not-matching'); + $input = Input::fromString('./bin not-matching'); $null = $this->collection->findMatch($input); @@ -35,8 +36,8 @@ public function returnNullIfNoCommandMatchesInput(): void public function inputsWithExpectedMatchingCommand(): array { return [ - ['./bin sample-id', Command::fromEntrypoint(new SampleCliEntrypoint())], - ['./bin another-sample-id', Command::fromEntrypoint(new AnotherSampleCliEntrypoint())], + ['./bin sample-id', Command::fromEntrypoint(new SampleEntrypoint())], + ['./bin another-sample-id', Command::fromEntrypoint(new AnotherSampleEntrypoint())], ]; } @@ -46,7 +47,7 @@ public function inputsWithExpectedMatchingCommand(): array */ public function returnCommandMatchingInput(string $rawInput, Command $expected): void { - $input = CliInput::fromString($rawInput); + $input = Input::fromString($rawInput); $command = $this->collection->findMatch($input); @@ -59,8 +60,8 @@ public function returnCommandMatchingInput(string $rawInput, Command $expected): public function isIterableHavingCommandsOrderedByTheirId(): void { $expected = new ArrayIterator([ - Command::fromEntrypoint(new AnotherSampleCliEntrypoint()), - Command::fromEntrypoint(new SampleCliEntrypoint()), + Command::fromEntrypoint(new AnotherSampleEntrypoint()), + Command::fromEntrypoint(new SampleEntrypoint()), ]); $iterator = $this->collection->getIterator(); diff --git a/tests/Cli/LazyEntrypointTest.php b/tests/Cli/PsrContainer/LazyEntrypointTest.php similarity index 83% rename from tests/Cli/LazyEntrypointTest.php rename to tests/Cli/PsrContainer/LazyEntrypointTest.php index a285670..6d27136 100644 --- a/tests/Cli/LazyEntrypointTest.php +++ b/tests/Cli/PsrContainer/LazyEntrypointTest.php @@ -1,8 +1,8 @@ expects($this->never()) ->method('get'); - new LazyEntrypoint($this->container, SampleCliEntrypoint::class); + new LazyEntrypoint($this->container, SampleEntrypoint::class); } /** @@ -40,10 +40,10 @@ public function loadEntrypointFromContainerBeforeItsExecution(): void $this->container ->expects($this->once()) ->method('get') - ->with(SampleCliEntrypoint::class) - ->willReturn(new SampleCliEntrypoint()); + ->with(SampleEntrypoint::class) + ->willReturn(new SampleEntrypoint()); - $entrypoint = new LazyEntrypoint($this->container, SampleCliEntrypoint::class); + $entrypoint = new LazyEntrypoint($this->container, SampleEntrypoint::class); $entrypoint->execute($this->dummyInput(), $this->dummyOutput()); } @@ -55,7 +55,7 @@ public function throwExceptionIfEntrypointCanNotBeLoadedFromContainer(): void $this->container ->method('get') ->willThrowException(new Exception('error msg')); - $class = SampleCliEntrypoint::class; + $class = SampleEntrypoint::class; $this->expectException(CouldNotLoadFromPsrContainer::class); $this->expectExceptionMessage(<<output(); @@ -34,7 +34,7 @@ public function defaultOutputIsPhpStdout(): void */ public function allowOutputCustomizationByCreatingNewInstance(): void { - $originalSettings = CliApplicationSettings::default(); + $originalSettings = CliSettings::default(); $newSettings = $originalSettings->withOutput('/var/tmp/some_file.txt'); @@ -48,13 +48,13 @@ public function allowOutputCustomizationByCreatingNewInstance(): void */ public function setEntrypointsByNewInstance(): void { - $originalSettings = CliApplicationSettings::default(); + $originalSettings = CliSettings::default(); - $newSettings = $originalSettings->withEntrypoints(new SampleCliEntrypoint()); + $newSettings = $originalSettings->withEntrypoints(new SampleEntrypoint()); $this->assertNotSame($originalSettings, $newSettings); $this->assertEquals([], $originalSettings->entrypoints()); - $this->assertEquals([new SampleCliEntrypoint()], $newSettings->entrypoints()); + $this->assertEquals([new SampleEntrypoint()], $newSettings->entrypoints()); } /** @@ -62,15 +62,15 @@ public function setEntrypointsByNewInstance(): void */ public function createLazyEntrypointInCaseClassNameIsProvided(): void { - $originalSettings = CliApplicationSettings::default() + $originalSettings = CliSettings::default() ->withPsrContainer($this->container); - $newSettings = $originalSettings->withEntrypoints(SampleCliEntrypoint::class); + $newSettings = $originalSettings->withEntrypoints(SampleEntrypoint::class); $this->assertNotSame($originalSettings, $newSettings); $this->assertEquals([], $originalSettings->entrypoints()); $this->assertEquals( - [new LazyEntrypoint($this->container, SampleCliEntrypoint::class)], + [new LazyEntrypoint($this->container, SampleEntrypoint::class)], $newSettings->entrypoints(), ); } @@ -80,7 +80,7 @@ public function createLazyEntrypointInCaseClassNameIsProvided(): void */ public function setMiddlewaresByNewInstance(): void { - $originalSettings = CliApplicationSettings::default(); + $originalSettings = CliSettings::default(); $newSettings = $originalSettings->withMiddlewares(new MiddlewareThatWritesInOutput('#')); diff --git a/tests/CliApplicationTest.php b/tests/CliTest.php similarity index 74% rename from tests/CliApplicationTest.php rename to tests/CliTest.php index 48a455e..5fcc840 100644 --- a/tests/CliApplicationTest.php +++ b/tests/CliTest.php @@ -2,38 +2,38 @@ namespace Bauhaus; -use Bauhaus\Doubles\Entrypoints\AnotherSampleCliEntrypoint; -use Bauhaus\Doubles\Entrypoints\SampleCliEntrypoint; +use Bauhaus\Doubles\Entrypoints\AnotherSampleEntrypoint; +use Bauhaus\Doubles\Entrypoints\SampleEntrypoint; use Bauhaus\Doubles\Middlewares\MiddlewareThatWritesInOutput; use Bauhaus\Doubles\SimpleContainer; use PHPUnit\Framework\TestCase; -class CliApplicationTest extends TestCase +class CliTest extends TestCase { private const OUTPUT = '/var/tmp/cli_application_test.txt'; - private CliApplication $cliApplication; + private Cli $cliApplication; protected function setUp(): void { $container = new SimpleContainer([ - AnotherSampleCliEntrypoint::class => new AnotherSampleCliEntrypoint(), + AnotherSampleEntrypoint::class => new AnotherSampleEntrypoint(), MiddlewareThatWritesInOutput::class => new MiddlewareThatWritesInOutput('# '), ]); - $settings = CliApplicationSettings::default() + $settings = CliSettings::default() ->withOutput(self::OUTPUT) ->withPsrContainer($container) ->withEntrypoints( - new SampleCliEntrypoint(), - AnotherSampleCliEntrypoint::class, + new SampleEntrypoint(), + AnotherSampleEntrypoint::class, ) ->withMiddlewares( new MiddlewareThatWritesInOutput('! '), MiddlewareThatWritesInOutput::class, ); - $this->cliApplication = CliApplication::bootstrap($settings); + $this->cliApplication = Cli::bootstrap($settings); } protected function tearDown(): void diff --git a/tests/Doubles/Entrypoints/AnotherSampleCliEntrypoint.php b/tests/Doubles/Entrypoints/AnotherSampleCliEntrypoint.php deleted file mode 100644 index 38781be..0000000 --- a/tests/Doubles/Entrypoints/AnotherSampleCliEntrypoint.php +++ /dev/null @@ -1,17 +0,0 @@ -write('another sample entrypoint'); - } -} diff --git a/tests/Doubles/Entrypoints/AnotherSampleEntrypoint.php b/tests/Doubles/Entrypoints/AnotherSampleEntrypoint.php new file mode 100644 index 0000000..a002ba1 --- /dev/null +++ b/tests/Doubles/Entrypoints/AnotherSampleEntrypoint.php @@ -0,0 +1,17 @@ +write('another sample entrypoint'); + } +} diff --git a/tests/Doubles/Entrypoints/SampleCliEntrypoint.php b/tests/Doubles/Entrypoints/SampleCliEntrypoint.php deleted file mode 100644 index 3eff1b7..0000000 --- a/tests/Doubles/Entrypoints/SampleCliEntrypoint.php +++ /dev/null @@ -1,17 +0,0 @@ -write('sample entrypoint'); - } -} diff --git a/tests/Doubles/Entrypoints/SampleEntrypoint.php b/tests/Doubles/Entrypoints/SampleEntrypoint.php new file mode 100644 index 0000000..85c13c9 --- /dev/null +++ b/tests/Doubles/Entrypoints/SampleEntrypoint.php @@ -0,0 +1,17 @@ +write('sample entrypoint'); + } +} diff --git a/tests/Doubles/Middlewares/MiddlewareThatDoesNothing.php b/tests/Doubles/Middlewares/MiddlewareThatDoesNothing.php index ad0023d..9b10d55 100644 --- a/tests/Doubles/Middlewares/MiddlewareThatDoesNothing.php +++ b/tests/Doubles/Middlewares/MiddlewareThatDoesNothing.php @@ -3,13 +3,13 @@ namespace Bauhaus\Doubles\Middlewares; use Bauhaus\Cli\Processor\Handler; -use Bauhaus\CliMiddleware; -use Bauhaus\CliInput; -use Bauhaus\CliOutput; +use Bauhaus\Cli\Processor\Middleware; +use Bauhaus\Cli\Input; +use Bauhaus\Cli\Output; -class MiddlewareThatDoesNothing implements CliMiddleware +class MiddlewareThatDoesNothing implements Middleware { - public function execute(CliInput $input, CliOutput $output, Handler $next): void + public function execute(Input $input, Output $output, Handler $next): void { $next->execute($input, $output); } diff --git a/tests/Doubles/Middlewares/MiddlewareThatWritesInOutput.php b/tests/Doubles/Middlewares/MiddlewareThatWritesInOutput.php index 09939ca..ccda481 100644 --- a/tests/Doubles/Middlewares/MiddlewareThatWritesInOutput.php +++ b/tests/Doubles/Middlewares/MiddlewareThatWritesInOutput.php @@ -3,18 +3,18 @@ namespace Bauhaus\Doubles\Middlewares; use Bauhaus\Cli\Processor\Handler; -use Bauhaus\CliMiddleware; -use Bauhaus\CliInput; -use Bauhaus\CliOutput; +use Bauhaus\Cli\Processor\Middleware; +use Bauhaus\Cli\Input; +use Bauhaus\Cli\Output; -class MiddlewareThatWritesInOutput implements CliMiddleware +class MiddlewareThatWritesInOutput implements Middleware { public function __construct( private string $toWrite, ) { } - public function execute(CliInput $input, CliOutput $output, Handler $next): void + public function execute(Input $input, Output $output, Handler $next): void { $output->write($this->toWrite); $next->execute($input, $output); diff --git a/tests/DoublesTrait.php b/tests/DoublesTrait.php index 170cc61..7bad5ff 100644 --- a/tests/DoublesTrait.php +++ b/tests/DoublesTrait.php @@ -2,24 +2,26 @@ namespace Bauhaus; +use Bauhaus\Cli\Input; +use Bauhaus\Cli\Output; use Bauhaus\Cli\Processor\Handler; trait DoublesTrait { - protected function dummyInput(): CliInput + protected function dummyInput(): Input { - return CliInput::fromString('does not matter'); + return Input::fromString('does not matter'); } - protected function dummyOutput(): CliOutput + protected function dummyOutput(): Output { - return CliOutput::to('php://memory'); + return Output::to('php://memory'); } protected function dummyHandler(): Handler { return new class implements Handler { - public function execute(CliInput $input, CliOutput $output): void + public function execute(Input $input, Output $output): void { } }; From 531e02dd0e562db542f0b3218baa132a44b19ea0 Mon Sep 17 00:00:00 2001 From: Felipe Martins <6557756+fefas@users.noreply.github.com> Date: Sat, 1 May 2021 11:58:36 +0200 Subject: [PATCH 2/8] Add missing finals --- src/Cli/Processor.php | 2 +- src/Cli/Processor/HandlerFactory.php | 2 +- src/Cli/Processor/Handlers/CommandExecutor.php | 2 +- src/Cli/Processor/Handlers/MiddlewareDelegator.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Cli/Processor.php b/src/Cli/Processor.php index 7411402..a798f32 100644 --- a/src/Cli/Processor.php +++ b/src/Cli/Processor.php @@ -9,7 +9,7 @@ /** * @internal */ -class Processor +final class Processor { private function __construct( private Handler $handler, diff --git a/src/Cli/Processor/HandlerFactory.php b/src/Cli/Processor/HandlerFactory.php index 61f7d9e..11de310 100644 --- a/src/Cli/Processor/HandlerFactory.php +++ b/src/Cli/Processor/HandlerFactory.php @@ -9,7 +9,7 @@ /** * @internal */ -class HandlerFactory +final class HandlerFactory { private CommandCollection $commands; diff --git a/src/Cli/Processor/Handlers/CommandExecutor.php b/src/Cli/Processor/Handlers/CommandExecutor.php index 593f4e7..fabb3f8 100644 --- a/src/Cli/Processor/Handlers/CommandExecutor.php +++ b/src/Cli/Processor/Handlers/CommandExecutor.php @@ -10,7 +10,7 @@ /** * @internal */ -class CommandExecutor implements Handler +final class CommandExecutor implements Handler { public function __construct( private CommandCollection $commands, diff --git a/src/Cli/Processor/Handlers/MiddlewareDelegator.php b/src/Cli/Processor/Handlers/MiddlewareDelegator.php index 077a67a..48078d0 100644 --- a/src/Cli/Processor/Handlers/MiddlewareDelegator.php +++ b/src/Cli/Processor/Handlers/MiddlewareDelegator.php @@ -10,7 +10,7 @@ /** * @internal */ -class MiddlewareDelegator implements Handler +final class MiddlewareDelegator implements Handler { public function __construct( private Middleware $middleware, From ede40745437f59ff7b1f85337d61c927de128d62 Mon Sep 17 00:00:00 2001 From: Felipe Martins <6557756+fefas@users.noreply.github.com> Date: Sun, 9 May 2021 19:57:36 +0200 Subject: [PATCH 3/8] Rename double entrypoint names --- tests/Cli/CommandTest.php | 10 +++++----- tests/Cli/Processor/CommandCollectionTest.php | 4 ++-- tests/CliTest.php | 4 ++-- tests/Doubles/Entrypoints/AnotherSampleEntrypoint.php | 2 +- tests/Doubles/Entrypoints/SampleEntrypoint.php | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Cli/CommandTest.php b/tests/Cli/CommandTest.php index b35ce39..b8d9788 100644 --- a/tests/Cli/CommandTest.php +++ b/tests/Cli/CommandTest.php @@ -20,15 +20,15 @@ public function entrypointsWithExpectedCommandIds(): array return [ [ new SampleEntrypoint(), - new Name('sample-id'), + new Name('sample-name'), ], [ new AnotherSampleEntrypoint(), - new Name('another-sample-id'), + new Name('another-sample-name'), ], [ new LazyEntrypoint($container, AnotherSampleEntrypoint::class), - new Name('another-sample-id'), + new Name('another-sample-name'), ], ]; } @@ -51,7 +51,7 @@ public function extractIdFromEntrypoint(Entrypoint $entrypoint, Name $expected): */ public function matchIfInputCommandIdIsEqual(): void { - $input = Input::fromString('./bin sample-id'); + $input = Input::fromString('./bin sample-name'); $command = Command::fromEntrypoint(new SampleEntrypoint()); $result = $command->match($input); @@ -64,7 +64,7 @@ public function matchIfInputCommandIdIsEqual(): void */ public function doNotMatchIfInputCommandIdIsNotEqual(): void { - $input = Input::fromString('./bin another-sample-id'); + $input = Input::fromString('./bin another-sample-name'); $command = Command::fromEntrypoint(new SampleEntrypoint()); $result = $command->match($input); diff --git a/tests/Cli/Processor/CommandCollectionTest.php b/tests/Cli/Processor/CommandCollectionTest.php index c091423..dbe1c05 100644 --- a/tests/Cli/Processor/CommandCollectionTest.php +++ b/tests/Cli/Processor/CommandCollectionTest.php @@ -36,8 +36,8 @@ public function returnNullIfNoCommandMatchesInput(): void public function inputsWithExpectedMatchingCommand(): array { return [ - ['./bin sample-id', Command::fromEntrypoint(new SampleEntrypoint())], - ['./bin another-sample-id', Command::fromEntrypoint(new AnotherSampleEntrypoint())], + ['./bin sample-name', Command::fromEntrypoint(new SampleEntrypoint())], + ['./bin another-sample-name', Command::fromEntrypoint(new AnotherSampleEntrypoint())], ]; } diff --git a/tests/CliTest.php b/tests/CliTest.php index 5fcc840..c7335b2 100644 --- a/tests/CliTest.php +++ b/tests/CliTest.php @@ -46,8 +46,8 @@ protected function tearDown(): void public function commandIdWithExpectedOutput(): array { return [ - ['sample-id', '! # sample entrypoint'], - ['another-sample-id', '! # another sample entrypoint'], + ['sample-name', '! # sample entrypoint'], + ['another-sample-name', '! # another sample entrypoint'], ]; } diff --git a/tests/Doubles/Entrypoints/AnotherSampleEntrypoint.php b/tests/Doubles/Entrypoints/AnotherSampleEntrypoint.php index a002ba1..df495c6 100644 --- a/tests/Doubles/Entrypoints/AnotherSampleEntrypoint.php +++ b/tests/Doubles/Entrypoints/AnotherSampleEntrypoint.php @@ -7,7 +7,7 @@ use Bauhaus\Cli\Input; use Bauhaus\Cli\Output; -#[Name('another-sample-id')] +#[Name('another-sample-name')] class AnotherSampleEntrypoint implements Entrypoint { public function execute(Input $input, Output $output): void diff --git a/tests/Doubles/Entrypoints/SampleEntrypoint.php b/tests/Doubles/Entrypoints/SampleEntrypoint.php index 85c13c9..58ba643 100644 --- a/tests/Doubles/Entrypoints/SampleEntrypoint.php +++ b/tests/Doubles/Entrypoints/SampleEntrypoint.php @@ -7,7 +7,7 @@ use Bauhaus\Cli\Input; use Bauhaus\Cli\Output; -#[Name('sample-id')] +#[Name('sample-name')] class SampleEntrypoint implements Entrypoint { public function execute(Input $input, Output $output): void From dc8f18445c22486d052b2c2f0be834776fd4bbe0 Mon Sep 17 00:00:00 2001 From: Felipe Martins <6557756+fefas@users.noreply.github.com> Date: Wed, 12 May 2021 22:59:57 +0200 Subject: [PATCH 4/8] Validate name argument --- src/Cli/Attribute/InvalidArgument.php | 13 +++++ src/Cli/Attribute/Name.php | 12 +++++ tests/Cli/Attribute/NameTest.php | 78 +++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 src/Cli/Attribute/InvalidArgument.php create mode 100644 tests/Cli/Attribute/NameTest.php diff --git a/src/Cli/Attribute/InvalidArgument.php b/src/Cli/Attribute/InvalidArgument.php new file mode 100644 index 0000000..5578186 --- /dev/null +++ b/src/Cli/Attribute/InvalidArgument.php @@ -0,0 +1,13 @@ +assertIsValid(); } public function equalTo(self $that): bool @@ -21,4 +22,15 @@ public function __toString(): string { return $this->value; } + + private function assertIsValid(): void + { + $alphaNumeric = 'A-Za-z0-9'; + $allowed = "$alphaNumeric-_"; + $word = "[$alphaNumeric][$allowed]*"; + + if (0 === preg_match("/^$word(:$word)*$/", $this->value)) { + throw new InvalidArgument($this->value); + } + } } diff --git a/tests/Cli/Attribute/NameTest.php b/tests/Cli/Attribute/NameTest.php new file mode 100644 index 0000000..42b26bd --- /dev/null +++ b/tests/Cli/Attribute/NameTest.php @@ -0,0 +1,78 @@ +expectException(InvalidArgument::class); + $this->expectExceptionMessage("Invalid cli argument: '$invalid'"); + + new Name($invalid); + } + + public function validNames(): array + { + return [ + ['valid'], + ['val:id'], + ['va:aa:lid'], + ['v:aa:lid'], + ['v:a:lid'], + ['val_id'], + ['val-id'], + ['val-i_d'], + ['val_-id'], + ]; + } + + /** + * @test + * @dataProvider validNames + */ + public function convertToString(string $str): void + { + $name = new Name($str); + + $this->assertEquals($str, (string) $name); + } + + /** + * @test + */ + public function returnTrueIfTwoNameAreEqual(): void + { + $name = new Name('something'); + + $this->assertTrue($name->equalTo(new Name('something'))); + } + + /** + * @test + */ + public function returnFalseIfTwoNameAreNotEqual(): void + { + $name = new Name('something'); + + $this->assertFalse($name->equalTo(new Name('anotherThing'))); + } +} From 7bb203162ecf41ef02df0aa4e9926bf36f1973cd Mon Sep 17 00:00:00 2001 From: Felipe Martins <6557756+fefas@users.noreply.github.com> Date: Wed, 12 May 2021 23:00:36 +0200 Subject: [PATCH 5/8] Rename variable and method --- src/Cli/Command.php | 2 +- src/Cli/Input.php | 8 ++++---- tests/Cli/InputTest.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Cli/Command.php b/src/Cli/Command.php index bc956aa..3b86bfe 100644 --- a/src/Cli/Command.php +++ b/src/Cli/Command.php @@ -35,7 +35,7 @@ public function execute(Input $input, Output $output): void public function match(Input $input): bool { - return $this->id->equalTo($input->commandId()); + return $this->id->equalTo($input->commandName()); } private function extractEntrypointAttributes(): void diff --git a/src/Cli/Input.php b/src/Cli/Input.php index 03cf11b..59e0f07 100644 --- a/src/Cli/Input.php +++ b/src/Cli/Input.php @@ -7,7 +7,7 @@ final class Input { private array $argv; - private Name $commandId; + private Name $commandName; private function __construct(string ...$rawInput) { @@ -25,13 +25,13 @@ public static function fromString(string $string): self return new self(...explode(' ', $string)); } - public function commandId(): Name + public function commandName(): Name { - return $this->commandId; + return $this->commandName; } private function parseInput(): void { - $this->commandId = new Name($this->argv[1]); + $this->commandName = new Name($this->argv[1]); } } diff --git a/tests/Cli/InputTest.php b/tests/Cli/InputTest.php index f9aff39..ca5e3c0 100644 --- a/tests/Cli/InputTest.php +++ b/tests/Cli/InputTest.php @@ -15,7 +15,7 @@ public function determineCommandIdFromArgv(): void $expected = new Name('command-id'); $input = Input::fromArgv('./bin/console', 'command-id'); - $commandId = $input->commandId(); + $commandId = $input->commandName(); $this->assertEquals($expected, $commandId); } From 012e1a28b4d8bb69797b627538c6b47c123703b2 Mon Sep 17 00:00:00 2001 From: Felipe Martins <6557756+fefas@users.noreply.github.com> Date: Wed, 12 May 2021 23:00:51 +0200 Subject: [PATCH 6/8] Remove unneeded code --- src/Cli/Processor/CommandCollection.php | 19 +------------------ tests/Cli/Processor/CommandCollectionTest.php | 15 --------------- 2 files changed, 1 insertion(+), 33 deletions(-) diff --git a/src/Cli/Processor/CommandCollection.php b/src/Cli/Processor/CommandCollection.php index 65dd3fd..1032816 100644 --- a/src/Cli/Processor/CommandCollection.php +++ b/src/Cli/Processor/CommandCollection.php @@ -2,24 +2,20 @@ namespace Bauhaus\Cli\Processor; -use ArrayIterator; use Bauhaus\Cli\Command; use Bauhaus\Cli\Entrypoint; use Bauhaus\Cli\Input; -use IteratorAggregate; /** * @internal */ -final class CommandCollection implements IteratorAggregate +final class CommandCollection { private array $commands; private function __construct(Command ...$commands) { $this->commands = $commands; - - $this->sort(); } public static function fromEntrypoints(Entrypoint ...$entrypoints): self @@ -32,11 +28,6 @@ public static function fromEntrypoints(Entrypoint ...$entrypoints): self return new self(...$commands); } - public function getIterator() - { - return new ArrayIterator($this->commands); - } - public function findMatch(Input $input): ?Command { foreach ($this->commands as $command) { @@ -47,12 +38,4 @@ public function findMatch(Input $input): ?Command return null; } - - private function sort(): void - { - usort( - $this->commands, - fn (Command $a, Command $b) => strcmp($a->id(), $b->id()), - ); - } } diff --git a/tests/Cli/Processor/CommandCollectionTest.php b/tests/Cli/Processor/CommandCollectionTest.php index dbe1c05..5ee54e5 100644 --- a/tests/Cli/Processor/CommandCollectionTest.php +++ b/tests/Cli/Processor/CommandCollectionTest.php @@ -53,19 +53,4 @@ public function returnCommandMatchingInput(string $rawInput, Command $expected): $this->assertEquals($expected, $command); } - - /** - * @test - */ - public function isIterableHavingCommandsOrderedByTheirId(): void - { - $expected = new ArrayIterator([ - Command::fromEntrypoint(new AnotherSampleEntrypoint()), - Command::fromEntrypoint(new SampleEntrypoint()), - ]); - - $iterator = $this->collection->getIterator(); - - $this->assertEquals($expected, $iterator); - } } From 3583a7b942b170023d0fb43720b3da4e6df98b98 Mon Sep 17 00:00:00 2001 From: Felipe Martins <6557756+fefas@users.noreply.github.com> Date: Wed, 12 May 2021 23:05:12 +0200 Subject: [PATCH 7/8] Fix merge problems --- src/Cli/Attribute/Name.php | 14 +++++++++++++- tests/Cli/InputTest.php | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Cli/Attribute/Name.php b/src/Cli/Attribute/Name.php index a08ed08..2a2cf85 100644 --- a/src/Cli/Attribute/Name.php +++ b/src/Cli/Attribute/Name.php @@ -10,6 +10,7 @@ final class Name public function __construct( private string $value, ) { + $this->assertIsValid(); } public function equalTo(self $that): bool @@ -21,4 +22,15 @@ public function __toString(): string { return $this->value; } -} + + private function assertIsValid(): void + { + $alphaNumeric = 'A-Za-z0-9'; + $allowed = "$alphaNumeric-_"; + $word = "[$alphaNumeric][$allowed]*"; + + if (0 === preg_match("/^$word(:$word)*$/", $this->value)) { + throw new InvalidArgument($this->value); + } + } +} \ No newline at end of file diff --git a/tests/Cli/InputTest.php b/tests/Cli/InputTest.php index f9aff39..ca5e3c0 100644 --- a/tests/Cli/InputTest.php +++ b/tests/Cli/InputTest.php @@ -15,7 +15,7 @@ public function determineCommandIdFromArgv(): void $expected = new Name('command-id'); $input = Input::fromArgv('./bin/console', 'command-id'); - $commandId = $input->commandId(); + $commandId = $input->commandName(); $this->assertEquals($expected, $commandId); } From fdb19e130e22a1637be69a2d8ddb27a284351cf7 Mon Sep 17 00:00:00 2001 From: Felipe Martins <6557756+fefas@users.noreply.github.com> Date: Wed, 12 May 2021 23:05:50 +0200 Subject: [PATCH 8/8] Fix CS --- src/Cli/Attribute/Name.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/Attribute/Name.php b/src/Cli/Attribute/Name.php index 2a2cf85..18e150d 100644 --- a/src/Cli/Attribute/Name.php +++ b/src/Cli/Attribute/Name.php @@ -33,4 +33,4 @@ private function assertIsValid(): void throw new InvalidArgument($this->value); } } -} \ No newline at end of file +}