From f07538af093e569bf30738378a94c4634c533267 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sun, 8 Oct 2023 20:52:02 +0800 Subject: [PATCH] wip Signed-off-by: Mior Muhammad Zaki --- src/Concerns/UsesGeneratorOverrides.php | 14 +++++ tests/Concerns/UsesGeneratorOverridesTest.php | 63 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tests/Concerns/UsesGeneratorOverridesTest.php diff --git a/src/Concerns/UsesGeneratorOverrides.php b/src/Concerns/UsesGeneratorOverrides.php index 360a583..2de7f9a 100644 --- a/src/Concerns/UsesGeneratorOverrides.php +++ b/src/Concerns/UsesGeneratorOverrides.php @@ -3,6 +3,7 @@ namespace Orchestra\Canvas\Core\Concerns; use Illuminate\Support\Str; +use Orchestra\Canvas\Core\Presets\Preset; use Symfony\Component\Finder\Finder; trait UsesGeneratorOverrides @@ -96,4 +97,17 @@ protected function possibleEventsUsingCanvas(): array ->values() ->all(); } + + /** + * Get the root namespace for the class. + * + * @return string + */ + abstract protected function rootNamespace(); + + + /** + * Resolve the generator preset. + */ + abstract protected function generatorPreset(): Preset; } diff --git a/tests/Concerns/UsesGeneratorOverridesTest.php b/tests/Concerns/UsesGeneratorOverridesTest.php new file mode 100644 index 0000000..7cc807b --- /dev/null +++ b/tests/Concerns/UsesGeneratorOverridesTest.php @@ -0,0 +1,63 @@ +app['files']; + + $filesystem->ensureDirectoryExists(base_path('app/Models')); + + $stub = new UsesGeneratorOverridesTestStub(); + + $this->assertSame([ + 'user-model' => 'App\Models\User', + 'welcome-view' => $this->app->joinPaths(base_path('resources'.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'welcome.blade.php')), + ], $stub->toArray()); + } +} + +class UsesGeneratorOverridesTestStub implements Arrayable +{ + use UsesGeneratorOverrides; + + /** + * Get the root namespace for the class. + * + * @return string + */ + protected function rootNamespace() + { + return $this->rootNamespaceUsingCanvas(); + } + + /** + * Get the instance as an array. + * + * @return array + */ + public function toArray() + { + return [ + 'user-model' => $this->qualifyModelUsingCanvas('User'), + 'welcome-view' => $this->viewPathUsingCanvas('welcome.blade.php'), + ]; + } + + /** + * Resolve the generator preset. + */ + protected function generatorPreset(): Preset + { + return app(PresetManager::class)->driver('laravel'); + } +}