From 0260e6c9ecbf16b581153042ad74135037fda671 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 1 Sep 2023 20:05:42 +0800 Subject: [PATCH 01/37] Implements `PromptsForMissingInput` (#4) Signed-off-by: Mior Muhammad Zaki --- src/Commands/Command.php | 4 +- src/Commands/Generator.php | 115 ++++++++++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 2 deletions(-) diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 1882aae..ab397aa 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -6,6 +6,7 @@ use Illuminate\Console\Concerns\ConfiguresPrompts; use Illuminate\Console\Concerns\HasParameters; use Illuminate\Console\Concerns\InteractsWithIO; +use Illuminate\Console\Concerns\PromptsForMissingInput; use Illuminate\Console\OutputStyle; use Illuminate\Console\View\Components\Factory; use Illuminate\Container\Container; @@ -20,7 +21,8 @@ abstract class Command extends \Symfony\Component\Console\Command\Command use CallsCommands, ConfiguresPrompts, HasParameters, - InteractsWithIO; + InteractsWithIO, + PromptsForMissingInput; /** * Canvas preset. diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 1607196..5d26e07 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -3,6 +3,7 @@ namespace Orchestra\Canvas\Core\Commands; use Illuminate\Console\Concerns\CreatesMatchingTest; +use Illuminate\Contracts\Console\PromptsForMissingInput; use Orchestra\Canvas\Core\CodeGenerator; use Orchestra\Canvas\Core\Contracts\GeneratesCodeListener; use Orchestra\Canvas\Core\GeneratesCode; @@ -15,7 +16,7 @@ * @property string|null $name * @property string|null $description */ -abstract class Generator extends Command implements GeneratesCodeListener +abstract class Generator extends Command implements GeneratesCodeListener, PromptsForMissingInput { use CodeGenerator; @@ -43,6 +44,96 @@ abstract class Generator extends Command implements GeneratesCodeListener */ protected string $processor = GeneratesCode::class; + /** + * Reserved names that cannot be used for generation. + * + * @var array + */ + protected array $reservedNames = [ + '__halt_compiler', + 'abstract', + 'and', + 'array', + 'as', + 'break', + 'callable', + 'case', + 'catch', + 'class', + 'clone', + 'const', + 'continue', + 'declare', + 'default', + 'die', + 'do', + 'echo', + 'else', + 'elseif', + 'empty', + 'enddeclare', + 'endfor', + 'endforeach', + 'endif', + 'endswitch', + 'endwhile', + 'enum', + 'eval', + 'exit', + 'extends', + 'false', + 'final', + 'finally', + 'fn', + 'for', + 'foreach', + 'function', + 'global', + 'goto', + 'if', + 'implements', + 'include', + 'include_once', + 'instanceof', + 'insteadof', + 'interface', + 'isset', + 'list', + 'match', + 'namespace', + 'new', + 'or', + 'print', + 'private', + 'protected', + 'public', + 'readonly', + 'require', + 'require_once', + 'return', + 'self', + 'static', + 'switch', + 'throw', + 'trait', + 'true', + 'try', + 'unset', + 'use', + 'var', + 'while', + 'xor', + 'yield', + '__CLASS__', + '__DIR__', + '__FILE__', + '__FUNCTION__', + '__LINE__', + '__METHOD__', + '__NAMESPACE__', + '__TRAIT__', + ]; + /** * Construct a new generator command. */ @@ -81,6 +172,15 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + // First we need to ensure that the given name is not a reserved word within the PHP + // language and that the class name will actually be valid. If it is not valid we + // can error now and prevent from polluting the filesystem using invalid files. + if ($this->isReservedName($name = $this->generatorName())) { + $this->components->error('The name "'.$name.'" is reserved by PHP.'); + + return Command::FAILURE; + } + $force = $this->hasOption('force') && $this->option('force') === true; return $this->generateCode($force); @@ -143,4 +243,17 @@ public function generatorName(): string return trim($name); }); } + + /** + * Checks whether the given name is reserved. + * + * @param string $name + * @return bool + */ + protected function isReservedName($name) + { + $name = strtolower($name); + + return in_array($name, $this->reservedNames); + } } From f300b8f9588bd3bbcccc5851580cf8bfb6b73a41 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 1 Sep 2023 20:05:42 +0800 Subject: [PATCH 02/37] Implements `PromptsForMissingInput` (#4) Signed-off-by: Mior Muhammad Zaki --- src/Commands/Command.php | 4 +- src/Commands/Generator.php | 115 ++++++++++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 2 deletions(-) diff --git a/src/Commands/Command.php b/src/Commands/Command.php index bcc6cb7..9d5a940 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -5,6 +5,7 @@ use Illuminate\Console\Concerns\CallsCommands; use Illuminate\Console\Concerns\HasParameters; use Illuminate\Console\Concerns\InteractsWithIO; +use Illuminate\Console\Concerns\PromptsForMissingInput; use Illuminate\Console\OutputStyle; use Orchestra\Canvas\Core\Presets\Preset; use Symfony\Component\Console\Command\Command as SymfonyConsole; @@ -15,7 +16,8 @@ abstract class Command extends \Symfony\Component\Console\Command\Command { use CallsCommands, HasParameters, - InteractsWithIO; + InteractsWithIO, + PromptsForMissingInput; /** * Canvas preset. diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 96d3690..31562c9 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -3,6 +3,7 @@ namespace Orchestra\Canvas\Core\Commands; use Illuminate\Console\Concerns\CreatesMatchingTest; +use Illuminate\Contracts\Console\PromptsForMissingInput; use Orchestra\Canvas\Core\CodeGenerator; use Orchestra\Canvas\Core\Contracts\GeneratesCodeListener; use Orchestra\Canvas\Core\GeneratesCode; @@ -15,7 +16,7 @@ * @property string $name * @property string $description */ -abstract class Generator extends Command implements GeneratesCodeListener +abstract class Generator extends Command implements GeneratesCodeListener, PromptsForMissingInput { use CodeGenerator; @@ -47,6 +48,96 @@ abstract class Generator extends Command implements GeneratesCodeListener */ protected string $processor = GeneratesCode::class; + /** + * Reserved names that cannot be used for generation. + * + * @var array + */ + protected array $reservedNames = [ + '__halt_compiler', + 'abstract', + 'and', + 'array', + 'as', + 'break', + 'callable', + 'case', + 'catch', + 'class', + 'clone', + 'const', + 'continue', + 'declare', + 'default', + 'die', + 'do', + 'echo', + 'else', + 'elseif', + 'empty', + 'enddeclare', + 'endfor', + 'endforeach', + 'endif', + 'endswitch', + 'endwhile', + 'enum', + 'eval', + 'exit', + 'extends', + 'false', + 'final', + 'finally', + 'fn', + 'for', + 'foreach', + 'function', + 'global', + 'goto', + 'if', + 'implements', + 'include', + 'include_once', + 'instanceof', + 'insteadof', + 'interface', + 'isset', + 'list', + 'match', + 'namespace', + 'new', + 'or', + 'print', + 'private', + 'protected', + 'public', + 'readonly', + 'require', + 'require_once', + 'return', + 'self', + 'static', + 'switch', + 'throw', + 'trait', + 'true', + 'try', + 'unset', + 'use', + 'var', + 'while', + 'xor', + 'yield', + '__CLASS__', + '__DIR__', + '__FILE__', + '__FUNCTION__', + '__LINE__', + '__METHOD__', + '__NAMESPACE__', + '__TRAIT__', + ]; + /** * Construct a new generator command. */ @@ -85,6 +176,15 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + // First we need to ensure that the given name is not a reserved word within the PHP + // language and that the class name will actually be valid. If it is not valid we + // can error now and prevent from polluting the filesystem using invalid files. + if ($this->isReservedName($name = $this->generatorName())) { + $this->components->error('The name "'.$name.'" is reserved by PHP.'); + + return Command::FAILURE; + } + $force = $this->hasOption('force') && $this->option('force') === true; return $this->generateCode($force); @@ -148,4 +248,17 @@ public function generatorName(): string return trim($name); }); } + + /** + * Checks whether the given name is reserved. + * + * @param string $name + * @return bool + */ + protected function isReservedName($name) + { + $name = strtolower($name); + + return in_array($name, $this->reservedNames); + } } From 0df006765b297fa8f27f7a493ebd01e87c051c97 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 1 Sep 2023 20:07:41 +0800 Subject: [PATCH 03/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Command.php | 2 -- src/Commands/Generator.php | 11 ++--------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 9d5a940..ee4840a 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -40,8 +40,6 @@ public function __construct(Preset $preset) /** * Run the console command. - * - * @return int */ public function run(InputInterface $input, OutputInterface $output): int { diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 31562c9..82f4498 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -29,15 +29,11 @@ abstract class Generator extends Command implements GeneratesCodeListener, Promp /** * The type of class being generated. - * - * @var string */ protected string $type; /** * The type of file being generated. - * - * @var string */ protected string $fileType = 'class'; @@ -251,14 +247,11 @@ public function generatorName(): string /** * Checks whether the given name is reserved. - * - * @param string $name - * @return bool */ - protected function isReservedName($name) + protected function isReservedName(string $name): bool { $name = strtolower($name); - return in_array($name, $this->reservedNames); + return \in_array($name, $this->reservedNames); } } From fb44e9fdc01c4dd82198f859e5e775f492c5b657 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 11:43:33 +0800 Subject: [PATCH 04/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Presets/Package.php | 2 +- src/Presets/Preset.php | 1 + tests/Unit/Presets/PackageTest.php | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Presets/Package.php b/src/Presets/Package.php index ebb4b85..3422f6a 100644 --- a/src/Presets/Package.php +++ b/src/Presets/Package.php @@ -88,7 +88,7 @@ public function providerNamespace(): string */ public function getCustomStubPath(): ?string { - return null; + return sprintf('%s/stubs', $this->basePath()); } /** diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php index e9c4e31..9081f49 100644 --- a/src/Presets/Preset.php +++ b/src/Presets/Preset.php @@ -18,6 +18,7 @@ public function __construct( protected string $basePath, protected Filesystem $files ) { + // } /** diff --git a/tests/Unit/Presets/PackageTest.php b/tests/Unit/Presets/PackageTest.php index 2589fd8..ff83bed 100644 --- a/tests/Unit/Presets/PackageTest.php +++ b/tests/Unit/Presets/PackageTest.php @@ -35,8 +35,8 @@ public function it_has_proper_signatures() $this->assertSame("{$directory}/database/migrations", $preset->migrationPath()); $this->assertSame("{$directory}/database/seeders", $preset->seederPath()); - $this->assertFalse($preset->hasCustomStubPath()); - $this->assertNull($preset->getCustomStubPath()); + $this->assertTrue($preset->hasCustomStubPath()); + $this->assertSame("{$directory}/stubs", $preset->getCustomStubPath()); $this->assertSame($files, $preset->filesystem()); } From 4a95bcf20b52979777d8cf244f96e34d0e38f5f3 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 11:44:28 +0800 Subject: [PATCH 05/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Generator.php | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 5d26e07..d62794e 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -250,10 +250,50 @@ public function generatorName(): string * @param string $name * @return bool */ - protected function isReservedName($name) + protected function isReservedName(string $name): bool { $name = strtolower($name); return in_array($name, $this->reservedNames); } + + /** + * Prompt for missing input arguments using the returned questions. + * + * @return array + */ + protected function promptForMissingArgumentsUsing() + { + return [ + 'name' => [ + 'What should the '.strtolower($this->type).' be named?', + match ($this->type) { + 'Cast' => 'E.g. Json', + 'Channel' => 'E.g. OrderChannel', + 'Console command' => 'E.g. SendEmails', + 'Component' => 'E.g. Alert', + 'Controller' => 'E.g. UserController', + 'Event' => 'E.g. PodcastProcessed', + 'Exception' => 'E.g. InvalidOrderException', + 'Factory' => 'E.g. PostFactory', + 'Job' => 'E.g. ProcessPodcast', + 'Listener' => 'E.g. SendPodcastNotification', + 'Mailable' => 'E.g. OrderShipped', + 'Middleware' => 'E.g. EnsureTokenIsValid', + 'Model' => 'E.g. Flight', + 'Notification' => 'E.g. InvoicePaid', + 'Observer' => 'E.g. UserObserver', + 'Policy' => 'E.g. PostPolicy', + 'Provider' => 'E.g. ElasticServiceProvider', + 'Request' => 'E.g. StorePodcastRequest', + 'Resource' => 'E.g. UserResource', + 'Rule' => 'E.g. Uppercase', + 'Scope' => 'E.g. TrendingScope', + 'Seeder' => 'E.g. UserSeeder', + 'Test' => 'E.g. UserTest', + default => '', + }, + ], + ]; + } } From 2cd3e9f036a9aeaf3eb87627392e589aa2fd7039 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 11:48:33 +0800 Subject: [PATCH 06/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Generator.php | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index d62794e..12459fe 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -11,6 +11,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Finder\Finder; /** * @property string|null $name @@ -257,6 +258,44 @@ protected function isReservedName(string $name): bool return in_array($name, $this->reservedNames); } + /** + * Get a list of possible model names. + * + * @return array + */ + protected function possibleModels() + { + $sourcePath = $this->preset->sourcePath(); + + $modelPath = is_dir("{$sourcePath}/Models") ? "{$sourcePath}/Models" : $sourcePath; + + return collect((new Finder)->files()->depth(0)->in($modelPath)) + ->map(fn ($file) => $file->getBasename('.php')) + ->sort() + ->values() + ->all(); + } + + /** + * Get a list of possible event names. + * + * @return array + */ + protected function possibleEvents() + { + $eventPath = sprintf('%s/Events', $this->preset->sourcePath()); + + if (! is_dir($eventPath)) { + return []; + } + + return collect((new Finder)->files()->depth(0)->in($eventPath)) + ->map(fn ($file) => $file->getBasename('.php')) + ->sort() + ->values() + ->all(); + } + /** * Prompt for missing input arguments using the returned questions. * From 7dc25f114d683e2e0e0dbc4a2af4e0a3017217b7 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 16:38:51 +0800 Subject: [PATCH 07/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Command.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Commands/Command.php b/src/Commands/Command.php index ee4840a..3c11509 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -7,6 +7,7 @@ use Illuminate\Console\Concerns\InteractsWithIO; use Illuminate\Console\Concerns\PromptsForMissingInput; use Illuminate\Console\OutputStyle; +use Illuminate\Console\View\Components\Factory; use Orchestra\Canvas\Core\Presets\Preset; use Symfony\Component\Console\Command\Command as SymfonyConsole; use Symfony\Component\Console\Input\InputInterface; @@ -37,6 +38,18 @@ public function __construct(Preset $preset) $this->specifyParameters(); } + /** + * Initializes the command after the input has been bound and before the input + * is validated. + * + * @return void + * + * @phpstan-param \Symfony\Component\Console\Output\OutputInterface&\Illuminate\Console\OutputStyle $output + */ + protected function initialize(InputInterface $input, OutputInterface $output) + { + $this->components = new Factory($output); + } /** * Run the console command. From 648f9805b8092ee238aedf12bf4903fb96168b66 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 16:47:41 +0800 Subject: [PATCH 08/37] wip Signed-off-by: Mior Muhammad Zaki --- src/CodeGenerator.php | 4 +--- src/Commands/Command.php | 19 +++++++++++++++++-- src/Commands/Generator.php | 4 ++-- src/Contracts/GeneratesCodeListener.php | 4 ---- src/GeneratesCode.php | 2 -- src/Presets/Preset.php | 1 - 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/CodeGenerator.php b/src/CodeGenerator.php index f48279e..1f8c23c 100644 --- a/src/CodeGenerator.php +++ b/src/CodeGenerator.php @@ -25,8 +25,6 @@ public function setPreset(Presets\Preset $preset) /** * Generate code. - * - * @return mixed */ public function generateCode(bool $force = false) { @@ -60,7 +58,7 @@ public function getDefaultNamespace(string $rootNamespace): string /** * Generator options. * - * @return array + * @return array{name: string} */ public function generatorOptions(): array { diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 3c11509..90bd635 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -8,7 +8,9 @@ use Illuminate\Console\Concerns\PromptsForMissingInput; use Illuminate\Console\OutputStyle; use Illuminate\Console\View\Components\Factory; +use Illuminate\Container\Container; use Orchestra\Canvas\Core\Presets\Preset; +use Orchestra\Testbench\Foundation\Application as Testbench; use Symfony\Component\Console\Command\Command as SymfonyConsole; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -27,6 +29,13 @@ abstract class Command extends \Symfony\Component\Console\Command\Command */ protected $preset; + /** + * The Laravel application instance. + * + * @var \Illuminate\Contracts\Foundation\Application + */ + protected $laravel; + /** * Construct a new generator command. */ @@ -38,6 +47,7 @@ public function __construct(Preset $preset) $this->specifyParameters(); } + /** * Initializes the command after the input has been bound and before the input * is validated. @@ -56,10 +66,15 @@ protected function initialize(InputInterface $input, OutputInterface $output) */ public function run(InputInterface $input, OutputInterface $output): int { - $this->output = new OutputStyle($input, $output); + $container = Container::getInstance(); + + $this->laravel = $container->bound('app') + ? $container->get('app') + : Testbench::create(basePath: $this->preset->laravelPath()); return parent::run( - $this->input = $input, $this->output + $this->input = $input, + $this->output = new OutputStyle($input, $output) ); } diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 82f4498..e45eb85 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -13,8 +13,8 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * @property string $name - * @property string $description + * @property string|null $name + * @property string|null $description */ abstract class Generator extends Command implements GeneratesCodeListener, PromptsForMissingInput { diff --git a/src/Contracts/GeneratesCodeListener.php b/src/Contracts/GeneratesCodeListener.php index b808675..7ca882f 100644 --- a/src/Contracts/GeneratesCodeListener.php +++ b/src/Contracts/GeneratesCodeListener.php @@ -6,8 +6,6 @@ interface GeneratesCodeListener { /** * Code already exists. - * - * @return mixed */ public function codeAlreadyExists(string $className); @@ -18,8 +16,6 @@ public function generatingCode(string $stub, string $className): string; /** * Code successfully generated. - * - * @return mixed */ public function codeHasBeenGenerated(string $className); diff --git a/src/GeneratesCode.php b/src/GeneratesCode.php index 10afd79..82c316c 100644 --- a/src/GeneratesCode.php +++ b/src/GeneratesCode.php @@ -34,8 +34,6 @@ public function __construct( /** * Execute generates code processor. - * - * @return mixed */ public function __invoke(bool $force = false) { diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php index 0ba7367..c6383c9 100644 --- a/src/Presets/Preset.php +++ b/src/Presets/Preset.php @@ -32,7 +32,6 @@ public function is(string $name): bool * Get configuration. * * @param mixed|null $default - * @return mixed */ public function config(?string $key = null, $default = null) { From 1feb328ccfac841b56f5999aa5d118bfccfa19a9 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 16:50:12 +0800 Subject: [PATCH 09/37] wip Signed-off-by: Mior Muhammad Zaki --- src/LaravelServiceProvider.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/LaravelServiceProvider.php b/src/LaravelServiceProvider.php index 7658a11..eba91ac 100644 --- a/src/LaravelServiceProvider.php +++ b/src/LaravelServiceProvider.php @@ -12,8 +12,6 @@ class LaravelServiceProvider extends ServiceProvider implements DeferrableProvid /** * Register services. - * - * @return void */ public function register(): void { From 007de95880bd8c502f3df7095b6ca4b5e6e32aee Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 16:55:37 +0800 Subject: [PATCH 10/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Command.php | 10 ++++++++++ src/Commands/Generator.php | 7 ++++--- src/LaravelServiceProvider.php | 6 ++---- src/Presets/Laravel.php | 8 ++++++++ src/Presets/Package.php | 10 +++++++++- src/Presets/Preset.php | 6 ++++++ tests/Unit/Presets/PackageTest.php | 4 ++-- 7 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 90bd635..a6bc19f 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -92,4 +92,14 @@ protected function resolveCommand($command) : $command ); } + + /** + * Get the Laravel application instance. + * + * @return \Illuminate\Contracts\Foundation\Application + */ + public function getLaravel() + { + return $this->laravel; + } } diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index e45eb85..48d0ad8 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -199,7 +199,7 @@ public function generatingCode(string $stub, string $className): string */ public function codeAlreadyExists(string $className): int { - $this->error($this->type.' already exists!'); + $this->components->error(sprintf('%s [%s] already exists!', $this->type, $className)); return 1; } @@ -209,7 +209,7 @@ public function codeAlreadyExists(string $className): int */ public function codeHasBeenGenerated(string $className): int { - $this->info($this->type.' created successfully.'); + $this->components->info(sprintf('%s [%s] created successfully.', $this->type, $className)); return 0; } @@ -240,7 +240,8 @@ public function getPublishedStubFileName(): ?string */ public function generatorName(): string { - return transform($this->argument('name'), function (string $name) { + return transform($this->argument('name'), function ($name) { + /** @var string $name */ return trim($name); }); } diff --git a/src/LaravelServiceProvider.php b/src/LaravelServiceProvider.php index 363b9b8..6e446a9 100644 --- a/src/LaravelServiceProvider.php +++ b/src/LaravelServiceProvider.php @@ -17,15 +17,13 @@ class LaravelServiceProvider extends ServiceProvider implements DeferrableProvid */ public function register() { - $this->app->singleton(Presets\Preset::class, function (Container $app) { - return $this->presetForLaravel($app); - }); + $this->app->singleton(Presets\Preset::class, fn (Container $app) => $this->presetForLaravel($app)); } /** * Get the services provided by the provider. * - * @return array + * @return array */ public function provides() { diff --git a/src/Presets/Laravel.php b/src/Presets/Laravel.php index ec059dc..808e0ac 100644 --- a/src/Presets/Laravel.php +++ b/src/Presets/Laravel.php @@ -32,6 +32,14 @@ public function name(): string return 'laravel'; } + /** + * Get the path to the base working directory. + */ + public function laravelPath(): string + { + return $this->basePath(); + } + /** * Get the path to the source directory. */ diff --git a/src/Presets/Package.php b/src/Presets/Package.php index 1ca3dcc..3422f6a 100644 --- a/src/Presets/Package.php +++ b/src/Presets/Package.php @@ -33,6 +33,14 @@ public function name(): string return 'package'; } + /** + * Get the path to the base working directory. + */ + public function laravelPath(): string + { + return sprintf('%s/orchestra/testbench-core/laravel', $this->vendorPath()); + } + /** * Get the path to the source directory. */ @@ -80,7 +88,7 @@ public function providerNamespace(): string */ public function getCustomStubPath(): ?string { - return null; + return sprintf('%s/stubs', $this->basePath()); } /** diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php index c6383c9..933b04a 100644 --- a/src/Presets/Preset.php +++ b/src/Presets/Preset.php @@ -18,6 +18,7 @@ public function __construct( protected string $basePath, protected Filesystem $files ) { + // } /** @@ -156,6 +157,11 @@ public function hasCustomStubPath(): bool */ abstract public function name(): string; + /** + * Get the path to the base working directory. + */ + abstract public function laravelPath(): string; + /** * Get the path to the source directory. */ diff --git a/tests/Unit/Presets/PackageTest.php b/tests/Unit/Presets/PackageTest.php index b92ba0d..6431d4f 100644 --- a/tests/Unit/Presets/PackageTest.php +++ b/tests/Unit/Presets/PackageTest.php @@ -33,8 +33,8 @@ public function it_has_proper_signatures() $this->assertSame("{$directory}/database/migrations", $preset->migrationPath()); $this->assertSame("{$directory}/database/seeders", $preset->seederPath()); - $this->assertFalse($preset->hasCustomStubPath()); - $this->assertNull($preset->getCustomStubPath()); + $this->assertTrue($preset->hasCustomStubPath()); + $this->assertSame("{$directory}/stubs", $preset->getCustomStubPath()); $this->assertSame($files, $preset->filesystem()); } From 3bf7e1340f26a7363450d4d054b99445ed8f3036 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 16:56:27 +0800 Subject: [PATCH 11/37] wip Signed-off-by: Mior Muhammad Zaki --- .gitattributes | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 3686d80..697e507 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,7 +5,6 @@ /tests export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/.phpunit.cache export-ignore /phpstan-baseline.neon export-ignore /phpstan.neon.dist export-ignore /phpunit.xml export-ignore From be8c050b62affba754b88f3f13f1a1ebf12a5638 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 17:06:01 +0800 Subject: [PATCH 12/37] wip Signed-off-by: Mior Muhammad Zaki --- src/CodeGenerator.php | 14 ++++++++++++-- src/Contracts/GeneratesCodeListener.php | 4 ++++ src/GeneratesCode.php | 2 ++ src/Presets/Preset.php | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/CodeGenerator.php b/src/CodeGenerator.php index 1f8c23c..6db941c 100644 --- a/src/CodeGenerator.php +++ b/src/CodeGenerator.php @@ -25,6 +25,8 @@ public function setPreset(Presets\Preset $preset) /** * Generate code. + * + * @return int */ public function generateCode(bool $force = false) { @@ -33,18 +35,26 @@ public function generateCode(bool $force = false) /** * Code already exists. + * + * @return int */ public function codeAlreadyExists(string $className) { - return false; + $this->components->error(sprintf('%s [%s] already exists!', $this->type, $className)); + + return 1; } /** * Code successfully generated. + * + * @return int */ public function codeHasBeenGenerated(string $className) { - return true; + $this->components->info(sprintf('%s [%s] created successfully.', $this->type, $className)); + + return 0; } /** diff --git a/src/Contracts/GeneratesCodeListener.php b/src/Contracts/GeneratesCodeListener.php index 7ca882f..b808675 100644 --- a/src/Contracts/GeneratesCodeListener.php +++ b/src/Contracts/GeneratesCodeListener.php @@ -6,6 +6,8 @@ interface GeneratesCodeListener { /** * Code already exists. + * + * @return mixed */ public function codeAlreadyExists(string $className); @@ -16,6 +18,8 @@ public function generatingCode(string $stub, string $className): string; /** * Code successfully generated. + * + * @return mixed */ public function codeHasBeenGenerated(string $className); diff --git a/src/GeneratesCode.php b/src/GeneratesCode.php index 82c316c..2160801 100644 --- a/src/GeneratesCode.php +++ b/src/GeneratesCode.php @@ -34,6 +34,8 @@ public function __construct( /** * Execute generates code processor. + * + * @return int */ public function __invoke(bool $force = false) { diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php index 933b04a..9081f49 100644 --- a/src/Presets/Preset.php +++ b/src/Presets/Preset.php @@ -33,6 +33,7 @@ public function is(string $name): bool * Get configuration. * * @param mixed|null $default + * @return mixed */ public function config(?string $key = null, $default = null) { From 6f97fd92197de53576ddf6bda1f6241a0aa5ad83 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 17:12:54 +0800 Subject: [PATCH 13/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Generator.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 48d0ad8..19d1460 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -255,4 +255,16 @@ protected function isReservedName(string $name): bool return \in_array($name, $this->reservedNames); } + + /** + * Prompt for missing input arguments using the returned questions. + * + * @return array + */ + protected function promptForMissingArgumentsUsing() + { + return [ + 'name' => 'What should the '.strtolower($this->type).' be named?', + ]; + } } From 23c2470b75723181d3f9639defd6ab7dfcc56c74 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 17:19:14 +0800 Subject: [PATCH 14/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Generator.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 19d1460..44b3b17 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -194,26 +194,6 @@ public function generatingCode(string $stub, string $className): string return $stub; } - /** - * Code already exists. - */ - public function codeAlreadyExists(string $className): int - { - $this->components->error(sprintf('%s [%s] already exists!', $this->type, $className)); - - return 1; - } - - /** - * Code successfully generated. - */ - public function codeHasBeenGenerated(string $className): int - { - $this->components->info(sprintf('%s [%s] created successfully.', $this->type, $className)); - - return 0; - } - /** * Run after code successfully generated. * From afb959219aa0d2229bd72d662345d5e31ec5ba76 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 17:20:09 +0800 Subject: [PATCH 15/37] wip Signed-off-by: Mior Muhammad Zaki --- tests/Unit/Presets/LaravelTest.php | 2 ++ tests/Unit/Presets/PackageTest.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/Unit/Presets/LaravelTest.php b/tests/Unit/Presets/LaravelTest.php index 5cc8480..bf9e4a2 100644 --- a/tests/Unit/Presets/LaravelTest.php +++ b/tests/Unit/Presets/LaravelTest.php @@ -20,6 +20,7 @@ public function it_has_proper_signatures() $this->assertFalse($preset->is('package')); $this->assertSame($directory, $preset->basePath()); + $this->assertSame($preset->basePath(), $preset->laravelPath()); $this->assertSame('App', $preset->rootNamespace()); $this->assertSame('App\Models', $preset->modelNamespace()); @@ -28,6 +29,7 @@ public function it_has_proper_signatures() $this->assertSame('Database\Seeders', $preset->seederNamespace()); $this->assertSame("{$directory}/app", $preset->sourcePath()); + $this->assertSame("{$directory}/vendor", $preset->vendorPath()); $this->assertSame("{$directory}/resources", $preset->resourcePath()); $this->assertSame("{$directory}/database/factories", $preset->factoryPath()); $this->assertSame("{$directory}/database/migrations", $preset->migrationPath()); diff --git a/tests/Unit/Presets/PackageTest.php b/tests/Unit/Presets/PackageTest.php index 6431d4f..ff83bed 100644 --- a/tests/Unit/Presets/PackageTest.php +++ b/tests/Unit/Presets/PackageTest.php @@ -20,6 +20,7 @@ public function it_has_proper_signatures() $this->assertFalse($preset->is('laravel')); $this->assertSame($directory, $preset->basePath()); + $this->assertSame("{$directory}/vendor/orchestra/testbench-core/laravel", $preset->laravelPath()); $this->assertSame('FooBar', $preset->rootNamespace()); $this->assertSame('FooBar', $preset->modelNamespace()); @@ -28,6 +29,7 @@ public function it_has_proper_signatures() $this->assertSame('Database\Seeders', $preset->seederNamespace()); $this->assertSame("{$directory}/src", $preset->sourcePath()); + $this->assertSame("{$directory}/vendor", $preset->vendorPath()); $this->assertSame("{$directory}/resources", $preset->resourcePath()); $this->assertSame("{$directory}/database/factories", $preset->factoryPath()); $this->assertSame("{$directory}/database/migrations", $preset->migrationPath()); From 13ac05e610d5e4810a944b41736467af55256273 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 11 Sep 2023 21:03:33 +0800 Subject: [PATCH 16/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Generator.php | 4 ++-- src/TestGenerator.php | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/TestGenerator.php diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 44b3b17..d335fd7 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -18,7 +18,7 @@ */ abstract class Generator extends Command implements GeneratesCodeListener, PromptsForMissingInput { - use CodeGenerator; + use CodeGenerator, TestGenerator; /** * The filesystem instance. @@ -203,7 +203,7 @@ public function afterCodeHasBeenGenerated(string $className, string $path) { if (\in_array(CreatesMatchingTest::class, class_uses_recursive($this))) { /** @phpstan-ignore-next-line */ - $this->handleTestCreation($path); + $this->handleTestCreationUsingCanvas($path); } } diff --git a/src/TestGenerator.php b/src/TestGenerator.php new file mode 100644 index 0000000..6b7184e --- /dev/null +++ b/src/TestGenerator.php @@ -0,0 +1,24 @@ +option('test') && ! $this->option('pest')) { + return false; + } + + return $this->callSilent('make:test', [ + 'name' => Str::of($path)->after($this->preset->sourcePath())->beforeLast('.php')->append('Test')->replace('\\', '/'), + '--pest' => $this->option('pest'), + ]) == 0; + } +} From 710a81e3da551e9245b273af1df2f6a2d99105f5 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 11 Sep 2023 17:30:21 +0200 Subject: [PATCH 17/37] Update Generator.php (#5) Missing use --- src/Commands/Generator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 9dfd472..36e4b2a 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -5,6 +5,7 @@ use Illuminate\Console\Concerns\CreatesMatchingTest; use Illuminate\Contracts\Console\PromptsForMissingInput; use Orchestra\Canvas\Core\CodeGenerator; +use Orchestra\Canvas\Core\TestGenerator; use Orchestra\Canvas\Core\Contracts\GeneratesCodeListener; use Orchestra\Canvas\Core\GeneratesCode; use Orchestra\Canvas\Core\Presets\Preset; From af070da4f62c2bcbf659652d8a5afe3ccfb3ad2e Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 11 Sep 2023 23:33:16 +0200 Subject: [PATCH 18/37] Fix TestGenerator trait (#6) * Update TestGenerator.php Fix missing use directive * Update Generator.php --- src/Commands/Generator.php | 1 - src/TestGenerator.php | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 36e4b2a..6a581b3 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -202,7 +202,6 @@ public function generatingCode(string $stub, string $className): string public function afterCodeHasBeenGenerated(string $className, string $path): void { if (\in_array(CreatesMatchingTest::class, class_uses_recursive($this))) { - /** @phpstan-ignore-next-line */ $this->handleTestCreationUsingCanvas($path); } } diff --git a/src/TestGenerator.php b/src/TestGenerator.php index 6b7184e..64a0c1e 100644 --- a/src/TestGenerator.php +++ b/src/TestGenerator.php @@ -2,6 +2,8 @@ namespace Orchestra\Canvas\Core; +use Illuminate\Support\Str; + trait TestGenerator { /** @@ -17,7 +19,7 @@ protected function handleTestCreationUsingCanvas($path) } return $this->callSilent('make:test', [ - 'name' => Str::of($path)->after($this->preset->sourcePath())->beforeLast('.php')->append('Test')->replace('\\', '/'), + 'name' => Str::of($path)->after($this->preset->sourcePath())->beforeLast('.php')->append('Test')->replace('\\', '/'), '--pest' => $this->option('pest'), ]) == 0; } From 484f6c7b540d37f934d82148caf106050646b4db Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 12 Sep 2023 06:21:00 +0800 Subject: [PATCH 19/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Generator.php | 2 +- src/TestGenerator.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index d335fd7..83153d9 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -8,6 +8,7 @@ use Orchestra\Canvas\Core\Contracts\GeneratesCodeListener; use Orchestra\Canvas\Core\GeneratesCode; use Orchestra\Canvas\Core\Presets\Preset; +use Orchestra\Canvas\Core\TestGenerator; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -202,7 +203,6 @@ public function generatingCode(string $stub, string $className): string public function afterCodeHasBeenGenerated(string $className, string $path) { if (\in_array(CreatesMatchingTest::class, class_uses_recursive($this))) { - /** @phpstan-ignore-next-line */ $this->handleTestCreationUsingCanvas($path); } } diff --git a/src/TestGenerator.php b/src/TestGenerator.php index 6b7184e..8c7ca6a 100644 --- a/src/TestGenerator.php +++ b/src/TestGenerator.php @@ -2,6 +2,8 @@ namespace Orchestra\Canvas\Core; +use Illuminate\Support\Str; + trait TestGenerator { /** From 4ef0a53a69539ab17827e9fc7573d6db5f9ad3e0 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 12 Sep 2023 06:43:20 +0800 Subject: [PATCH 20/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Generator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 62fcd21..c42de4d 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -5,7 +5,6 @@ use Illuminate\Console\Concerns\CreatesMatchingTest; use Illuminate\Contracts\Console\PromptsForMissingInput; use Orchestra\Canvas\Core\CodeGenerator; -use Orchestra\Canvas\Core\TestGenerator; use Orchestra\Canvas\Core\Contracts\GeneratesCodeListener; use Orchestra\Canvas\Core\GeneratesCode; use Orchestra\Canvas\Core\Presets\Preset; From 881b115f0ec64523adbace015ebc96df223c7be7 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 12 Sep 2023 21:13:49 +0800 Subject: [PATCH 21/37] wip Signed-off-by: Mior Muhammad Zaki --- src/TestGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TestGenerator.php b/src/TestGenerator.php index 64a0c1e..f8f219d 100644 --- a/src/TestGenerator.php +++ b/src/TestGenerator.php @@ -12,14 +12,14 @@ trait TestGenerator * @param string $path * @return bool */ - protected function handleTestCreationUsingCanvas($path) + protected function handleTestCreationUsingCanvas(string $path): bool { if (! $this->option('test') && ! $this->option('pest')) { return false; } return $this->callSilent('make:test', [ - 'name' => Str::of($path)->after($this->preset->sourcePath())->beforeLast('.php')->append('Test')->replace('\\', '/'), + 'name' => Str::of($path)->after($this->preset->sourcePath())->beforeLast('.php')->append('Test')->replace('\\', '/'), '--pest' => $this->option('pest'), ]) == 0; } From 2eb084dd92519ef1552bd67956d2bff1d3d11a8c Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 12 Sep 2023 21:14:07 +0800 Subject: [PATCH 22/37] wip Signed-off-by: Mior Muhammad Zaki --- src/TestGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TestGenerator.php b/src/TestGenerator.php index 8c7ca6a..f8f219d 100644 --- a/src/TestGenerator.php +++ b/src/TestGenerator.php @@ -12,7 +12,7 @@ trait TestGenerator * @param string $path * @return bool */ - protected function handleTestCreationUsingCanvas($path) + protected function handleTestCreationUsingCanvas(string $path): bool { if (! $this->option('test') && ! $this->option('pest')) { return false; From 96b4fff4813b95b2319100d44898bfdc6ee0f88d Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 12 Sep 2023 21:14:14 +0800 Subject: [PATCH 23/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Contracts/GeneratesCodeListener.php | 4 ---- src/Presets/Preset.php | 1 - src/TestGenerator.php | 3 --- 3 files changed, 8 deletions(-) diff --git a/src/Contracts/GeneratesCodeListener.php b/src/Contracts/GeneratesCodeListener.php index b808675..7ca882f 100644 --- a/src/Contracts/GeneratesCodeListener.php +++ b/src/Contracts/GeneratesCodeListener.php @@ -6,8 +6,6 @@ interface GeneratesCodeListener { /** * Code already exists. - * - * @return mixed */ public function codeAlreadyExists(string $className); @@ -18,8 +16,6 @@ public function generatingCode(string $stub, string $className): string; /** * Code successfully generated. - * - * @return mixed */ public function codeHasBeenGenerated(string $className); diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php index 9081f49..933b04a 100644 --- a/src/Presets/Preset.php +++ b/src/Presets/Preset.php @@ -33,7 +33,6 @@ public function is(string $name): bool * Get configuration. * * @param mixed|null $default - * @return mixed */ public function config(?string $key = null, $default = null) { diff --git a/src/TestGenerator.php b/src/TestGenerator.php index f8f219d..2c4f453 100644 --- a/src/TestGenerator.php +++ b/src/TestGenerator.php @@ -8,9 +8,6 @@ trait TestGenerator { /** * Create the matching test case if requested. - * - * @param string $path - * @return bool */ protected function handleTestCreationUsingCanvas(string $path): bool { From 3b774091b7ed0263bb95f418aa0018bc9fd24bc7 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 12 Sep 2023 23:38:28 +0800 Subject: [PATCH 24/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Contracts/GeneratesCodeListener.php | 4 ++++ src/Presets/Preset.php | 1 + 2 files changed, 5 insertions(+) diff --git a/src/Contracts/GeneratesCodeListener.php b/src/Contracts/GeneratesCodeListener.php index 7ca882f..b808675 100644 --- a/src/Contracts/GeneratesCodeListener.php +++ b/src/Contracts/GeneratesCodeListener.php @@ -6,6 +6,8 @@ interface GeneratesCodeListener { /** * Code already exists. + * + * @return mixed */ public function codeAlreadyExists(string $className); @@ -16,6 +18,8 @@ public function generatingCode(string $stub, string $className): string; /** * Code successfully generated. + * + * @return mixed */ public function codeHasBeenGenerated(string $className); diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php index 933b04a..9081f49 100644 --- a/src/Presets/Preset.php +++ b/src/Presets/Preset.php @@ -33,6 +33,7 @@ public function is(string $name): bool * Get configuration. * * @param mixed|null $default + * @return mixed */ public function config(?string $key = null, $default = null) { From 15b6193fb143355ab477f8542ebe562b122f7f3a Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 12 Sep 2023 23:39:02 +0800 Subject: [PATCH 25/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Contracts/GeneratesCodeListener.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Contracts/GeneratesCodeListener.php b/src/Contracts/GeneratesCodeListener.php index a527baa..ca8e490 100644 --- a/src/Contracts/GeneratesCodeListener.php +++ b/src/Contracts/GeneratesCodeListener.php @@ -6,8 +6,6 @@ interface GeneratesCodeListener { /** * Code already exists. - * - * @return mixed */ public function codeAlreadyExists(string $className): mixed; @@ -18,8 +16,6 @@ public function generatingCode(string $stub, string $className): string; /** * Code successfully generated. - * - * @return mixed */ public function codeHasBeenGenerated(string $className): mixed; From d4722ad8a617bb300c88716784db070b5c96abf4 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 10:17:05 +0800 Subject: [PATCH 26/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Presets/Preset.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php index 9081f49..d4ba9f7 100644 --- a/src/Presets/Preset.php +++ b/src/Presets/Preset.php @@ -61,7 +61,15 @@ public function basePath(): string } /** - * Get the path to the base working directory. + * Get the path to the testing directory. + */ + public function testingPath(): string + { + return "{$this->basePath}/tests"; + } + + /** + * Get the path to the vendor directory. */ public function vendorPath(): string { From c30f38f076f22daa9136607bb38ec455b2bd36cb Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 10:23:03 +0800 Subject: [PATCH 27/37] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 2 +- src/Presets/Package.php | 8 ++++++++ src/Presets/Preset.php | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4e24819..4e1f02d 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "phpstan/phpstan": "^1.10.6" }, "conflict": { - "orchestra/canvas": "<7.7.0", + "orchestra/canvas": "<7.8.0", "orchestra/testbench-core": "<7.25.0" }, "config": { diff --git a/src/Presets/Package.php b/src/Presets/Package.php index 3422f6a..1faa8f8 100644 --- a/src/Presets/Package.php +++ b/src/Presets/Package.php @@ -67,6 +67,14 @@ public function rootNamespace(): string return $namespace; } + /** + * Testing namespace. + */ + public function testingNamespace(): string + { + return $this->preset->config('testing.namespace', 'Tests'); + } + /** * Model namespace. */ diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php index d4ba9f7..ae1b851 100644 --- a/src/Presets/Preset.php +++ b/src/Presets/Preset.php @@ -181,6 +181,11 @@ abstract public function sourcePath(): string; */ abstract public function rootNamespace(): string; + /** + * Testing namespace. + */ + abstract public function testingNamespace(): string; + /** * Model namespace. */ From 5a86593313a44b023de345d97945912dfead3352 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 10:24:50 +0800 Subject: [PATCH 28/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Presets/Laravel.php | 8 ++++++++ src/Presets/Package.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Presets/Laravel.php b/src/Presets/Laravel.php index 808e0ac..a53df9d 100644 --- a/src/Presets/Laravel.php +++ b/src/Presets/Laravel.php @@ -60,6 +60,14 @@ public function rootNamespace(): string return $this->config['namespace'] ?? 'App'; } + /** + * Testing namespace. + */ + public function testingNamespace(): string + { + return $this->preset->config('testing.namespace', 'Tests'); + } + /** * Model namespace. */ diff --git a/src/Presets/Package.php b/src/Presets/Package.php index 1faa8f8..1a615b6 100644 --- a/src/Presets/Package.php +++ b/src/Presets/Package.php @@ -72,7 +72,7 @@ public function rootNamespace(): string */ public function testingNamespace(): string { - return $this->preset->config('testing.namespace', 'Tests'); + return $this->preset->config('testing.namespace', $this->rootNamespace().'\Tests'); } /** From 1b0dd3787a036320e337af14048ea95b76702740 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 10:26:14 +0800 Subject: [PATCH 29/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Presets/Laravel.php | 2 +- src/Presets/Package.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Presets/Laravel.php b/src/Presets/Laravel.php index a53df9d..23b296f 100644 --- a/src/Presets/Laravel.php +++ b/src/Presets/Laravel.php @@ -65,7 +65,7 @@ public function rootNamespace(): string */ public function testingNamespace(): string { - return $this->preset->config('testing.namespace', 'Tests'); + return $this->config('testing.namespace', 'Tests'); } /** diff --git a/src/Presets/Package.php b/src/Presets/Package.php index 1a615b6..c977120 100644 --- a/src/Presets/Package.php +++ b/src/Presets/Package.php @@ -72,7 +72,7 @@ public function rootNamespace(): string */ public function testingNamespace(): string { - return $this->preset->config('testing.namespace', $this->rootNamespace().'\Tests'); + return $this->config('testing.namespace', $this->rootNamespace().'\Tests'); } /** From 348dd4e4bf8dd5802f7c2359bc9f21e25a70dd27 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 13:07:31 +0800 Subject: [PATCH 30/37] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 12 ++++++++-- src/Contracts/GeneratesCodeListener.php | 4 ---- src/Presets/Preset.php | 1 - testbench.yaml | 2 ++ tests/Unit/Presets/LaravelTest.php | 31 +++++++++++++++++++++++++ tests/Unit/Presets/PackageTest.php | 23 ++++++++++++++++++ workbench/app/.gitkeep | 0 workbench/database/factories/.gitkeep | 0 workbench/database/migrations/.gitkeep | 0 workbench/database/seeders/.gitkeep | 0 10 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 testbench.yaml create mode 100644 workbench/app/.gitkeep create mode 100644 workbench/database/factories/.gitkeep create mode 100644 workbench/database/migrations/.gitkeep create mode 100644 workbench/database/seeders/.gitkeep diff --git a/composer.json b/composer.json index 4e1f02d..14100e7 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,10 @@ }, "autoload-dev": { "psr-4": { - "Orchestra\\Canvas\\Core\\Tests\\": "tests/" + "Orchestra\\Canvas\\Core\\Tests\\": "tests/", + "Workbench\\App\\": "workbench/app/", + "Workbench\\Database\\Factories\\": "workbench/database/factories/", + "Workbench\\Database\\Seeders\\": "workbench/database/seeders/" } }, "require": { @@ -54,8 +57,13 @@ } }, "scripts": { - "post-autoload-dump": "@prepare", + "post-autoload-dump": [ + "@clear", + "@prepare" + ], "prepare": "@php vendor/bin/testbench package:discover --ansi", + "clear": "@php vendor/bin/testbench package:purge-skeleton --ansi", + "build": "@php vendor/bin/testbench workbench:build --ansi", "lint": [ "@php vendor/bin/phpstan analyse", "@php vendor/bin/pint" diff --git a/src/Contracts/GeneratesCodeListener.php b/src/Contracts/GeneratesCodeListener.php index b808675..7ca882f 100644 --- a/src/Contracts/GeneratesCodeListener.php +++ b/src/Contracts/GeneratesCodeListener.php @@ -6,8 +6,6 @@ interface GeneratesCodeListener { /** * Code already exists. - * - * @return mixed */ public function codeAlreadyExists(string $className); @@ -18,8 +16,6 @@ public function generatingCode(string $stub, string $className): string; /** * Code successfully generated. - * - * @return mixed */ public function codeHasBeenGenerated(string $className); diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php index ae1b851..c62a001 100644 --- a/src/Presets/Preset.php +++ b/src/Presets/Preset.php @@ -33,7 +33,6 @@ public function is(string $name): bool * Get configuration. * * @param mixed|null $default - * @return mixed */ public function config(?string $key = null, $default = null) { diff --git a/testbench.yaml b/testbench.yaml new file mode 100644 index 0000000..ab4b7fc --- /dev/null +++ b/testbench.yaml @@ -0,0 +1,2 @@ +providers: + - Orchestra\Canvas\Core\LaravelServiceProvider diff --git a/tests/Unit/Presets/LaravelTest.php b/tests/Unit/Presets/LaravelTest.php index bf9e4a2..50f55c3 100644 --- a/tests/Unit/Presets/LaravelTest.php +++ b/tests/Unit/Presets/LaravelTest.php @@ -3,11 +3,22 @@ namespace Orchestra\Canvas\Core\Tests\Unit\Presets; use Illuminate\Filesystem\Filesystem; +use Mockery as m; +use Orchestra\Canvas\Commands; use Orchestra\Canvas\Core\Presets\Laravel; use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Application; class LaravelTest extends TestCase { + /** + * Teardown the test environment. + */ + protected function tearDown(): void + { + m::close(); + } + /** @test */ public function it_has_proper_signatures() { @@ -23,6 +34,7 @@ public function it_has_proper_signatures() $this->assertSame($preset->basePath(), $preset->laravelPath()); $this->assertSame('App', $preset->rootNamespace()); + $this->assertSame('Tests', $preset->testingNamespace()); $this->assertSame('App\Models', $preset->modelNamespace()); $this->assertSame('App\Providers', $preset->providerNamespace()); $this->assertSame('Database\Factories', $preset->factoryNamespace()); @@ -62,4 +74,23 @@ public function it_can_configure_provider_namespace() $this->assertSame('App\Models', $preset->modelNamespace()); $this->assertSame('App', $preset->providerNamespace()); } + + /** @test */ + public function it_can_add_additional_commands() + { + Laravel::commands([ + Commands\Code::class, + ]); + + $app = m::mock(Application::class); + $app->shouldReceive('add') + ->once() + ->with(m::type(Commands\Code::class)) + ->andReturnUsing(fn ($generator) => $this->assertInstanceOf(Commands\Code::class, $generator)); + + $directory = __DIR__; + $preset = new Laravel(['namespace' => 'App', 'provider' => ['namespace' => 'App']], $directory, new Filesystem()); + + $preset->addAdditionalCommands($app); + } } diff --git a/tests/Unit/Presets/PackageTest.php b/tests/Unit/Presets/PackageTest.php index ff83bed..57b2b08 100644 --- a/tests/Unit/Presets/PackageTest.php +++ b/tests/Unit/Presets/PackageTest.php @@ -3,8 +3,11 @@ namespace Orchestra\Canvas\Core\Tests\Unit\Presets; use Illuminate\Filesystem\Filesystem; +use Mockery as m; +use Orchestra\Canvas\Commands; use Orchestra\Canvas\Core\Presets\Package; use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Application; class PackageTest extends TestCase { @@ -23,6 +26,7 @@ public function it_has_proper_signatures() $this->assertSame("{$directory}/vendor/orchestra/testbench-core/laravel", $preset->laravelPath()); $this->assertSame('FooBar', $preset->rootNamespace()); + $this->assertSame('FooBar\Tests', $preset->testingNamespace()); $this->assertSame('FooBar', $preset->modelNamespace()); $this->assertSame('FooBar', $preset->providerNamespace()); $this->assertSame('Database\Factories', $preset->factoryNamespace()); @@ -73,4 +77,23 @@ public function it_requires_root_namespace_to_be_configured() $preset->rootNamespace(); } + + /** @test */ + public function it_can_add_additional_commands() + { + Package::commands([ + Commands\Code::class, + ]); + + $app = m::mock(Application::class); + $app->shouldReceive('add') + ->once() + ->with(m::type(Commands\Code::class)) + ->andReturnUsing(fn ($generator) => $this->assertInstanceOf(Commands\Code::class, $generator)); + + $directory = __DIR__; + $preset = new Package(['namespace' => 'App', 'provider' => ['namespace' => 'App']], $directory, new Filesystem()); + + $preset->addAdditionalCommands($app); + } } diff --git a/workbench/app/.gitkeep b/workbench/app/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/workbench/database/factories/.gitkeep b/workbench/database/factories/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/workbench/database/migrations/.gitkeep b/workbench/database/migrations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/workbench/database/seeders/.gitkeep b/workbench/database/seeders/.gitkeep new file mode 100644 index 0000000..e69de29 From b5aa220562a80c78870ec6899aeda0819ff03079 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 13:11:04 +0800 Subject: [PATCH 31/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Contracts/GeneratesCodeListener.php | 4 ++++ src/Presets/Preset.php | 1 + 2 files changed, 5 insertions(+) diff --git a/src/Contracts/GeneratesCodeListener.php b/src/Contracts/GeneratesCodeListener.php index 7ca882f..b808675 100644 --- a/src/Contracts/GeneratesCodeListener.php +++ b/src/Contracts/GeneratesCodeListener.php @@ -6,6 +6,8 @@ interface GeneratesCodeListener { /** * Code already exists. + * + * @return mixed */ public function codeAlreadyExists(string $className); @@ -16,6 +18,8 @@ public function generatingCode(string $stub, string $className): string; /** * Code successfully generated. + * + * @return mixed */ public function codeHasBeenGenerated(string $className); diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php index c62a001..ae1b851 100644 --- a/src/Presets/Preset.php +++ b/src/Presets/Preset.php @@ -33,6 +33,7 @@ public function is(string $name): bool * Get configuration. * * @param mixed|null $default + * @return mixed */ public function config(?string $key = null, $default = null) { From 50da75ca4df93078fad2eb0222eeaee67fa83178 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 13:14:02 +0800 Subject: [PATCH 32/37] wip Signed-off-by: Mior Muhammad Zaki --- src/CodeGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CodeGenerator.php b/src/CodeGenerator.php index 6db941c..311806c 100644 --- a/src/CodeGenerator.php +++ b/src/CodeGenerator.php @@ -68,7 +68,7 @@ public function getDefaultNamespace(string $rootNamespace): string /** * Generator options. * - * @return array{name: string} + * @return array */ public function generatorOptions(): array { From 626ed7a01c80352b46251bcbfb29f528ad62c077 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 13:45:17 +0800 Subject: [PATCH 33/37] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Generators/Code.php | 31 +++++++ src/Commands/Generators/ConsoleGenerator.php | 87 +++++++++++++++++++ storage/canvas/code.stub | 8 ++ storage/canvas/generator.stub | 51 +++++++++++ .../Feature/Commands/Generators/CodeTest.php | 53 +++++++++++ .../Generators/ConsoleGeneratorTest.php | 87 +++++++++++++++++++ 6 files changed, 317 insertions(+) create mode 100644 src/Commands/Generators/Code.php create mode 100644 src/Commands/Generators/ConsoleGenerator.php create mode 100644 storage/canvas/code.stub create mode 100644 storage/canvas/generator.stub create mode 100644 tests/Feature/Commands/Generators/CodeTest.php create mode 100644 tests/Feature/Commands/Generators/ConsoleGeneratorTest.php diff --git a/src/Commands/Generators/Code.php b/src/Commands/Generators/Code.php new file mode 100644 index 0000000..33f12d4 --- /dev/null +++ b/src/Commands/Generators/Code.php @@ -0,0 +1,31 @@ +getStubFileName(); + } + + /** + * Get the stub file name for the generator. + */ + public function getStubFileName(): string + { + return __DIR__.'/../../../storage/canvas/code.stub'; + } +} diff --git a/src/Commands/Generators/ConsoleGenerator.php b/src/Commands/Generators/ConsoleGenerator.php new file mode 100644 index 0000000..de76c1a --- /dev/null +++ b/src/Commands/Generators/ConsoleGenerator.php @@ -0,0 +1,87 @@ + + */ + protected string $processor = GeneratesCommandCode::class; + + /** + * Get the stub file for the generator. + */ + public function getPublishedStubFileName(): ?string + { + return null; + } + + /** + * Get the stub file for the generator. + */ + public function getStubFile(): string + { + return __DIR__.'/../../../storage/canvas/generator.stub'; + } + + /** + * Get the default namespace for the class. + */ + public function getDefaultNamespace(string $rootNamespace): string + { + return $this->preset->config('console.namespace', $rootNamespace.'\Console\Commands'); + } + + /** + * Generator options. + * + * @return array + */ + public function generatorOptions(): array + { + /** @var string $command */ + $command = $this->option('command'); + + if (! Str::startsWith($command, 'make:')) { + $command = "make:{$command}"; + } + + return [ + 'command' => $command, + 'force' => $this->option('force'), + ]; + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return [ + ['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the generator already exists'], + ['command', null, InputOption::VALUE_OPTIONAL, 'The terminal command that should be assigned', 'make:name'], + ]; + } +} diff --git a/storage/canvas/code.stub b/storage/canvas/code.stub new file mode 100644 index 0000000..daae325 --- /dev/null +++ b/storage/canvas/code.stub @@ -0,0 +1,8 @@ + + */ + protected string $processor = GeneratesCode::class; + + /** + * Get the stub file name for the generator. + */ + public function getStubFileName(): string + { + // Implement path to stub file. + } + + /** + * Get the default namespace for the class. + */ + public function getDefaultNamespace(string $rootNamespace): string + { + return $rootNamespace; + } + + /** + * Generator options. + */ + public function generatorOptions(): array + { + return [ + 'name' => $this->generatorName(), + ]; + } +} diff --git a/tests/Feature/Commands/Generators/CodeTest.php b/tests/Feature/Commands/Generators/CodeTest.php new file mode 100644 index 0000000..eb1c192 --- /dev/null +++ b/tests/Feature/Commands/Generators/CodeTest.php @@ -0,0 +1,53 @@ + 'App', 'generators' => [Generators\Code::class]], $this->app->basePath(), $this->filesystem + ); + + $this->instance('orchestra.canvas', $preset); + + Artisan::starting(fn ($artisan) => $preset->addAdditionalCommands($artisan)); + + $this->artisan('make:class', ['name' => 'Value/Foo']) + ->assertExitCode(0); + + $this->assertFileContains([ + 'namespace App\Value;', + 'class Foo', + ], 'app/Value/Foo.php'); + } + + /** @test */ + public function it_cant_generate_class_file() + { + $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException'); + $this->expectExceptionMessage('The command "make:class" does not exist.'); + + $this->artisan('make:class', ['name' => 'Foo']) + ->assertExitCode(0); + + $this->assertFileContains([ + 'namespace App\Value;', + 'class Foo', + ], 'app/Value/Foo.php'); + } +} diff --git a/tests/Feature/Commands/Generators/ConsoleGeneratorTest.php b/tests/Feature/Commands/Generators/ConsoleGeneratorTest.php new file mode 100644 index 0000000..c7a48f6 --- /dev/null +++ b/tests/Feature/Commands/Generators/ConsoleGeneratorTest.php @@ -0,0 +1,87 @@ + 'App', 'generators' => [Generators\ConsoleGenerator::class]], $this->app->basePath(), $this->filesystem + ); + + $this->instance('orchestra.canvas', $preset); + + Artisan::starting(fn ($artisan) => $preset->addAdditionalCommands($artisan)); + + $this->artisan('make:generator', ['name' => 'FooCommand']) + ->assertExitCode(0); + + $this->assertFileContains([ + 'namespace App\Console\Commands;', + 'use Orchestra\Canvas\Commands\Generator;', + 'use Symfony\Component\Console\Attribute\AsCommand;', + '#[AsCommand(name: \'make:name\', description: \'Create a new class\')]', + 'class FooCommand extends Generator', + ], 'app/Console/Commands/FooCommand.php'); + } + + /** @test */ + public function it_can_generate_command_file_with_command_name() + { + $preset = new Laravel( + ['namespace' => 'App', 'generators' => [Generators\ConsoleGenerator::class]], $this->app->basePath(), $this->filesystem + ); + + $this->instance('orchestra.canvas', $preset); + + Artisan::starting(fn ($artisan) => $preset->addAdditionalCommands($artisan)); + + $this->artisan('make:generator', ['name' => 'FooCommand', '--command' => 'make:foobar']) + ->assertExitCode(0); + + $this->assertFileContains([ + 'namespace App\Console\Commands;', + 'use Orchestra\Canvas\Commands\Generator;', + 'use Symfony\Component\Console\Attribute\AsCommand;', + '#[AsCommand(name: \'make:foobar\', description: \'Create a new class\')]', + 'class FooCommand extends Generator', + ], 'app/Console/Commands/FooCommand.php'); + } + + /** @test */ + public function it_can_generate_command_file_with_command_name_without_make_prefix() + { + $preset = new Laravel( + ['namespace' => 'App', 'generators' => [Generators\ConsoleGenerator::class]], $this->app->basePath(), $this->filesystem + ); + + $this->instance('orchestra.canvas', $preset); + + Artisan::starting(fn ($artisan) => $preset->addAdditionalCommands($artisan)); + + $this->artisan('make:generator', ['name' => 'FooCommand', '--command' => 'foobar']) + ->assertExitCode(0); + + $this->assertFileContains([ + 'namespace App\Console\Commands;', + 'use Orchestra\Canvas\Commands\Generator;', + 'use Symfony\Component\Console\Attribute\AsCommand;', + '#[AsCommand(name: \'make:foobar\', description: \'Create a new class\')]', + 'class FooCommand extends Generator', + ], 'app/Console/Commands/FooCommand.php'); + } +} From bd94889794d1feb14b505e9275374d9420d07585 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 13:49:39 +0800 Subject: [PATCH 34/37] wip Signed-off-by: Mior Muhammad Zaki --- phpunit.xml | 56 ++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 53b2727..7c2f46a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,31 +1,31 @@ - - - src/ - - - src/Core/Commands/Concerns - - - - - ./tests/ - - - - - + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" + backupGlobals="false" + backupStaticAttributes="false" + bootstrap="vendor/autoload.php" + colors="true" + convertDeprecationsToExceptions="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + processIsolation="false" + stopOnFailure="false" + verbose="true"> + + + src/ + + + src/Testing/ + + + + + tests/ + + + + + From a2958cc45cfeb17cc541e8655a8ce9d54d6e336d Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 13:52:46 +0800 Subject: [PATCH 35/37] wip Signed-off-by: Mior Muhammad Zaki --- tests/Unit/Presets/LaravelTest.php | 8 ++++---- tests/Unit/Presets/PackageTest.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Unit/Presets/LaravelTest.php b/tests/Unit/Presets/LaravelTest.php index 50f55c3..ae4bb50 100644 --- a/tests/Unit/Presets/LaravelTest.php +++ b/tests/Unit/Presets/LaravelTest.php @@ -4,7 +4,7 @@ use Illuminate\Filesystem\Filesystem; use Mockery as m; -use Orchestra\Canvas\Commands; +use Orchestra\Canvas\Core\Commands\Generators; use Orchestra\Canvas\Core\Presets\Laravel; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; @@ -79,14 +79,14 @@ public function it_can_configure_provider_namespace() public function it_can_add_additional_commands() { Laravel::commands([ - Commands\Code::class, + Generators\Code::class, ]); $app = m::mock(Application::class); $app->shouldReceive('add') ->once() - ->with(m::type(Commands\Code::class)) - ->andReturnUsing(fn ($generator) => $this->assertInstanceOf(Commands\Code::class, $generator)); + ->with(m::type(Generators\Code::class)) + ->andReturnUsing(fn ($generator) => $this->assertInstanceOf(Generators\Code::class, $generator)); $directory = __DIR__; $preset = new Laravel(['namespace' => 'App', 'provider' => ['namespace' => 'App']], $directory, new Filesystem()); diff --git a/tests/Unit/Presets/PackageTest.php b/tests/Unit/Presets/PackageTest.php index 57b2b08..38655e3 100644 --- a/tests/Unit/Presets/PackageTest.php +++ b/tests/Unit/Presets/PackageTest.php @@ -4,7 +4,7 @@ use Illuminate\Filesystem\Filesystem; use Mockery as m; -use Orchestra\Canvas\Commands; +use Orchestra\Canvas\Core\Commands\Generators; use Orchestra\Canvas\Core\Presets\Package; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; @@ -82,14 +82,14 @@ public function it_requires_root_namespace_to_be_configured() public function it_can_add_additional_commands() { Package::commands([ - Commands\Code::class, + Generators\Code::class, ]); $app = m::mock(Application::class); $app->shouldReceive('add') ->once() - ->with(m::type(Commands\Code::class)) - ->andReturnUsing(fn ($generator) => $this->assertInstanceOf(Commands\Code::class, $generator)); + ->with(m::type(Generators\Code::class)) + ->andReturnUsing(fn ($generator) => $this->assertInstanceOf(Generators\Code::class, $generator)); $directory = __DIR__; $preset = new Package(['namespace' => 'App', 'provider' => ['namespace' => 'App']], $directory, new Filesystem()); From 686f0bd43b758f39215ec48bcf95d193ce75e854 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 13:53:17 +0800 Subject: [PATCH 36/37] wip Signed-off-by: Mior Muhammad Zaki --- phpstan-baseline.neon | 15 +++++++++++++++ src/Contracts/GeneratesCodeListener.php | 4 ---- src/Presets/Preset.php | 1 - 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d60fac4..1eede53 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,6 +1,21 @@ parameters: ignoreErrors: + - + message: "#^Method Orchestra\\\\Canvas\\\\Core\\\\Contracts\\\\GeneratesCodeListener\\:\\:codeAlreadyExists\\(\\) has no return type specified\\.$#" + count: 1 + path: src/Contracts/GeneratesCodeListener.php + + - + message: "#^Method Orchestra\\\\Canvas\\\\Core\\\\Contracts\\\\GeneratesCodeListener\\:\\:codeHasBeenGenerated\\(\\) has no return type specified\\.$#" + count: 1 + path: src/Contracts/GeneratesCodeListener.php + - message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Container\\\\Container\\:\\:basePath\\(\\)\\.$#" count: 1 path: src/LaravelServiceProvider.php + + - + message: "#^Method Orchestra\\\\Canvas\\\\Core\\\\Presets\\\\Preset\\:\\:config\\(\\) has no return type specified\\.$#" + count: 1 + path: src/Presets/Preset.php diff --git a/src/Contracts/GeneratesCodeListener.php b/src/Contracts/GeneratesCodeListener.php index b808675..7ca882f 100644 --- a/src/Contracts/GeneratesCodeListener.php +++ b/src/Contracts/GeneratesCodeListener.php @@ -6,8 +6,6 @@ interface GeneratesCodeListener { /** * Code already exists. - * - * @return mixed */ public function codeAlreadyExists(string $className); @@ -18,8 +16,6 @@ public function generatingCode(string $stub, string $className): string; /** * Code successfully generated. - * - * @return mixed */ public function codeHasBeenGenerated(string $className); diff --git a/src/Presets/Preset.php b/src/Presets/Preset.php index ae1b851..c62a001 100644 --- a/src/Presets/Preset.php +++ b/src/Presets/Preset.php @@ -33,7 +33,6 @@ public function is(string $name): bool * Get configuration. * * @param mixed|null $default - * @return mixed */ public function config(?string $key = null, $default = null) { From 54e75ae77bc2462945399a6e3269ba4f7695e5e0 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 13 Sep 2023 13:54:41 +0800 Subject: [PATCH 37/37] wip Signed-off-by: Mior Muhammad Zaki --- phpstan-baseline.neon | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1eede53..3d858b8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,15 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Method Orchestra\\\\Canvas\\\\Core\\\\Contracts\\\\GeneratesCodeListener\\:\\:codeAlreadyExists\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Contracts/GeneratesCodeListener.php - - - - message: "#^Method Orchestra\\\\Canvas\\\\Core\\\\Contracts\\\\GeneratesCodeListener\\:\\:codeHasBeenGenerated\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Contracts/GeneratesCodeListener.php - - message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Container\\\\Container\\:\\:basePath\\(\\)\\.$#" count: 1