From 007de95880bd8c502f3df7095b6ca4b5e6e32aee Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 9 Sep 2023 16:55:37 +0800 Subject: [PATCH] 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()); }