From bd02f0a7d3f0cf6eed5ee18454fa34728ade996c Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Tue, 17 Oct 2023 14:27:06 +0300 Subject: [PATCH 1/3] Change console command name --- src/Prototype/src/Bootloader/PrototypeBootloader.php | 2 +- .../src/Command/{ListCommand.php => UsageCommand.php} | 4 ++-- .../{ListCommandTest.php => UsageCommandTest.php} | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) rename src/Prototype/src/Command/{ListCommand.php => UsageCommand.php} (89%) rename src/Prototype/tests/Commands/{ListCommandTest.php => UsageCommandTest.php} (82%) diff --git a/src/Prototype/src/Bootloader/PrototypeBootloader.php b/src/Prototype/src/Bootloader/PrototypeBootloader.php index ea1ddfebf..0f9f40d16 100644 --- a/src/Prototype/src/Bootloader/PrototypeBootloader.php +++ b/src/Prototype/src/Bootloader/PrototypeBootloader.php @@ -79,7 +79,7 @@ public function __construct( public function init(ConsoleBootloader $console): void { $console->addCommand(Command\DumpCommand::class); - $console->addCommand(Command\ListCommand::class); + $console->addCommand(Command\UsageCommand::class); $console->addCommand(Command\InjectCommand::class); $console->addConfigureSequence( diff --git a/src/Prototype/src/Command/ListCommand.php b/src/Prototype/src/Command/UsageCommand.php similarity index 89% rename from src/Prototype/src/Command/ListCommand.php rename to src/Prototype/src/Command/UsageCommand.php index ea7ee333b..66f64057e 100644 --- a/src/Prototype/src/Command/ListCommand.php +++ b/src/Prototype/src/Command/UsageCommand.php @@ -4,9 +4,9 @@ namespace Spiral\Prototype\Command; -final class ListCommand extends AbstractCommand +final class UsageCommand extends AbstractCommand { - public const NAME = 'prototype:list'; + public const NAME = 'prototype:usage'; public const DESCRIPTION = 'List all prototyped classes'; /** diff --git a/src/Prototype/tests/Commands/ListCommandTest.php b/src/Prototype/tests/Commands/UsageCommandTest.php similarity index 82% rename from src/Prototype/tests/Commands/ListCommandTest.php rename to src/Prototype/tests/Commands/UsageCommandTest.php index 5a7f674a8..11b920d83 100644 --- a/src/Prototype/tests/Commands/ListCommandTest.php +++ b/src/Prototype/tests/Commands/UsageCommandTest.php @@ -9,7 +9,7 @@ use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; -class ListCommandTest extends AbstractCommandsTestCase +class UsageCommandTest extends AbstractCommandsTestCase { public function testList(): void { @@ -19,7 +19,7 @@ public function testList(): void $result = $out->fetch(); - $this->assertStringContainsString('prototype:list', $result); + $this->assertStringContainsString('prototype:usage', $result); $this->assertStringContainsString('prototype:inject', $result); } @@ -27,7 +27,7 @@ public function testPrototypes(): void { $inp = new ArrayInput([]); $out = new BufferedOutput(); - $this->app->get(Console::class)->run('prototype:list', $inp, $out); + $this->app->get(Console::class)->run('prototype:usage', $inp, $out); $result = $out->fetch(); @@ -41,7 +41,7 @@ public function testPrototypesBound(): void $inp = new ArrayInput([]); $out = new BufferedOutput(); - $this->app->get(Console::class)->run('prototype:list', $inp, $out); + $this->app->get(Console::class)->run('prototype:usage', $inp, $out); $result = $out->fetch(); @@ -57,7 +57,7 @@ public function testPrototypesBoundWithoutResolve(): void $inp = new ArrayInput([]); $out = new BufferedOutput(); - $this->app->get(Console::class)->run('prototype:list', $inp, $out); + $this->app->get(Console::class)->run('prototype:usage', $inp, $out); $result = $out->fetch(); From e7dbfa51ae034f5f3dd3281371bd2d4a04c3afd3 Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Tue, 17 Oct 2023 15:47:47 +0300 Subject: [PATCH 2/3] Add cli command for listing prototype dependencies --- .../src/Bootloader/PrototypeBootloader.php | 1 + src/Prototype/src/Command/ListCommand.php | 31 ++++++ .../tests/Commands/InjectCommandTest.php | 10 ++ .../tests/Commands/ListCommandTest.php | 98 +++++++++++++++++++ .../tests/Commands/UsageCommandTest.php | 6 +- 5 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 src/Prototype/src/Command/ListCommand.php create mode 100644 src/Prototype/tests/Commands/ListCommandTest.php diff --git a/src/Prototype/src/Bootloader/PrototypeBootloader.php b/src/Prototype/src/Bootloader/PrototypeBootloader.php index 0f9f40d16..ddba47686 100644 --- a/src/Prototype/src/Bootloader/PrototypeBootloader.php +++ b/src/Prototype/src/Bootloader/PrototypeBootloader.php @@ -79,6 +79,7 @@ public function __construct( public function init(ConsoleBootloader $console): void { $console->addCommand(Command\DumpCommand::class); + $console->addCommand(Command\ListCommand::class); $console->addCommand(Command\UsageCommand::class); $console->addCommand(Command\InjectCommand::class); diff --git a/src/Prototype/src/Command/ListCommand.php b/src/Prototype/src/Command/ListCommand.php new file mode 100644 index 000000000..bcae5f706 --- /dev/null +++ b/src/Prototype/src/Command/ListCommand.php @@ -0,0 +1,31 @@ +registry->getPropertyBindings(); + if ($bindings === []) { + $this->comment('No prototype dependencies found.'); + + return self::SUCCESS; + } + + $grid = $this->table(['Name:', 'Target:']); + + foreach ($bindings as $binding) { + $grid->addRow([$binding->property, $binding->type->name()]); + } + + $grid->render(); + + return self::SUCCESS; + } +} diff --git a/src/Prototype/tests/Commands/InjectCommandTest.php b/src/Prototype/tests/Commands/InjectCommandTest.php index fcfbefdb9..1577908a9 100644 --- a/src/Prototype/tests/Commands/InjectCommandTest.php +++ b/src/Prototype/tests/Commands/InjectCommandTest.php @@ -16,6 +16,16 @@ class InjectCommandTest extends AbstractCommandsTestCase { + public function testCommandRegistered(): void + { + $out = new BufferedOutput(); + $this->app->get(Console::class)->run('list', new ArrayInput([]), $out); + + $result = $out->fetch(); + + $this->assertStringContainsString('prototype:inject', $result); + } + public function testEmptyInjection(): void { $target = EmptyInjectionClass::class; diff --git a/src/Prototype/tests/Commands/ListCommandTest.php b/src/Prototype/tests/Commands/ListCommandTest.php new file mode 100644 index 000000000..d12bb6956 --- /dev/null +++ b/src/Prototype/tests/Commands/ListCommandTest.php @@ -0,0 +1,98 @@ +app->get(Console::class)->run('list', new ArrayInput([]), $out); + + $result = $out->fetch(); + + $this->assertStringContainsString('prototype:list', $result); + } + + public function testList(): void + { + $out = new BufferedOutput(); + $this->app->get(Console::class)->run('prototype:list', new ArrayInput([]), $out); + + $result = $out->fetch(); + + $this->assertStringContainsString('app', $result); + $this->assertStringContainsString(TestApp::class, $result); + $this->assertStringContainsString('classLocator', $result); + $this->assertStringContainsString(\Spiral\Tokenizer\ClassesInterface::class, $result); + $this->assertStringContainsString('console', $result); + $this->assertStringContainsString(\Spiral\Console\Console::class, $result); + $this->assertStringContainsString('broadcast', $result); + $this->assertStringContainsString(\Spiral\Broadcasting\BroadcastInterface::class, $result); + $this->assertStringContainsString('container', $result); + $this->assertStringContainsString(\Psr\Container\ContainerInterface::class, $result); + $this->assertStringContainsString('encrypter', $result); + $this->assertStringContainsString(\Spiral\Encrypter\EncrypterInterface::class, $result); + $this->assertStringContainsString('env', $result); + $this->assertStringContainsString(\Spiral\Boot\EnvironmentInterface::class, $result); + $this->assertStringContainsString('files', $result); + $this->assertStringContainsString(\Spiral\Files\FilesInterface::class, $result); + $this->assertStringContainsString('guard', $result); + $this->assertStringContainsString(\Spiral\Security\GuardInterface::class, $result); + $this->assertStringContainsString('http', $result); + $this->assertStringContainsString(\Spiral\Http\Http::class, $result); + $this->assertStringContainsString('i18n', $result); + $this->assertStringContainsString(\Spiral\Translator\TranslatorInterface::class, $result); + $this->assertStringContainsString('input', $result); + $this->assertStringContainsString(\Spiral\Http\Request\InputManager::class, $result); + $this->assertStringContainsString('session', $result); + $this->assertStringContainsString(\Spiral\Session\SessionScope::class, $result); + $this->assertStringContainsString('cookies', $result); + $this->assertStringContainsString(\Spiral\Cookies\CookieManager::class, $result); + $this->assertStringContainsString('logger', $result); + $this->assertStringContainsString(\Psr\Log\LoggerInterface::class, $result); + $this->assertStringContainsString('logs', $result); + $this->assertStringContainsString(\Spiral\Logger\LogsInterface::class, $result); + $this->assertStringContainsString('memory', $result); + $this->assertStringContainsString(\Spiral\Boot\MemoryInterface::class, $result); + $this->assertStringContainsString('paginators', $result); + $this->assertStringContainsString(\Spiral\Pagination\PaginationProviderInterface::class, $result); + $this->assertStringContainsString('queue', $result); + $this->assertStringContainsString(\Spiral\Queue\QueueInterface::class, $result); + $this->assertStringContainsString('queueManager', $result); + $this->assertStringContainsString(\Spiral\Queue\QueueConnectionProviderInterface::class, $result); + $this->assertStringContainsString('request', $result); + $this->assertStringContainsString(\Spiral\Http\Request\InputManager::class, $result); + $this->assertStringContainsString('response', $result); + $this->assertStringContainsString(\Spiral\Http\ResponseWrapper::class, $result); + $this->assertStringContainsString('router', $result); + $this->assertStringContainsString(\Spiral\Router\RouterInterface::class, $result); + $this->assertStringContainsString('snapshots', $result); + $this->assertStringContainsString(\Spiral\Snapshots\SnapshotterInterface::class, $result); + $this->assertStringContainsString('storage', $result); + $this->assertStringContainsString(\Spiral\Storage\BucketInterface::class, $result); + $this->assertStringContainsString('serializer', $result); + $this->assertStringContainsString(\Spiral\Serializer\SerializerManager::class, $result); + $this->assertStringContainsString('validator', $result); + $this->assertStringContainsString(\Spiral\Validation\ValidationInterface::class, $result); + $this->assertStringContainsString('views', $result); + $this->assertStringContainsString(\Spiral\Views\ViewsInterface::class, $result); + $this->assertStringContainsString('auth', $result); + $this->assertStringContainsString(\Spiral\Auth\AuthScope::class, $result); + $this->assertStringContainsString('authTokens', $result); + $this->assertStringContainsString(\Spiral\Auth\TokenStorageInterface::class, $result); + $this->assertStringContainsString('cache', $result); + $this->assertStringContainsString(\Psr\SimpleCache\CacheInterface::class, $result); + $this->assertStringContainsString('cacheManager', $result); + $this->assertStringContainsString(\Spiral\Cache\CacheStorageProviderInterface::class, $result); + $this->assertStringContainsString('exceptionHandler', $result); + $this->assertStringContainsString(\Spiral\Exceptions\ExceptionHandlerInterface::class, $result); + } +} diff --git a/src/Prototype/tests/Commands/UsageCommandTest.php b/src/Prototype/tests/Commands/UsageCommandTest.php index 11b920d83..cca71537e 100644 --- a/src/Prototype/tests/Commands/UsageCommandTest.php +++ b/src/Prototype/tests/Commands/UsageCommandTest.php @@ -11,16 +11,14 @@ class UsageCommandTest extends AbstractCommandsTestCase { - public function testList(): void + public function testCommandRegistered(): void { - $inp = new ArrayInput([]); $out = new BufferedOutput(); - $this->app->get(Console::class)->run('list', $inp, $out); + $this->app->get(Console::class)->run('list', new ArrayInput([]), $out); $result = $out->fetch(); $this->assertStringContainsString('prototype:usage', $result); - $this->assertStringContainsString('prototype:inject', $result); } public function testPrototypes(): void From f3bdaf8b7577b5ae906d7cf778ef2e14b46a79d1 Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Tue, 17 Oct 2023 15:59:07 +0300 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fabcd3c5b..dfc23ce9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - [spiral/monolog-bridge] Added the ability to configure the **Monolog** messages format via environment variable `MONOLOG_FORMAT`. - [spiral/translator] Added the ability to register additional locales directories. + - [spiral/prototype] Added console command `Spiral\Prototype\Command\ListCommand` for listing prototype dependencies. ## 3.8.4 - 2023-09-08