diff --git a/phel b/phel index a8e144c0..9b6c3764 100755 --- a/phel +++ b/phel @@ -1,26 +1,26 @@ #!/usr/bin/env php add($commandFactory->createExportCommand()); -$application->add($commandFactory->createFormatCommand()); -$application->add($commandFactory->createReplCommand()); -$application->add($commandFactory->createRunCommand()); -$application->add($commandFactory->createTestCommand()); +$application->add($commandFacade->getExportCommand()); +$application->add($commandFacade->getFormatCommand()); +$application->add($commandFacade->getReplCommand()); +$application->add($commandFacade->getRunCommand()); +$application->add($commandFacade->getTestCommand()); $application->run(); diff --git a/src/php/Command/CommandFacade.php b/src/php/Command/CommandFacade.php new file mode 100644 index 00000000..1ebea51a --- /dev/null +++ b/src/php/Command/CommandFacade.php @@ -0,0 +1,43 @@ +getFactory()->createReplCommand(); + } + + public function getRunCommand(): RunCommand + { + return $this->getFactory()->createRunCommand(); + } + + public function getTestCommand(): TestCommand + { + return $this->getFactory()->createTestCommand(); + } + + public function getFormatCommand(): FormatCommand + { + return $this->getFactory()->createFormatCommand(); + } + + public function getExportCommand(): ExportCommand + { + return $this->getFactory()->createExportCommand(); + } +} diff --git a/tests/php/Integration/Command/AbstractCommandTest.php b/tests/php/Integration/Command/AbstractCommandTest.php index 2359ae9e..554387f1 100644 --- a/tests/php/Integration/Command/AbstractCommandTest.php +++ b/tests/php/Integration/Command/AbstractCommandTest.php @@ -4,7 +4,7 @@ namespace PhelTest\Integration\Command; -use Phel\Command\CommandFactory; +use Phel\Command\CommandFacade; use Phel\Runtime\RuntimeSingleton; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; @@ -16,9 +16,9 @@ protected function setUp(): void RuntimeSingleton::reset(); } - protected function createCommandFactory(): CommandFactory + protected function createCommandFacade(): CommandFacade { - return new CommandFactory(); + return new CommandFacade(); } protected function stubOutput(): OutputInterface diff --git a/tests/php/Integration/Command/Export/ExportCommandTest.php b/tests/php/Integration/Command/Export/ExportCommandTest.php index 1401caf6..d2470eb5 100644 --- a/tests/php/Integration/Command/Export/ExportCommandTest.php +++ b/tests/php/Integration/Command/Export/ExportCommandTest.php @@ -19,8 +19,8 @@ public static function setUpBeforeClass(): void public function test_export_command_multiple(): void { $command = $this - ->createCommandFactory() - ->createExportCommand() + ->createCommandFacade() + ->getExportCommand() ->addRuntimePath('test-cmd-export-multiple\\', [__DIR__ . '/src/test-cmd-export-multiple/']); $this->expectOutputRegex('~Exported namespaces:~'); diff --git a/tests/php/Integration/Command/Format/FormatCommandTest.php b/tests/php/Integration/Command/Format/FormatCommandTest.php index f03b32aa..fbbcccc5 100644 --- a/tests/php/Integration/Command/Format/FormatCommandTest.php +++ b/tests/php/Integration/Command/Format/FormatCommandTest.php @@ -5,6 +5,7 @@ namespace PhelTest\Integration\Command\Format; use Gacela\Framework\Config; +use Phel\Command\Format\FormatCommand; use PhelTest\Integration\Command\AbstractCommandTest; use Symfony\Component\Console\Input\InputInterface; @@ -22,9 +23,7 @@ public function test_good_format(): void $path = self::FIXTURES_DIR . 'good-format.phel'; $oldContent = file_get_contents($path); - $command = $this - ->createCommandFactory() - ->createFormatCommand(); + $command = $this->getFormatCommand(); $this->expectOutputRegex('/No files were formatted+/s'); @@ -43,9 +42,7 @@ public function test_bad_format(): void $path = self::FIXTURES_DIR . 'bad-format.phel'; $oldContent = file_get_contents($path); - $command = $this - ->createCommandFactory() - ->createFormatCommand(); + $command = $this->getFormatCommand(); $this->expectOutputString(<<createCommandFacade()->getFormatCommand(); + } + private function stubInput(array $paths): InputInterface { $input = $this->createStub(InputInterface::class); diff --git a/tests/php/Integration/Command/Run/RunCommandTest.php b/tests/php/Integration/Command/Run/RunCommandTest.php index 001c1fe1..ccc55a75 100644 --- a/tests/php/Integration/Command/Run/RunCommandTest.php +++ b/tests/php/Integration/Command/Run/RunCommandTest.php @@ -5,6 +5,7 @@ namespace PhelTest\Integration\Command\Run; use Gacela\Framework\Config; +use Phel\Command\Run\RunCommand; use PhelTest\Integration\Command\AbstractCommandTest; use Symfony\Component\Console\Input\InputInterface; @@ -19,8 +20,7 @@ public function test_run_by_namespace(): void { $this->expectOutputRegex('~hello world~'); - $this->createCommandFactory() - ->createRunCommand() + $this->getRunCommand() ->addRuntimePath('test\\', [__DIR__ . '/Fixtures']) ->run( $this->stubInput('test\\test-script'), @@ -32,8 +32,7 @@ public function test_run_by_filename(): void { $this->expectOutputRegex('~hello world~'); - $this->createCommandFactory() - ->createRunCommand() + $this->getRunCommand() ->addRuntimePath('test\\', [__DIR__ . '/Fixtures']) ->run( $this->stubInput(__DIR__ . '/Fixtures/test-script.phel'), @@ -46,8 +45,7 @@ public function test_cannot_parse_file(): void $filename = __DIR__ . '/Fixtures/test-script-not-parsable.phel'; $this->expectOutputRegex(sprintf('~Cannot parse file: %s~', $filename)); - $this->createCommandFactory() - ->createRunCommand() + $this->getRunCommand() ->run($this->stubInput($filename), $this->stubOutput()); } @@ -56,8 +54,7 @@ public function test_cannot_read_file(): void $filename = __DIR__ . '/Fixtures/this-file-does-not-exist.phel'; $this->expectOutputRegex(sprintf('~Cannot load namespace: %s~', $filename)); - $this->createCommandFactory() - ->createRunCommand() + $this->getRunCommand() ->run($this->stubInput($filename), $this->stubOutput()); } @@ -66,11 +63,15 @@ public function test_file_without_ns(): void $filename = __DIR__ . '/Fixtures/test-script-without-ns.phel'; $this->expectOutputRegex(sprintf('~Cannot extract namespace from file: %s~', $filename)); - $this->createCommandFactory() - ->createRunCommand() + $this->getRunCommand() ->run($this->stubInput($filename), $this->stubOutput()); } + private function getRunCommand(): RunCommand + { + return $this->createCommandFacade()->getRunCommand(); + } + private function stubInput(string $path): InputInterface { $input = $this->createStub(InputInterface::class); diff --git a/tests/php/Integration/Command/Test/TestCommandTest.php b/tests/php/Integration/Command/Test/TestCommandTest.php index fb0e4ed7..bddfc671 100644 --- a/tests/php/Integration/Command/Test/TestCommandTest.php +++ b/tests/php/Integration/Command/Test/TestCommandTest.php @@ -5,6 +5,7 @@ namespace PhelTest\Integration\Command\Test; use Gacela\Framework\Config; +use Phel\Command\Test\TestCommand; use PhelTest\Integration\Command\AbstractCommandTest; use Symfony\Component\Console\Input\InputInterface; @@ -19,9 +20,7 @@ public function test_all_in_project(): void { $currentDir = __DIR__ . '/Fixtures/test-cmd-project-success/'; - $command = $this - ->createCommandFactory() - ->createTestCommand() + $command = $this->getTestCommand() ->addRuntimePath('test-cmd-project-success\\', [$currentDir]); $this->expectOutputRegex('/\.\..*/'); @@ -37,9 +36,7 @@ public function test_one_file_in_project(): void { $currentDir = __DIR__ . '/Fixtures/test-cmd-project-success/'; - $command = $this - ->createCommandFactory() - ->createTestCommand() + $command = $this->getTestCommand() ->addRuntimePath('test-cmd-project-success\\', [$currentDir]); $this->expectOutputRegex('/\..*/'); @@ -58,9 +55,7 @@ public function test_all_in_failed_project(): void { $currentDir = __DIR__ . '/Fixtures/test-cmd-project-failure/'; - $command = $this - ->createCommandFactory() - ->createTestCommand() + $command = $this->getTestCommand() ->addRuntimePath('test-cmd-project-failure\\', [$currentDir]); $this->expectOutputRegex('/E.*/'); @@ -72,6 +67,11 @@ public function test_all_in_failed_project(): void $command->run($this->stubInput([]), $this->stubOutput()); } + private function getTestCommand(): TestCommand + { + return $this->createCommandFacade()->getTestCommand(); + } + private function stubInput(array $paths): InputInterface { $input = $this->createStub(InputInterface::class);