From 6b51dfb3f0a8d096aeb4b2985e8a2732e586f605 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Sep 2023 05:48:07 +0800 Subject: [PATCH 01/28] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 4 +++ sync.sh | 5 ++++ workbench/tests/CastMakeCommandTest.php | 2 -- workbench/tests/ComponentMakeCommandTest.php | 10 +++++++ workbench/tests/ExceptionMakeCommandTest.php | 4 --- workbench/tests/ListenerMakeCommandTest.php | 6 ++-- workbench/tests/MigrateMakeCommandTest.php | 4 --- workbench/tests/ResourceMakeCommandTest.php | 4 +-- workbench/tests/RuleMakeCommandTest.php | 2 ++ workbench/tests/ViewMakeCommandTest.php | 29 ++++++++++++++++++++ 10 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 workbench/tests/ViewMakeCommandTest.php diff --git a/composer.json b/composer.json index 81bb316c..b768d735 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,10 @@ "spatie/laravel-ray": "^1.32.4" }, "config": { + "preferred-install": { + "laravel/framework": "source", + "*": "auto" + }, "sort-packages": true }, "extra": { diff --git a/sync.sh b/sync.sh index f5bc91a6..d8c3ef6e 100755 --- a/sync.sh +++ b/sync.sh @@ -11,6 +11,11 @@ cp -rf vendor/laravel/framework/src/Illuminate/Foundation/Console/stubs/test.uni cp -rf vendor/laravel/framework/src/Illuminate/Foundation/Console/stubs/view.stub src/Console/stubs/ cp -rf vendor/laravel/framework/src/Illuminate/Foundation/Console/stubs/view.test.stub src/Console/stubs/ +# Testing +if [ -d vendor/laravel/framework/tests ]; then + cp -rf vendor/laravel/framework/tests/Integration/Generators/*.php workbench/tests/ +fi + ## Fixes namespace. awk '{sub(/use PHPUnit\\Framework\\TestCase/,"use NamespacedDummyTestCase")}1' src/Console/stubs/test.unit.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.unit.stub awk '{sub(/class {{ class }} extends TestCase/,"class {{ class }} extends DummyTestCase")}1' src/Console/stubs/test.unit.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.unit.stub diff --git a/workbench/tests/CastMakeCommandTest.php b/workbench/tests/CastMakeCommandTest.php index 39785616..dbbc5ad9 100644 --- a/workbench/tests/CastMakeCommandTest.php +++ b/workbench/tests/CastMakeCommandTest.php @@ -16,7 +16,6 @@ public function testItCanGenerateCastFile() $this->assertFileContains([ 'namespace App\Casts;', 'use Illuminate\Contracts\Database\Eloquent\CastsAttributes;', - 'use Illuminate\Database\Eloquent\Model;', 'class Foo implements CastsAttributes', 'public function get(Model $model, string $key, mixed $value, array $attributes): mixed', 'public function set(Model $model, string $key, mixed $value, array $attributes): mixed', @@ -31,7 +30,6 @@ public function testItCanGenerateInboundCastFile() $this->assertFileContains([ 'namespace App\Casts;', 'use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes;', - 'use Illuminate\Database\Eloquent\Model;', 'class Foo implements CastsInboundAttributes', 'public function set(Model $model, string $key, mixed $value, array $attributes): mixed', ], 'app/Casts/Foo.php'); diff --git a/workbench/tests/ComponentMakeCommandTest.php b/workbench/tests/ComponentMakeCommandTest.php index 8158ee7b..fc1651ec 100644 --- a/workbench/tests/ComponentMakeCommandTest.php +++ b/workbench/tests/ComponentMakeCommandTest.php @@ -40,4 +40,14 @@ public function testItCanGenerateInlineComponentFile() $this->assertFilenameNotExists('resources/views/components/foo.blade.php'); } + + public function testItCanGenerateComponentFileWithTest() + { + $this->artisan('make:component', ['name' => 'Foo', '--test' => true]) + ->assertExitCode(0); + + $this->assertFilenameExists('app/View/Components/Foo.php'); + $this->assertFilenameExists('resources/views/components/foo.blade.php'); + $this->assertFilenameExists('tests/Feature/View/Components/FooTest.php'); + } } diff --git a/workbench/tests/ExceptionMakeCommandTest.php b/workbench/tests/ExceptionMakeCommandTest.php index 5af9d1ea..9876630c 100644 --- a/workbench/tests/ExceptionMakeCommandTest.php +++ b/workbench/tests/ExceptionMakeCommandTest.php @@ -50,8 +50,6 @@ public function testItCanGenerateExceptionFileWithRenderOption() $this->assertFileContains([ 'namespace App\Exceptions;', 'use Exception;', - 'use Illuminate\Http\Request;', - 'use Illuminate\Http\Response;', 'class FooException extends Exception', 'public function render(Request $request): Response', ], 'app/Exceptions/FooException.php'); @@ -69,8 +67,6 @@ public function testItCanGenerateExceptionFileWithReportAndRenderOption() $this->assertFileContains([ 'namespace App\Exceptions;', 'use Exception;', - 'use Illuminate\Http\Request;', - 'use Illuminate\Http\Response;', 'class FooException extends Exception', 'public function render(Request $request): Response', 'public function report()', diff --git a/workbench/tests/ListenerMakeCommandTest.php b/workbench/tests/ListenerMakeCommandTest.php index 131f162c..6888304b 100644 --- a/workbench/tests/ListenerMakeCommandTest.php +++ b/workbench/tests/ListenerMakeCommandTest.php @@ -11,7 +11,7 @@ class ListenerMakeCommandTest extends TestCase public function testItCanGenerateListenerFile() { - $this->artisan('make:listener', ['name' => 'FooListener', '--event' => '']) + $this->artisan('make:listener', ['name' => 'FooListener']) ->assertExitCode(0); $this->assertFileContains([ @@ -53,7 +53,7 @@ public function testItCanGenerateListenerFileForIlluminateEvent() public function testItCanGenerateQueuedListenerFile() { - $this->artisan('make:listener', ['name' => 'FooListener', '--queued' => true, '--event' => '']) + $this->artisan('make:listener', ['name' => 'FooListener', '--queued' => true]) ->assertExitCode(0); $this->assertFileContains([ @@ -97,7 +97,7 @@ public function testItCanGenerateQueuedListenerFileForIlluminateEvent() public function testItCanGenerateQueuedListenerFileWithTest() { - $this->artisan('make:listener', ['name' => 'FooListener', '--event' => '', '--test' => true]) + $this->artisan('make:listener', ['name' => 'FooListener', '--test' => true]) ->assertExitCode(0); $this->assertFilenameExists('app/Listeners/FooListener.php'); diff --git a/workbench/tests/MigrateMakeCommandTest.php b/workbench/tests/MigrateMakeCommandTest.php index eb47b6fa..fd2ef65a 100644 --- a/workbench/tests/MigrateMakeCommandTest.php +++ b/workbench/tests/MigrateMakeCommandTest.php @@ -4,10 +4,6 @@ class MigrateMakeCommandTest extends TestCase { - protected $files = [ - 'database/acme-migrations/*.php', - ]; - public function testItCanGenerateMigrationFile() { $this->artisan('make:migration', ['name' => 'AddBarToFoosTable']) diff --git a/workbench/tests/ResourceMakeCommandTest.php b/workbench/tests/ResourceMakeCommandTest.php index 24f226c3..b50b4087 100644 --- a/workbench/tests/ResourceMakeCommandTest.php +++ b/workbench/tests/ResourceMakeCommandTest.php @@ -10,7 +10,7 @@ class ResourceMakeCommandTest extends TestCase ]; /** @test */ - public function testItCanGenerateResourceFile() + public function it_can_generate_resource_file() { $this->artisan('make:resource', ['name' => 'FooResource']) ->assertExitCode(0); @@ -23,7 +23,7 @@ public function testItCanGenerateResourceFile() } /** @test */ - public function testItCanGenerateResourceCollectionFile() + public function it_can_generate_resource_collection_file() { $this->artisan('make:resource', ['name' => 'FooResourceCollection', '--collection' => true]) ->assertExitCode(0); diff --git a/workbench/tests/RuleMakeCommandTest.php b/workbench/tests/RuleMakeCommandTest.php index 6c1eea5d..770672a7 100644 --- a/workbench/tests/RuleMakeCommandTest.php +++ b/workbench/tests/RuleMakeCommandTest.php @@ -29,6 +29,7 @@ public function testItCanGenerateInvokableRuleFile() 'namespace App\Rules;', 'use Illuminate\Contracts\Validation\ValidationRule;', 'class Foo implements ValidationRule', + 'public function validate(string $attribute, mixed $value, Closure $fail): void', ], 'app/Rules/Foo.php'); } @@ -41,6 +42,7 @@ public function testItCanGenerateImplicitRuleFile() 'namespace App\Rules;', 'use Illuminate\Contracts\Validation\ValidationRule;', 'class Foo implements ValidationRule', + 'public $implicit = true;', 'public function validate(string $attribute, mixed $value, Closure $fail): void', ], 'app/Rules/Foo.php'); } diff --git a/workbench/tests/ViewMakeCommandTest.php b/workbench/tests/ViewMakeCommandTest.php new file mode 100644 index 00000000..202bc156 --- /dev/null +++ b/workbench/tests/ViewMakeCommandTest.php @@ -0,0 +1,29 @@ +artisan('make:view', ['name' => 'foo']) + ->assertExitCode(0); + + $this->assertFilenameExists('resources/views/foo.blade.php'); + $this->assertFilenameNotExists('tests/Feature/View/FooTest.php'); + } + + public function testItCanGenerateViewFileWithTest() + { + $this->artisan('make:view', ['name' => 'foo', '--test' => true]) + ->assertExitCode(0); + + $this->assertFilenameExists('resources/views/foo.blade.php'); + $this->assertFilenameExists('tests/Feature/View/FooTest.php'); + } +} From 0de887db9448fde721dc00121ce98ac37b3dccee Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Sep 2023 06:10:46 +0800 Subject: [PATCH 02/28] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/ControllerMakeCommand.php | 10 ++++++++++ src/Console/ListenerMakeCommand.php | 10 ++++++++++ src/Console/ObserverMakeCommand.php | 10 ++++++++++ src/Console/PolicyMakeCommand.php | 10 ++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/Console/ControllerMakeCommand.php b/src/Console/ControllerMakeCommand.php index f013931a..2a262abd 100644 --- a/src/Console/ControllerMakeCommand.php +++ b/src/Console/ControllerMakeCommand.php @@ -129,4 +129,14 @@ protected function rootNamespace() { return $this->rootNamespaceUsingCanvas(); } + + /** + * Get a list of possible model names. + * + * @return array + */ + protected function possibleModels() + { + return $this->possibleModelsUsingCanvas(); + } } diff --git a/src/Console/ListenerMakeCommand.php b/src/Console/ListenerMakeCommand.php index ad9770a2..86d7bf26 100644 --- a/src/Console/ListenerMakeCommand.php +++ b/src/Console/ListenerMakeCommand.php @@ -62,4 +62,14 @@ protected function rootNamespace() { return $this->rootNamespaceUsingCanvas(); } + + /** + * Get a list of possible event names. + * + * @return array + */ + protected function possibleEvents() + { + return $this->possibleEventsUsingCanvas(); + } } diff --git a/src/Console/ObserverMakeCommand.php b/src/Console/ObserverMakeCommand.php index 5ddb29df..06cca3ce 100644 --- a/src/Console/ObserverMakeCommand.php +++ b/src/Console/ObserverMakeCommand.php @@ -71,4 +71,14 @@ protected function rootNamespace() { return $this->rootNamespaceUsingCanvas(); } + + /** + * Get a list of possible model names. + * + * @return array + */ + protected function possibleModels() + { + return $this->possibleModelsUsingCanvas(); + } } diff --git a/src/Console/PolicyMakeCommand.php b/src/Console/PolicyMakeCommand.php index a702223f..b2916df4 100644 --- a/src/Console/PolicyMakeCommand.php +++ b/src/Console/PolicyMakeCommand.php @@ -84,4 +84,14 @@ protected function userProviderModel() return $this->userProviderModelUsingCanvas($guard); } + + /** + * Get a list of possible model names. + * + * @return array + */ + protected function possibleModels() + { + return $this->possibleModelsUsingCanvas(); + } } From 47547b61771b336d468e4a06e53e312e455bf056 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Sep 2023 09:18:08 +0800 Subject: [PATCH 03/28] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/ConsoleMakeCommand.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Console/ConsoleMakeCommand.php b/src/Console/ConsoleMakeCommand.php index 9050cd6f..97661af2 100644 --- a/src/Console/ConsoleMakeCommand.php +++ b/src/Console/ConsoleMakeCommand.php @@ -62,4 +62,15 @@ protected function rootNamespace() { return $this->rootNamespaceUsingCanvas(); } + + /** + * Get the default namespace for the class. + * + * @param string $rootNamespace + * @return string + */ + protected function getDefaultNamespace($rootNamespace) + { + return rtrim($this->generatorPreset()->commandNamespace(), '\\'); + } } From 0948f53742c85f8fc8a675520972ca0f8768d2b2 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Sep 2023 09:26:48 +0800 Subject: [PATCH 04/28] wip Signed-off-by: Mior Muhammad Zaki --- canvas.yaml | 2 +- src/Console/CastMakeCommand.php | 2 +- src/Console/ChannelMakeCommand.php | 2 +- src/Console/ComponentMakeCommand.php | 2 +- src/Console/ConsoleMakeCommand.php | 2 +- src/Console/ControllerMakeCommand.php | 2 +- src/Console/EventMakeCommand.php | 2 +- src/Console/ExceptionMakeCommand.php | 2 +- src/Console/FactoryMakeCommand.php | 2 +- src/Console/JobMakeCommand.php | 2 +- src/Console/ListenerMakeCommand.php | 2 +- src/Console/MailMakeCommand.php | 2 +- src/Console/MiddlewareMakeCommand.php | 2 +- src/Console/ModelMakeCommand.php | 2 +- src/Console/NotificationMakeCommand.php | 2 +- src/Console/NotificationTableCommand.php | 37 ++++++++++++++++++++++++ src/Console/ObserverMakeCommand.php | 2 +- src/Console/PolicyMakeCommand.php | 2 +- src/Console/ProviderMakeCommand.php | 2 +- src/Console/RequestMakeCommand.php | 2 +- src/Console/ResourceMakeCommand.php | 2 +- src/Console/RuleMakeCommand.php | 2 +- src/Console/ScopeMakeCommand.php | 2 +- src/Console/SeederMakeCommand.php | 2 +- src/Console/TestMakeCommand.php | 2 +- 25 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 src/Console/NotificationTableCommand.php diff --git a/canvas.yaml b/canvas.yaml index 85d3084e..cdc935bd 100644 --- a/canvas.yaml +++ b/canvas.yaml @@ -6,7 +6,7 @@ paths: src: src console: - namespace: Orchestra\Canvas\Commands + namespace: Orchestra\Canvas\Console provider: namespace: Orchestra\Canvas diff --git a/src/Console/CastMakeCommand.php b/src/Console/CastMakeCommand.php index da938da4..7b2b0b32 100644 --- a/src/Console/CastMakeCommand.php +++ b/src/Console/CastMakeCommand.php @@ -17,7 +17,7 @@ class CastMakeCommand extends \Illuminate\Foundation\Console\CastMakeCommand use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/ChannelMakeCommand.php b/src/Console/ChannelMakeCommand.php index d06eac29..6bcbd29c 100644 --- a/src/Console/ChannelMakeCommand.php +++ b/src/Console/ChannelMakeCommand.php @@ -19,7 +19,7 @@ class ChannelMakeCommand extends \Illuminate\Foundation\Console\ChannelMakeComma use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/ComponentMakeCommand.php b/src/Console/ComponentMakeCommand.php index 9fe06144..83751f72 100644 --- a/src/Console/ComponentMakeCommand.php +++ b/src/Console/ComponentMakeCommand.php @@ -17,7 +17,7 @@ class ComponentMakeCommand extends \Illuminate\Foundation\Console\ComponentMakeC use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/ConsoleMakeCommand.php b/src/Console/ConsoleMakeCommand.php index 97661af2..9f6524da 100644 --- a/src/Console/ConsoleMakeCommand.php +++ b/src/Console/ConsoleMakeCommand.php @@ -19,7 +19,7 @@ class ConsoleMakeCommand extends \Illuminate\Foundation\Console\ConsoleMakeComma use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/ControllerMakeCommand.php b/src/Console/ControllerMakeCommand.php index f013931a..6d05d31a 100644 --- a/src/Console/ControllerMakeCommand.php +++ b/src/Console/ControllerMakeCommand.php @@ -19,7 +19,7 @@ class ControllerMakeCommand extends \Illuminate\Routing\Console\ControllerMakeCo use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/EventMakeCommand.php b/src/Console/EventMakeCommand.php index ce44f5d6..d69b680a 100644 --- a/src/Console/EventMakeCommand.php +++ b/src/Console/EventMakeCommand.php @@ -17,7 +17,7 @@ class EventMakeCommand extends \Illuminate\Foundation\Console\EventMakeCommand use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/ExceptionMakeCommand.php b/src/Console/ExceptionMakeCommand.php index 3befbbef..1a41532b 100644 --- a/src/Console/ExceptionMakeCommand.php +++ b/src/Console/ExceptionMakeCommand.php @@ -17,7 +17,7 @@ class ExceptionMakeCommand extends \Illuminate\Foundation\Console\ExceptionMakeC use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/FactoryMakeCommand.php b/src/Console/FactoryMakeCommand.php index 034e8024..7b486caa 100644 --- a/src/Console/FactoryMakeCommand.php +++ b/src/Console/FactoryMakeCommand.php @@ -19,7 +19,7 @@ class FactoryMakeCommand extends \Illuminate\Database\Console\Factories\FactoryM use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/JobMakeCommand.php b/src/Console/JobMakeCommand.php index 3069d67b..36b9c223 100644 --- a/src/Console/JobMakeCommand.php +++ b/src/Console/JobMakeCommand.php @@ -19,7 +19,7 @@ class JobMakeCommand extends \Illuminate\Foundation\Console\JobMakeCommand use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/ListenerMakeCommand.php b/src/Console/ListenerMakeCommand.php index ad9770a2..d1ff5125 100644 --- a/src/Console/ListenerMakeCommand.php +++ b/src/Console/ListenerMakeCommand.php @@ -19,7 +19,7 @@ class ListenerMakeCommand extends \Illuminate\Foundation\Console\ListenerMakeCom use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/MailMakeCommand.php b/src/Console/MailMakeCommand.php index d22d3645..363aacb4 100644 --- a/src/Console/MailMakeCommand.php +++ b/src/Console/MailMakeCommand.php @@ -19,7 +19,7 @@ class MailMakeCommand extends \Illuminate\Foundation\Console\MailMakeCommand use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/MiddlewareMakeCommand.php b/src/Console/MiddlewareMakeCommand.php index 98405ac9..f1010e4b 100644 --- a/src/Console/MiddlewareMakeCommand.php +++ b/src/Console/MiddlewareMakeCommand.php @@ -19,7 +19,7 @@ class MiddlewareMakeCommand extends \Illuminate\Routing\Console\MiddlewareMakeCo use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/ModelMakeCommand.php b/src/Console/ModelMakeCommand.php index d07de5c2..342cef1b 100644 --- a/src/Console/ModelMakeCommand.php +++ b/src/Console/ModelMakeCommand.php @@ -20,7 +20,7 @@ class ModelMakeCommand extends \Illuminate\Foundation\Console\ModelMakeCommand use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/NotificationMakeCommand.php b/src/Console/NotificationMakeCommand.php index 896bd654..3e02b38e 100644 --- a/src/Console/NotificationMakeCommand.php +++ b/src/Console/NotificationMakeCommand.php @@ -19,7 +19,7 @@ class NotificationMakeCommand extends \Illuminate\Foundation\Console\Notificatio use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/NotificationTableCommand.php b/src/Console/NotificationTableCommand.php new file mode 100644 index 00000000..594c636b --- /dev/null +++ b/src/Console/NotificationTableCommand.php @@ -0,0 +1,37 @@ +addGeneratorPresetOptions(); + } + + + /** + * Create a base migration file for the notifications. + * + * @return string + */ + protected function createBaseMigration() + { + return $this->createBaseMigrationUsingCanvas('notifications'); + } +} diff --git a/src/Console/ObserverMakeCommand.php b/src/Console/ObserverMakeCommand.php index 5ddb29df..44ef1488 100644 --- a/src/Console/ObserverMakeCommand.php +++ b/src/Console/ObserverMakeCommand.php @@ -17,7 +17,7 @@ class ObserverMakeCommand extends \Illuminate\Foundation\Console\ObserverMakeCom use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/PolicyMakeCommand.php b/src/Console/PolicyMakeCommand.php index a702223f..4b2d87d2 100644 --- a/src/Console/PolicyMakeCommand.php +++ b/src/Console/PolicyMakeCommand.php @@ -17,7 +17,7 @@ class PolicyMakeCommand extends \Illuminate\Foundation\Console\PolicyMakeCommand use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/ProviderMakeCommand.php b/src/Console/ProviderMakeCommand.php index 72b327ec..fa5ee589 100644 --- a/src/Console/ProviderMakeCommand.php +++ b/src/Console/ProviderMakeCommand.php @@ -17,7 +17,7 @@ class ProviderMakeCommand extends \Illuminate\Foundation\Console\ProviderMakeCom use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/RequestMakeCommand.php b/src/Console/RequestMakeCommand.php index 66eb2c50..820f367b 100644 --- a/src/Console/RequestMakeCommand.php +++ b/src/Console/RequestMakeCommand.php @@ -17,7 +17,7 @@ class RequestMakeCommand extends \Illuminate\Foundation\Console\RequestMakeComma use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/ResourceMakeCommand.php b/src/Console/ResourceMakeCommand.php index d57a6900..ab69423a 100644 --- a/src/Console/ResourceMakeCommand.php +++ b/src/Console/ResourceMakeCommand.php @@ -17,7 +17,7 @@ class ResourceMakeCommand extends \Illuminate\Foundation\Console\ResourceMakeCom use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/RuleMakeCommand.php b/src/Console/RuleMakeCommand.php index 795f2c0c..4881c292 100644 --- a/src/Console/RuleMakeCommand.php +++ b/src/Console/RuleMakeCommand.php @@ -17,7 +17,7 @@ class RuleMakeCommand extends \Illuminate\Foundation\Console\RuleMakeCommand use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/ScopeMakeCommand.php b/src/Console/ScopeMakeCommand.php index b51d95cf..2b30066f 100644 --- a/src/Console/ScopeMakeCommand.php +++ b/src/Console/ScopeMakeCommand.php @@ -17,7 +17,7 @@ class ScopeMakeCommand extends \Illuminate\Foundation\Console\ScopeMakeCommand use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/SeederMakeCommand.php b/src/Console/SeederMakeCommand.php index 79c9b4fb..36a25ec4 100644 --- a/src/Console/SeederMakeCommand.php +++ b/src/Console/SeederMakeCommand.php @@ -17,7 +17,7 @@ class SeederMakeCommand extends \Illuminate\Database\Console\Seeds\SeederMakeCom use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ diff --git a/src/Console/TestMakeCommand.php b/src/Console/TestMakeCommand.php index 113dd6dd..2301cf70 100644 --- a/src/Console/TestMakeCommand.php +++ b/src/Console/TestMakeCommand.php @@ -19,7 +19,7 @@ class TestMakeCommand extends \Illuminate\Foundation\Console\TestMakeCommand use UsesGeneratorOverrides; /** - * Create a new controller creator command instance. + * Create a new creator command instance. * * @return void */ From 98dc24a014ef62217bf9ce0200d9413270657543 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Sep 2023 09:40:01 +0800 Subject: [PATCH 05/28] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/NotificationTableCommand.php | 9 ++++++-- src/LaravelServiceProvider.php | 17 +++++++++++++++ .../Console/ComponentMakeCommandTest.php | 2 +- .../Console/MigrateMakeCommandTest.php | 2 +- .../Console/NotificationTableCommandTest.php | 21 +++++++++++++++++++ .../Console/RequestMakeCommandTest.php | 2 +- 6 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 tests/Feature/Console/NotificationTableCommandTest.php diff --git a/src/Console/NotificationTableCommand.php b/src/Console/NotificationTableCommand.php index 594c636b..f1c888ad 100644 --- a/src/Console/NotificationTableCommand.php +++ b/src/Console/NotificationTableCommand.php @@ -3,8 +3,14 @@ namespace Orchestra\Canvas\Console; use Illuminate\Console\Command; +use Illuminate\Filesystem\Filesystem; +use Illuminate\Support\Composer; use Orchestra\Canvas\Core\Concerns\MigrationGenerator; +use Symfony\Component\Console\Attribute\AsCommand; +/** + * @see https://github.com/laravel/framework/blob/9.x/src/Illuminate/Notifications/Console/NotificationTableCommand.php + */ #[AsCommand(name: 'notifications:table', description: 'Create a migration for the notifications table')] class NotificationTableCommand extends \Illuminate\Notifications\Console\NotificationTableCommand { @@ -19,12 +25,11 @@ class NotificationTableCommand extends \Illuminate\Notifications\Console\Notific */ public function __construct(Filesystem $files, Composer $composer) { - parent::__construct($files); + parent::__construct($files, $composer); $this->addGeneratorPresetOptions(); } - /** * Create a base migration file for the notifications. * diff --git a/src/LaravelServiceProvider.php b/src/LaravelServiceProvider.php index b2620fff..9d4f8eb5 100644 --- a/src/LaravelServiceProvider.php +++ b/src/LaravelServiceProvider.php @@ -25,6 +25,7 @@ use Illuminate\Foundation\Console\RuleMakeCommand; use Illuminate\Foundation\Console\ScopeMakeCommand; use Illuminate\Foundation\Console\TestMakeCommand; +use Illuminate\Notifications\Console\NotificationTableCommand; use Illuminate\Routing\Console\ControllerMakeCommand; use Illuminate\Routing\Console\MiddlewareMakeCommand; use Illuminate\Support\ServiceProvider; @@ -66,6 +67,7 @@ public function register() $this->registerMigrateMakeCommand(); $this->registerModelMakeCommand(); $this->registerNotificationMakeCommand(); + $this->registerNotificationTableCommand(); $this->registerObserverMakeCommand(); $this->registerPolicyMakeCommand(); $this->registerProviderMakeCommand(); @@ -92,6 +94,7 @@ public function register() Console\MigrateMakeCommand::class, Console\ModelMakeCommand::class, Console\NotificationMakeCommand::class, + Console\NotificationTableCommand::class, Console\ObserverMakeCommand::class, Console\PolicyMakeCommand::class, Console\ProviderMakeCommand::class, @@ -291,6 +294,18 @@ protected function registerNotificationMakeCommand() }); } + /** + * Register the command. + * + * @return void + */ + protected function registerNotificationTableCommand() + { + $this->app->singleton(NotificationTableCommand::class, function ($app) { + return new Console\NotificationTableCommand($app['files'], $app['composer']); + }); + } + /** * Register the command. * @@ -437,6 +452,8 @@ public function provides() Console\ModelMakeCommand::class, NotificationMakeCommand::class, Console\NotificationMakeCommand::class, + NotificationTableCommand::class, + Console\NotificationTableCommand::class, ObserverMakeCommand::class, Console\ObserverMakeCommand::class, PolicyMakeCommand::class, diff --git a/tests/Feature/Console/ComponentMakeCommandTest.php b/tests/Feature/Console/ComponentMakeCommandTest.php index fc4e77df..7542065c 100644 --- a/tests/Feature/Console/ComponentMakeCommandTest.php +++ b/tests/Feature/Console/ComponentMakeCommandTest.php @@ -1,6 +1,6 @@ artisan('notifications:table', ['--preset' => 'canvas']) + ->assertSuccessful(); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'notifications\', function (Blueprint $table) {', + ], 'create_notifications_table.php'); + } +} diff --git a/tests/Feature/Console/RequestMakeCommandTest.php b/tests/Feature/Console/RequestMakeCommandTest.php index 7de16e68..71f74a21 100644 --- a/tests/Feature/Console/RequestMakeCommandTest.php +++ b/tests/Feature/Console/RequestMakeCommandTest.php @@ -1,6 +1,6 @@ Date: Tue, 19 Sep 2023 10:04:15 +0800 Subject: [PATCH 06/28] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/BatchesTableCommand.php | 42 +++++++ src/Console/FailedTableCommand.php | 42 +++++++ src/Console/NotificationTableCommand.php | 1 - src/Console/QueueTableCommand.php | 43 +++++++ src/Console/SessionTableCommand.php | 41 +++++++ src/LaravelServiceProvider.php | 116 +++++++++++++----- .../Console/BatchesTableCommandTest.php | 21 ++++ .../Console/FailedTableCommandTest.php | 21 ++++ .../Feature/Console/QueueTableCommandTest.php | 21 ++++ .../Console/SessionTableCommandTest.php | 21 ++++ 10 files changed, 339 insertions(+), 30 deletions(-) create mode 100644 src/Console/BatchesTableCommand.php create mode 100644 src/Console/FailedTableCommand.php create mode 100644 src/Console/QueueTableCommand.php create mode 100644 src/Console/SessionTableCommand.php create mode 100644 tests/Feature/Console/BatchesTableCommandTest.php create mode 100644 tests/Feature/Console/FailedTableCommandTest.php create mode 100644 tests/Feature/Console/QueueTableCommandTest.php create mode 100644 tests/Feature/Console/SessionTableCommandTest.php diff --git a/src/Console/BatchesTableCommand.php b/src/Console/BatchesTableCommand.php new file mode 100644 index 00000000..1df3f2b3 --- /dev/null +++ b/src/Console/BatchesTableCommand.php @@ -0,0 +1,42 @@ +addGeneratorPresetOptions(); + } + + /** + * Create a base migration file for the table. + * + * @param string $table + * @return string + */ + protected function createBaseMigration($table = 'job_batches') + { + return $this->createBaseMigrationUsingCanvas($table); + } +} diff --git a/src/Console/FailedTableCommand.php b/src/Console/FailedTableCommand.php new file mode 100644 index 00000000..432cf6b6 --- /dev/null +++ b/src/Console/FailedTableCommand.php @@ -0,0 +1,42 @@ +addGeneratorPresetOptions(); + } + + /** + * Create a base migration file for the table. + * + * @param string $table + * @return string + */ + protected function createBaseMigration($table = 'failed_jobs') + { + return $this->createBaseMigrationUsingCanvas($table); + } +} diff --git a/src/Console/NotificationTableCommand.php b/src/Console/NotificationTableCommand.php index f1c888ad..f238d8b8 100644 --- a/src/Console/NotificationTableCommand.php +++ b/src/Console/NotificationTableCommand.php @@ -2,7 +2,6 @@ namespace Orchestra\Canvas\Console; -use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Composer; use Orchestra\Canvas\Core\Concerns\MigrationGenerator; diff --git a/src/Console/QueueTableCommand.php b/src/Console/QueueTableCommand.php new file mode 100644 index 00000000..ed856fae --- /dev/null +++ b/src/Console/QueueTableCommand.php @@ -0,0 +1,43 @@ +addGeneratorPresetOptions(); + } + + /** + * Create a base migration file for the table. + * + * @param string $table + * @return string + */ + protected function createBaseMigration($table = 'jobs') + { + return $this->createBaseMigrationUsingCanvas($table); + } +} diff --git a/src/Console/SessionTableCommand.php b/src/Console/SessionTableCommand.php new file mode 100644 index 00000000..9cbe0fa5 --- /dev/null +++ b/src/Console/SessionTableCommand.php @@ -0,0 +1,41 @@ +addGeneratorPresetOptions(); + } + + /** + * Create a base migration file for the session. + * + * @return string + */ + protected function createBaseMigration() + { + return $this->createBaseMigrationUsingCanvas('sessions'); + } +} diff --git a/src/LaravelServiceProvider.php b/src/LaravelServiceProvider.php index 9d4f8eb5..e8022177 100644 --- a/src/LaravelServiceProvider.php +++ b/src/LaravelServiceProvider.php @@ -26,25 +26,16 @@ use Illuminate\Foundation\Console\ScopeMakeCommand; use Illuminate\Foundation\Console\TestMakeCommand; use Illuminate\Notifications\Console\NotificationTableCommand; +use Illuminate\Queue\Console\BatchesTableCommand; +use Illuminate\Queue\Console\FailedTableCommand; +use Illuminate\Queue\Console\TableCommand as QueueTableCommand; use Illuminate\Routing\Console\ControllerMakeCommand; use Illuminate\Routing\Console\MiddlewareMakeCommand; +use Illuminate\Session\Console\SessionTableCommand; use Illuminate\Support\ServiceProvider; class LaravelServiceProvider extends ServiceProvider implements DeferrableProvider { - /** - * The commands to be registered. - * - * @var array - */ - protected $devCommands = [ - // 'NotificationTable' => NotificationTableCommand::class, - // 'QueueFailedTable' => FailedTableCommand::class, - // 'QueueTable' => TableCommand::class, - // 'QueueBatchesTable' => BatchesTableCommand::class, - // 'SessionTable' => SessionTableCommand::class, - ]; - /** * Register the service provider. * @@ -67,7 +58,6 @@ public function register() $this->registerMigrateMakeCommand(); $this->registerModelMakeCommand(); $this->registerNotificationMakeCommand(); - $this->registerNotificationTableCommand(); $this->registerObserverMakeCommand(); $this->registerPolicyMakeCommand(); $this->registerProviderMakeCommand(); @@ -78,6 +68,12 @@ public function register() $this->registerSeederMakeCommand(); $this->registerTestMakeCommand(); + $this->registerNotificationTableCommand(); + $this->registerQueueBatchesTableCommand(); + $this->registerQueueFailedTableCommand(); + $this->registerQueueTableCommand(); + $this->registerSessionTableCommand(); + $this->commands([ Console\CastMakeCommand::class, Console\ChannelMakeCommand::class, @@ -94,7 +90,6 @@ public function register() Console\MigrateMakeCommand::class, Console\ModelMakeCommand::class, Console\NotificationMakeCommand::class, - Console\NotificationTableCommand::class, Console\ObserverMakeCommand::class, Console\PolicyMakeCommand::class, Console\ProviderMakeCommand::class, @@ -104,6 +99,12 @@ public function register() Console\ScopeMakeCommand::class, Console\SeederMakeCommand::class, Console\TestMakeCommand::class, + + Console\BatchesTableCommand::class, + Console\FailedTableCommand::class, + Console\NotificationTableCommand::class, + Console\QueueTableCommand::class, + Console\SessionTableCommand::class, ]); } @@ -294,18 +295,6 @@ protected function registerNotificationMakeCommand() }); } - /** - * Register the command. - * - * @return void - */ - protected function registerNotificationTableCommand() - { - $this->app->singleton(NotificationTableCommand::class, function ($app) { - return new Console\NotificationTableCommand($app['files'], $app['composer']); - }); - } - /** * Register the command. * @@ -414,6 +403,66 @@ protected function registerTestMakeCommand() }); } + /** + * Register the command. + * + * @return void + */ + protected function registerNotificationTableCommand() + { + $this->app->singleton(NotificationTableCommand::class, function ($app) { + return new Console\NotificationTableCommand($app['files'], $app['composer']); + }); + } + + /** + * Register the command. + * + * @return void + */ + protected function registerQueueBatchesTableCommand() + { + $this->app->singleton(BatchesTableCommand::class, function ($app) { + return new Console\BatchesTableCommand($app['files'], $app['composer']); + }); + } + + /** + * Register the command. + * + * @return void + */ + protected function registerQueueFailedTableCommand() + { + $this->app->singleton(FailedTableCommand::class, function ($app) { + return new Console\FailedTableCommand($app['files'], $app['composer']); + }); + } + + /** + * Register the command. + * + * @return void + */ + protected function registerQueueTableCommand() + { + $this->app->singleton(QueueTableCommand::class, function ($app) { + return new Console\QueueTableCommand($app['files'], $app['composer']); + }); + } + + /** + * Register the command. + * + * @return void + */ + protected function registerSessionTableCommand() + { + $this->app->singleton(SessionTableCommand::class, function ($app) { + return new Console\SessionTableCommand($app['files'], $app['composer']); + }); + } + /** * Get the services provided by the provider. * @@ -452,8 +501,6 @@ public function provides() Console\ModelMakeCommand::class, NotificationMakeCommand::class, Console\NotificationMakeCommand::class, - NotificationTableCommand::class, - Console\NotificationTableCommand::class, ObserverMakeCommand::class, Console\ObserverMakeCommand::class, PolicyMakeCommand::class, @@ -472,6 +519,17 @@ public function provides() Console\SeederMakeCommand::class, TestMakeCommand::class, Console\TestMakeCommand::class, + + BatchesTableCommand::class, + Console\BatchesTableCommand::class, + FailedTableCommand::class, + Console\FailedTableCommand::class, + NotificationTableCommand::class, + Console\NotificationTableCommand::class, + QueueTableCommand::class, + Console\QueueTableCommand::class, + SessionTableCommand::class, + Console\SessionTableCommand::class, ]; } } diff --git a/tests/Feature/Console/BatchesTableCommandTest.php b/tests/Feature/Console/BatchesTableCommandTest.php new file mode 100644 index 00000000..bbf74f18 --- /dev/null +++ b/tests/Feature/Console/BatchesTableCommandTest.php @@ -0,0 +1,21 @@ +artisan('queue:batches-table', ['--preset' => 'canvas']) + ->assertSuccessful(); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'job_batches\', function (Blueprint $table) {', + ], 'create_job_batches_table.php'); + } +} diff --git a/tests/Feature/Console/FailedTableCommandTest.php b/tests/Feature/Console/FailedTableCommandTest.php new file mode 100644 index 00000000..f84d45c7 --- /dev/null +++ b/tests/Feature/Console/FailedTableCommandTest.php @@ -0,0 +1,21 @@ +artisan('queue:failed-table', ['--preset' => 'canvas']) + ->assertSuccessful(); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'failed_jobs\', function (Blueprint $table) {', + ], 'create_failed_jobs_table.php'); + } +} diff --git a/tests/Feature/Console/QueueTableCommandTest.php b/tests/Feature/Console/QueueTableCommandTest.php new file mode 100644 index 00000000..f28b0730 --- /dev/null +++ b/tests/Feature/Console/QueueTableCommandTest.php @@ -0,0 +1,21 @@ +artisan('queue:table', ['--preset' => 'canvas']) + ->assertSuccessful(); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'jobs\', function (Blueprint $table) {', + ], 'create_jobs_table.php'); + } +} diff --git a/tests/Feature/Console/SessionTableCommandTest.php b/tests/Feature/Console/SessionTableCommandTest.php new file mode 100644 index 00000000..3823e15f --- /dev/null +++ b/tests/Feature/Console/SessionTableCommandTest.php @@ -0,0 +1,21 @@ +artisan('session:table', ['--preset' => 'canvas']) + ->assertSuccessful(); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'sessions\', function (Blueprint $table) {', + ], 'create_sessions_table.php'); + } +} From 168e8500b9581ce7f1651550a0ea6972c9e18753 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Sep 2023 12:23:07 +0800 Subject: [PATCH 07/28] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 691272f5..156cc606 100644 --- a/composer.json +++ b/composer.json @@ -32,13 +32,13 @@ "illuminate/database": "^9.52.15", "illuminate/support": "^9.52.15", "orchestra/canvas-core": "^7.7", + "orchestra/testbench-core": "^7.31", "symfony/yaml": "^5.4 || ^6.0" }, "require-dev": { "laravel/framework": "^9.52.15", "laravel/pint": "^1.4", "mockery/mockery": "^1.5.1", - "orchestra/testbench-core": "^7.30", "phpstan/phpstan": "^1.10.5", "phpunit/phpunit": "^9.5.10", "spatie/laravel-ray": "^1.32.4" From cb55565f3b1c3f6ef88e9f70f9cefdc1743caaee Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Sep 2023 12:58:19 +0800 Subject: [PATCH 08/28] wip Signed-off-by: Mior Muhammad Zaki --- .../Console/MigrateMakeCommandTest.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/Feature/Console/MigrateMakeCommandTest.php b/tests/Feature/Console/MigrateMakeCommandTest.php index 4fd8e09a..a601d4a8 100644 --- a/tests/Feature/Console/MigrateMakeCommandTest.php +++ b/tests/Feature/Console/MigrateMakeCommandTest.php @@ -2,10 +2,15 @@ namespace Orchestra\Canvas\Tests\Feature\Console; +use Orchestra\Canvas\Presets\Laravel; use Orchestra\Canvas\Tests\Feature\TestCase; class MigrateMakeCommandTest extends TestCase { + protected $files = [ + 'database/acme-migrations/*.php', + ]; + /** @test */ public function it_can_generate_migration_file() { @@ -59,4 +64,21 @@ public function it_can_generate_migration_with_create_options_file() 'Schema::dropIfExists(\'foobar\');', ], 'foos_table.php'); } + + public function testItCanGenerateMigrationFileWithCustomMigrationPath() + { + $this->instance('orchestra.canvas', new Laravel( + ['namespace' => 'Acme', 'migration' => ['path' => 'database'.DIRECTORY_SEPARATOR.'acme-migrations']], $this->app->basePath() + )); + + $this->artisan('make:migration', ['name' => 'AcmeFoosTable', '--create' => 'foobar', '--preset' => 'canvas']) + ->assertExitCode(0); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'foobar\', function (Blueprint $table) {', + 'Schema::dropIfExists(\'foobar\');', + ], 'acme_foos_table.php', directory: 'database/acme-migrations'); + } } From 9e212fe85fdbd159bc1f4d3442c914ecda52dfc1 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Sep 2023 21:11:15 +0800 Subject: [PATCH 09/28] wip --- src/Console/stubs/factory.stub | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Console/stubs/factory.stub b/src/Console/stubs/factory.stub index 3995e1d2..b032dcef 100644 --- a/src/Console/stubs/factory.stub +++ b/src/Console/stubs/factory.stub @@ -6,14 +6,16 @@ use Illuminate\Database\Eloquent\Factories\Factory; use {{ namespacedModel }}; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\{{ namespacedModel }}> + * @template TModel of \{{ namespacedModel }} + * + * @extends \Illuminate\Database\Eloquent\Factories\Factory */ class {{ factory }}Factory extends Factory { /** * The name of the factory's corresponding model. * - * @var string + * @var class-string */ protected $model = {{ model }}::class; From c6b79cf2a8cb5bac32ce1fdb499af0ec0b86a2ad Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 20 Sep 2023 11:42:46 +0800 Subject: [PATCH 10/28] wip Signed-off-by: Mior Muhammad Zaki --- .gitattributes | 2 +- bin/sync | 52 ++++++++++++++++++++++++++++++++++ src/Console/stubs/factory.stub | 2 +- sync.sh | 16 ----------- 4 files changed, 54 insertions(+), 18 deletions(-) create mode 100755 bin/sync delete mode 100755 sync.sh diff --git a/.gitattributes b/.gitattributes index 36cc349e..46ac2098 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,6 +2,7 @@ # Ignore following folder/file. /.github export-ignore +/bin export-ignore /tests export-ignore /workbench export-ignore /.gitattributes export-ignore @@ -11,7 +12,6 @@ /phpstan-baseline.neon export-ignore /phpstan.neon.dist export-ignore /phpunit.xml export-ignore -/sync.sh export-ignore /testbench.yaml export-ignore /CHANGELOG-*.md export-ignore /CODE_OF_CONDUCT.md export-ignore diff --git a/bin/sync b/bin/sync new file mode 100755 index 00000000..a5accca9 --- /dev/null +++ b/bin/sync @@ -0,0 +1,52 @@ +#!/usr/bin/env php + 'Database/Console/Factories/stubs/factory.stub', + 'pest.stub' => 'Foundation/Console/stubs/pest.stub', + 'pest.unit.stub' => 'Foundation/Console/stubs/pest.unit.stub', + 'test.stub' => 'Foundation/Console/stubs/test.stub', + 'test.unit.stub' => 'Foundation/Console/stubs/test.unit.stub', +])->transform(fn ($file) => "{$workingPath}/vendor/laravel/framework/src/Illuminate/{$file}") +->each(function ($file, $name) use ($files, $workingPath) { + $files->copy($file, "{$workingPath}/src/Console/stubs/{$name}"); +}); + +transform([ + 'use Illuminate\Database\Eloquent\Factories\Factory;' => + 'use Illuminate\Database\Eloquent\Factories\Factory;'.PHP_EOL.'use {{ namespacedModel }};', + ' /** + * Define the model\'s default state.'.PHP_EOL => ' /** + * The name of the factory\'s corresponding model. + * + * @var string + */ + protected $model = {{ model }}::class; + + /** + * Define the model\'s default state.'.PHP_EOL, +], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/factory.stub")); + +transform([ + 'use Tests\TestCase;' => 'use NamespacedDummyTestCase;', + 'class {{ class }} extends TestCase' => 'class {{ class }} extends DummyTestCase', +], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/test.stub")); + +transform([ + 'use PHPUnit\Framework\TestCase;' => 'use NamespacedDummyTestCase;', + 'class {{ class }} extends TestCase' => 'class {{ class }} extends DummyTestCase', +], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/test.unit.stub")); + +/** +## Fixes namespace. +awk '{sub(/class {{ class }} extends TestCase/,"class {{ class }} extends DummyTestCase")}1' src/Console/stubs/test.unit.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.unit.stub +awk '{sub(/use Tests\\TestCase/,"use NamespacedDummyTestCase")}1' src/Console/stubs/test.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.stub +awk '{sub(/class {{ class }} extends TestCase/,"class {{ class }} extends DummyTestCase")}1' src/Console/stubs/test.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.stub + + */ diff --git a/src/Console/stubs/factory.stub b/src/Console/stubs/factory.stub index 3995e1d2..1f9acb8f 100644 --- a/src/Console/stubs/factory.stub +++ b/src/Console/stubs/factory.stub @@ -22,7 +22,7 @@ class {{ factory }}Factory extends Factory * * @return array */ - public function definition(): array + public function definition() { return [ // diff --git a/sync.sh b/sync.sh deleted file mode 100755 index 6a7db3b9..00000000 --- a/sync.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# Database -cp -rf vendor/laravel/framework/src/Illuminate/Database/Console/Factories/stubs/*.stub src/Console/stubs/ - -# Foundation -cp -rf vendor/laravel/framework/src/Illuminate/Foundation/Console/stubs/pest.stub src/Console/stubs/ -cp -rf vendor/laravel/framework/src/Illuminate/Foundation/Console/stubs/pest.unit.stub src/Console/stubs/ -cp -rf vendor/laravel/framework/src/Illuminate/Foundation/Console/stubs/test.stub src/Console/stubs/ -cp -rf vendor/laravel/framework/src/Illuminate/Foundation/Console/stubs/test.unit.stub src/Console/stubs/ - -## Fixes namespace. -awk '{sub(/use PHPUnit\\Framework\\TestCase/,"use NamespacedDummyTestCase")}1' src/Console/stubs/test.unit.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.unit.stub -awk '{sub(/class {{ class }} extends TestCase/,"class {{ class }} extends DummyTestCase")}1' src/Console/stubs/test.unit.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.unit.stub -awk '{sub(/use Tests\\TestCase/,"use NamespacedDummyTestCase")}1' src/Console/stubs/test.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.stub -awk '{sub(/class {{ class }} extends TestCase/,"class {{ class }} extends DummyTestCase")}1' src/Console/stubs/test.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.stub From 5196b4639591ea515ea14c85ced654ca194a4568 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 20 Sep 2023 11:54:05 +0800 Subject: [PATCH 11/28] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/sync b/bin/sync index c1e4c8e0..1720c279 100755 --- a/bin/sync +++ b/bin/sync @@ -21,13 +21,15 @@ Illuminate\Support\Collection::make([ }); transform([ - 'use Illuminate\Database\Eloquent\Factories\Factory;' => - 'use Illuminate\Database\Eloquent\Factories\Factory;'.PHP_EOL.'use {{ namespacedModel }};', + 'use Illuminate\Database\Eloquent\Factories\Factory;' => 'use Illuminate\Database\Eloquent\Factories\Factory;'.PHP_EOL.'use {{ namespacedModel }};', + ' * @extends \Illuminate\Database\Eloquent\Factories\Factory<\{{ namespacedModel }}>' => ' * @template TModel of \{{ namespacedModel }} + * + * @extends \Illuminate\Database\Eloquent\Factories\Factory', ' /** * Define the model\'s default state.'.PHP_EOL => ' /** * The name of the factory\'s corresponding model. * - * @var string + * @var class-string */ protected $model = {{ model }}::class; From 7979c6c4bb0ccf383b2256aa6da6aca70ba38808 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 20 Sep 2023 12:05:27 +0800 Subject: [PATCH 12/28] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 8 -------- 1 file changed, 8 deletions(-) diff --git a/bin/sync b/bin/sync index a5accca9..3eaff1cd 100755 --- a/bin/sync +++ b/bin/sync @@ -42,11 +42,3 @@ transform([ 'use PHPUnit\Framework\TestCase;' => 'use NamespacedDummyTestCase;', 'class {{ class }} extends TestCase' => 'class {{ class }} extends DummyTestCase', ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/test.unit.stub")); - -/** -## Fixes namespace. -awk '{sub(/class {{ class }} extends TestCase/,"class {{ class }} extends DummyTestCase")}1' src/Console/stubs/test.unit.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.unit.stub -awk '{sub(/use Tests\\TestCase/,"use NamespacedDummyTestCase")}1' src/Console/stubs/test.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.stub -awk '{sub(/class {{ class }} extends TestCase/,"class {{ class }} extends DummyTestCase")}1' src/Console/stubs/test.stub > src/Console/stubs/temp.stub && mv src/Console/stubs/temp.stub src/Console/stubs/test.stub - - */ From 30ee96760fd10e4e0aea84f08910176c152f6b84 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 20 Sep 2023 22:43:36 +0800 Subject: [PATCH 13/28] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 30 +++++ src/Console/FactoryMakeCommand.php | 2 +- src/Console/UserFactoryMakeCommand.php | 110 ++++++++++++++++++ src/Console/UserModelMakeCommand.php | 82 +++++++++++++ src/Console/stubs/user-factory.stub | 48 ++++++++ src/Console/stubs/user-model.stub | 44 +++++++ src/LaravelServiceProvider.php | 33 ++++++ ...nelTest.php => ChannelMakeCommandTest.php} | 2 +- .../Console/UserFactoryMakeCommandTest.php | 28 +++++ .../Console/UserModelMakeCommandTest.php | 25 ++++ 10 files changed, 402 insertions(+), 2 deletions(-) create mode 100644 src/Console/UserFactoryMakeCommand.php create mode 100644 src/Console/UserModelMakeCommand.php create mode 100644 src/Console/stubs/user-factory.stub create mode 100644 src/Console/stubs/user-model.stub rename tests/Feature/Console/{ChannelTest.php => ChannelMakeCommandTest.php} (92%) create mode 100644 tests/Feature/Console/UserFactoryMakeCommandTest.php create mode 100644 tests/Feature/Console/UserModelMakeCommandTest.php diff --git a/bin/sync b/bin/sync index 3eaff1cd..b92d437a 100755 --- a/bin/sync +++ b/bin/sync @@ -42,3 +42,33 @@ transform([ 'use PHPUnit\Framework\TestCase;' => 'use NamespacedDummyTestCase;', 'class {{ class }} extends TestCase' => 'class {{ class }} extends DummyTestCase', ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/test.unit.stub")); + +$files->deleteDirectory("{$workingPath}/skeleton"); + +Symfony\Component\Process\Process::fromShellCommandline( + 'composer create-project "laravel/laravel:9.x-dev" skeleton --no-install --no-scripts --no-plugins --quiet', $workingPath +)->mustRun(); + +$files->copy("{$workingPath}/skeleton/app/Models/User.php", "{$workingPath}/src/Console/stubs/user-model.stub"); +transform([ + 'namespace App\Models;' => 'namespace {{ namespace }};', +], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/user-model.stub")); + +$files->copy("{$workingPath}/skeleton/database/factories/UserFactory.php", "{$workingPath}/src/Console/stubs/user-factory.stub"); +transform([ + 'namespace Database\Factories;' => 'namespace {{ factoryNamespace }};', + 'use Illuminate\Support\Str;'.PHP_EOL => 'use Illuminate\Support\Str;'.PHP_EOL.'use {{ namespacedModel }};'.PHP_EOL, + '\Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>' => '\Illuminate\Database\Eloquent\Factories\Factory<\{{ namespacedModel }}>', + ' /** + * Define the model\'s default state.' => ' /** + * The name of the factory\'s corresponding model. + * + * @var string + */ + protected $model = {{ model }}::class; + + /** + * Define the model\'s default state.' +], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/user-factory.stub")); + +$files->deleteDirectory("{$workingPath}/skeleton"); diff --git a/src/Console/FactoryMakeCommand.php b/src/Console/FactoryMakeCommand.php index 7b486caa..2dcb792f 100644 --- a/src/Console/FactoryMakeCommand.php +++ b/src/Console/FactoryMakeCommand.php @@ -11,7 +11,7 @@ /** * @see https://github.com/laravel/framework/blob/9.x/src/Illuminate/Database/Console/Factories/FactoryMakeCommand.php */ -#[AsCommand(name: 'make:factory', description: 'Create a new model factory aa')] +#[AsCommand(name: 'make:factory', description: 'Create a new model factory')] class FactoryMakeCommand extends \Illuminate\Database\Console\Factories\FactoryMakeCommand { use CodeGenerator; diff --git a/src/Console/UserFactoryMakeCommand.php b/src/Console/UserFactoryMakeCommand.php new file mode 100644 index 00000000..15785244 --- /dev/null +++ b/src/Console/UserFactoryMakeCommand.php @@ -0,0 +1,110 @@ +resolveStubPath('/stubs/user-factory.stub'); + } + + /** + * Resolve the default fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveDefaultStubPath($stub) + { + return __DIR__.$stub; + } + + /** + * Get the root namespace for the class. + * + * @return string + */ + protected function rootNamespace() + { + return $this->generatorPreset()->factoryNamespace(); + } + + /** + * Get the generator preset source path. + */ + protected function getGeneratorSourcePath(): string + { + return $this->generatorPreset()->factoryPath(); + } + + /** + * Handle generating code. + */ + public function generatingCode(string $stub, string $className): string + { + $preset = $this->generatorPreset(); + + return str_replace([ + '{{ factoryNamespace }}', + '{{ namespacedModel }}', + '{{ model }}', + ], [ + rtrim($preset->factoryNamespace(), '\\'), + $preset->modelNamespace().'User', + 'User', + ], $stub); + } + + /** + * Get the desired class name from the input. + * + * @return string + */ + protected function getNameInput() + { + return 'UserFactory'; + } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return []; + } + + /** + * 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'], + ]; + } +} diff --git a/src/Console/UserModelMakeCommand.php b/src/Console/UserModelMakeCommand.php new file mode 100644 index 00000000..105b2b68 --- /dev/null +++ b/src/Console/UserModelMakeCommand.php @@ -0,0 +1,82 @@ +resolveStubPath('/stubs/user-model.stub'); + } + + /** + * Resolve the default fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveDefaultStubPath($stub) + { + return __DIR__.$stub; + } + + /** + * Get the default namespace for the class. + */ + public function getDefaultNamespace($rootNamespace) + { + return rtrim($this->generatorPreset()->modelNamespace(), '\\'); + } + + /** + * Get the desired class name from the input. + * + * @return string + */ + protected function getNameInput() + { + return 'User'; + } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return []; + } + + /** + * 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'], + ]; + } +} diff --git a/src/Console/stubs/user-factory.stub b/src/Console/stubs/user-factory.stub new file mode 100644 index 00000000..b7caa07c --- /dev/null +++ b/src/Console/stubs/user-factory.stub @@ -0,0 +1,48 @@ + + */ +class UserFactory extends Factory +{ + /** + * The name of the factory's corresponding model. + * + * @var string + */ + protected $model = {{ model }}::class; + + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + 'name' => fake()->name(), + 'email' => fake()->unique()->safeEmail(), + 'email_verified_at' => now(), + 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'remember_token' => Str::random(10), + ]; + } + + /** + * Indicate that the model's email address should be unverified. + * + * @return static + */ + public function unverified() + { + return $this->state(fn (array $attributes) => [ + 'email_verified_at' => null, + ]); + } +} diff --git a/src/Console/stubs/user-model.stub b/src/Console/stubs/user-model.stub new file mode 100644 index 00000000..0c890dd8 --- /dev/null +++ b/src/Console/stubs/user-model.stub @@ -0,0 +1,44 @@ + + */ + protected $fillable = [ + 'name', + 'email', + 'password', + ]; + + /** + * The attributes that should be hidden for serialization. + * + * @var array + */ + protected $hidden = [ + 'password', + 'remember_token', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'email_verified_at' => 'datetime', + ]; +} diff --git a/src/LaravelServiceProvider.php b/src/LaravelServiceProvider.php index e8022177..68f26f99 100644 --- a/src/LaravelServiceProvider.php +++ b/src/LaravelServiceProvider.php @@ -74,6 +74,9 @@ public function register() $this->registerQueueTableCommand(); $this->registerSessionTableCommand(); + $this->registerUserFactoryMakeCommand(); + $this->registerUserModelMakeCommand(); + $this->commands([ Console\CastMakeCommand::class, Console\ChannelMakeCommand::class, @@ -105,6 +108,9 @@ public function register() Console\NotificationTableCommand::class, Console\QueueTableCommand::class, Console\SessionTableCommand::class, + + Console\UserFactoryMakeCommand::class, + Console\UserModelMakeCommand::class, ]); } @@ -463,6 +469,30 @@ protected function registerSessionTableCommand() }); } + /** + * Register the command. + * + * @return void + */ + protected function registerUserFactoryMakeCommand() + { + $this->app->singleton(Console\UserFactoryMakeCommand::class, function ($app) { + return new Console\UserFactoryMakeCommand($app['files']); + }); + } + + /** + * Register the command. + * + * @return void + */ + protected function registerUserModelMakeCommand() + { + $this->app->singleton(Console\UserModelMakeCommand::class, function ($app) { + return new Console\UserModelMakeCommand($app['files']); + }); + } + /** * Get the services provided by the provider. * @@ -530,6 +560,9 @@ public function provides() Console\QueueTableCommand::class, SessionTableCommand::class, Console\SessionTableCommand::class, + + Console\UserFactoryMakeCommand::class, + Console\UserModelMakeCommand::class, ]; } } diff --git a/tests/Feature/Console/ChannelTest.php b/tests/Feature/Console/ChannelMakeCommandTest.php similarity index 92% rename from tests/Feature/Console/ChannelTest.php rename to tests/Feature/Console/ChannelMakeCommandTest.php index 79c68ba7..8e48c843 100644 --- a/tests/Feature/Console/ChannelTest.php +++ b/tests/Feature/Console/ChannelMakeCommandTest.php @@ -4,7 +4,7 @@ use Orchestra\Canvas\Tests\Feature\TestCase; -class ChannelTest extends TestCase +class ChannelMakeCommandTest extends TestCase { protected $files = [ 'app/Broadcasting/FooChannel.php', diff --git a/tests/Feature/Console/UserFactoryMakeCommandTest.php b/tests/Feature/Console/UserFactoryMakeCommandTest.php new file mode 100644 index 00000000..029a85da --- /dev/null +++ b/tests/Feature/Console/UserFactoryMakeCommandTest.php @@ -0,0 +1,28 @@ +artisan('make:user-factory', ['--preset' => 'canvas']) + ->assertSuccessful(); + + $this->assertFileContains([ + 'namespace Database\Factories;', + 'use Illuminate\Database\Eloquent\Factories\Factory;', + 'use App\Models\User;', + '* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>', + 'class UserFactory extends Factory', + 'protected $model = User::class;', + ], 'database/factories/UserFactory.php'); + } +} diff --git a/tests/Feature/Console/UserModelMakeCommandTest.php b/tests/Feature/Console/UserModelMakeCommandTest.php new file mode 100644 index 00000000..a0930fea --- /dev/null +++ b/tests/Feature/Console/UserModelMakeCommandTest.php @@ -0,0 +1,25 @@ +artisan('make:user-model', ['--preset' => 'canvas']) + ->assertSuccessful(); + + $this->assertFileContains([ + 'namespace App\Models;', + 'use Illuminate\Foundation\Auth\User as Authenticatable;', + 'class User extends Authenticatable', + ], 'app/Models/User.php'); + } +} From 8232da2e8608028907bdef023227c8376f3f6d15 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 20 Sep 2023 23:03:01 +0800 Subject: [PATCH 14/28] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/sync b/bin/sync index be27e5ac..4853b7f1 100755 --- a/bin/sync +++ b/bin/sync @@ -5,6 +5,10 @@ $workingPath = getcwd(); require __DIR__.'/../vendor/autoload.php'; +use function Laravel\Prompts\{spin}; + +spin(function () use ($workingPath) { + $files = new Illuminate\Filesystem\Filesystem(); Illuminate\Support\Collection::make([ @@ -90,3 +94,5 @@ transform([ ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/user-factory.stub")); $files->deleteDirectory("{$workingPath}/skeleton"); + +}, 'Sync project'); From bfe99fa35900aa8949e5e250ef2d02e6acfb971e Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 21 Sep 2023 09:24:36 +0800 Subject: [PATCH 15/28] wip --- bin/sync | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bin/sync b/bin/sync index 4853b7f1..be27e5ac 100755 --- a/bin/sync +++ b/bin/sync @@ -5,10 +5,6 @@ $workingPath = getcwd(); require __DIR__.'/../vendor/autoload.php'; -use function Laravel\Prompts\{spin}; - -spin(function () use ($workingPath) { - $files = new Illuminate\Filesystem\Filesystem(); Illuminate\Support\Collection::make([ @@ -94,5 +90,3 @@ transform([ ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/user-factory.stub")); $files->deleteDirectory("{$workingPath}/skeleton"); - -}, 'Sync project'); From ccfbf44bfd2b959fa05b6ad5c770c89641991edc Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 25 Sep 2023 16:18:28 +0800 Subject: [PATCH 16/28] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/ProviderMakeCommand.php | 11 ++++++++++ .../Console/ProviderMakeCommandTest.php | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Console/ProviderMakeCommand.php b/src/Console/ProviderMakeCommand.php index fa5ee589..e7a71ea8 100644 --- a/src/Console/ProviderMakeCommand.php +++ b/src/Console/ProviderMakeCommand.php @@ -60,4 +60,15 @@ protected function rootNamespace() { return $this->rootNamespaceUsingCanvas(); } + + /** + * Get the default namespace for the class. + * + * @param string $rootNamespace + * @return string + */ + protected function getDefaultNamespace($rootNamespace) + { + return rtrim($this->generatorPreset()->providerNamespace(), '\\'); + } } diff --git a/tests/Feature/Console/ProviderMakeCommandTest.php b/tests/Feature/Console/ProviderMakeCommandTest.php index 3df4122e..3abc9253 100644 --- a/tests/Feature/Console/ProviderMakeCommandTest.php +++ b/tests/Feature/Console/ProviderMakeCommandTest.php @@ -2,12 +2,14 @@ namespace Orchestra\Canvas\Tests\Feature\Console; +use Orchestra\Canvas\Presets\Laravel; use Orchestra\Canvas\Tests\Feature\TestCase; class ProviderMakeCommandTest extends TestCase { protected $files = [ 'app/Providers/FooServiceProvider.php', + 'app/FooServiceProvider.php', ]; /** @test */ @@ -24,4 +26,23 @@ public function it_can_generate_service_provider_file() 'public function boot()', ], 'app/Providers/FooServiceProvider.php'); } + + /** @test */ + public function it_can_generate_service_provider_file_with_custom_namespace() + { + $this->instance('orchestra.canvas', new Laravel( + ['namespace' => 'App', 'provider' => ['namespace' => 'App']], $this->app->basePath() + )); + + $this->artisan('make:provider', ['name' => 'FooServiceProvider', '--preset' => 'canvas']) + ->assertSuccessful(); + + $this->assertFileContains([ + 'namespace App;', + 'use Illuminate\Support\ServiceProvider;', + 'class FooServiceProvider extends ServiceProvider', + 'public function register()', + 'public function boot()', + ], 'app/FooServiceProvider.php'); + } } From 4a55d02f70a51007400ee6a51d0ba3a2c7a904c1 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 25 Sep 2023 16:22:10 +0800 Subject: [PATCH 17/28] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/sync b/bin/sync index be27e5ac..22202404 100755 --- a/bin/sync +++ b/bin/sync @@ -5,8 +5,11 @@ $workingPath = getcwd(); require __DIR__.'/../vendor/autoload.php'; +$input = new Symfony\Component\Console\Input\ArgvInput(); $files = new Illuminate\Filesystem\Filesystem(); +$version = ($input->hasParameterOption('--dev') && $input->hasParameterOption('--stable') === false) ? '10.x-dev' : '^10.0'; + Illuminate\Support\Collection::make([ 'factory.stub' => 'Database/Console/Factories/stubs/factory.stub', 'pest.stub' => 'Foundation/Console/stubs/pest.stub', @@ -64,7 +67,7 @@ if ($files->isDirectory("{$workingPath}/vendor/laravel/framework/tests")) { $files->deleteDirectory("{$workingPath}/skeleton"); Symfony\Component\Process\Process::fromShellCommandline( - 'composer create-project "laravel/laravel:10.x-dev" skeleton --no-install --no-scripts --no-plugins --quiet', $workingPath + 'composer create-project "laravel/laravel:'.$version.'" skeleton --no-install --no-scripts --no-plugins --quiet', $workingPath )->mustRun(); $files->copy("{$workingPath}/skeleton/app/Models/User.php", "{$workingPath}/src/Console/stubs/user-model.stub"); From 396675213cc5af5a69846b091315f1440f5e1fb2 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 25 Sep 2023 16:27:19 +0800 Subject: [PATCH 18/28] wip Signed-off-by: Mior Muhammad Zaki --- tests/Feature/Console/ControllerMakeCommandTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Feature/Console/ControllerMakeCommandTest.php b/tests/Feature/Console/ControllerMakeCommandTest.php index df257e19..032e3ec2 100644 --- a/tests/Feature/Console/ControllerMakeCommandTest.php +++ b/tests/Feature/Console/ControllerMakeCommandTest.php @@ -62,7 +62,7 @@ public function it_can_generate_controller_with_invokable_options_file() /** @test */ public function it_can_generate_controller_with_model_options_file() { - $this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Foo', '--no-interaction' => true, '--preset' => 'canvas']) + $this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Foo', '--preset' => 'canvas']) ->expectsQuestion('A App\Models\Foo model does not exist. Do you want to generate it?', false) ->assertSuccessful(); @@ -82,7 +82,7 @@ public function it_can_generate_controller_with_model_options_file() /** @test */ public function it_can_generate_controller_with_model_with_parent_options_file() { - $this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Bar', '--parent' => 'Foo', '--no-interaction' => true, '--preset' => 'canvas']) + $this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Bar', '--parent' => 'Foo', '--preset' => 'canvas']) ->expectsQuestion('A App\Models\Foo model does not exist. Do you want to generate it?', false) ->expectsQuestion('A App\Models\Bar model does not exist. Do you want to generate it?', false) ->assertSuccessful(); @@ -108,7 +108,7 @@ public function it_can_generate_controller_with_model_options_file_with_custom_m ['namespace' => 'App', 'model' => ['namespace' => 'App\Model']], $this->app->basePath() )); - $this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Foo', '--no-interaction' => true, '--preset' => 'canvas']) + $this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Foo', '--preset' => 'canvas']) ->expectsQuestion('A App\Model\Foo model does not exist. Do you want to generate it?', false) ->assertSuccessful(); @@ -132,7 +132,7 @@ public function it_can_generate_controller_with_model_with_parent_options_file_w ['namespace' => 'App', 'model' => ['namespace' => 'App\Model']], $this->app->basePath() )); - $this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Bar', '--parent' => 'Foo', '--no-interaction' => true, '--preset' => 'canvas']) + $this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Bar', '--parent' => 'Foo', '--preset' => 'canvas']) ->expectsQuestion('A App\Model\Foo model does not exist. Do you want to generate it?', false) ->expectsQuestion('A App\Model\Bar model does not exist. Do you want to generate it?', false) ->assertSuccessful(); @@ -197,7 +197,7 @@ public function it_can_generate_controller_file_can_handle_invokable_options_ign /** @test */ public function it_can_generate_controller_with_model_and_api_options_file() { - $this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Foo', '--api' => true, '--no-interaction' => true, '--preset' => 'canvas']) + $this->artisan('make:controller', ['name' => 'FooController', '--model' => 'Foo', '--api' => true, '--preset' => 'canvas']) ->expectsQuestion('A App\Models\Foo model does not exist. Do you want to generate it?', false) ->assertSuccessful(); From eef3eb34e263cc462c0eb284ba002f2829b04e2a Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 25 Sep 2023 16:37:12 +0800 Subject: [PATCH 19/28] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 722aeee6..f36aec3c 100644 --- a/composer.json +++ b/composer.json @@ -81,5 +81,6 @@ "@test" ] }, + "prefer-stable": true, "minimum-stability": "dev" } From 636f8278c26799ace3a579562943726a5ab43262 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 26 Sep 2023 23:20:36 +0800 Subject: [PATCH 20/28] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index cc02b880..aeab4cab 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -18,6 +18,7 @@ jobs: php: - 8.1 - 8.2 + - 8.3 dependencies: - "highest" - "lowest" From d2d79a97c78d05b09feace0a05739f7813b69202 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 26 Sep 2023 23:21:28 +0800 Subject: [PATCH 21/28] wip Signed-off-by: Mior Muhammad Zaki --- src/LaravelServiceProvider.php | 64 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/LaravelServiceProvider.php b/src/LaravelServiceProvider.php index 60005d2d..90fc1a3a 100644 --- a/src/LaravelServiceProvider.php +++ b/src/LaravelServiceProvider.php @@ -124,7 +124,7 @@ public function register() */ protected function registerCastMakeCommand() { - $this->app->singleton(CastMakeCommand::class, function ($app) { + $this->app->singleton(CastMakeCommand::class, static function ($app) { return new Console\CastMakeCommand($app['files']); }); } @@ -136,7 +136,7 @@ protected function registerCastMakeCommand() */ protected function registerChannelMakeCommand() { - $this->app->singleton(ChannelMakeCommand::class, function ($app) { + $this->app->singleton(ChannelMakeCommand::class, static function ($app) { return new Console\ChannelMakeCommand($app['files']); }); } @@ -148,7 +148,7 @@ protected function registerChannelMakeCommand() */ protected function registerComponentMakeCommand() { - $this->app->singleton(ComponentMakeCommand::class, function ($app) { + $this->app->singleton(ComponentMakeCommand::class, static function ($app) { return new Console\ComponentMakeCommand($app['files']); }); } @@ -160,7 +160,7 @@ protected function registerComponentMakeCommand() */ protected function registerConsoleMakeCommand() { - $this->app->singleton(ConsoleMakeCommand::class, function ($app) { + $this->app->singleton(ConsoleMakeCommand::class, static function ($app) { return new Console\ConsoleMakeCommand($app['files']); }); } @@ -172,7 +172,7 @@ protected function registerConsoleMakeCommand() */ protected function registerControllerMakeCommand() { - $this->app->singleton(ControllerMakeCommand::class, function ($app) { + $this->app->singleton(ControllerMakeCommand::class, static function ($app) { return new Console\ControllerMakeCommand($app['files']); }); } @@ -184,7 +184,7 @@ protected function registerControllerMakeCommand() */ protected function registerEventMakeCommand() { - $this->app->singleton(EventMakeCommand::class, function ($app) { + $this->app->singleton(EventMakeCommand::class, static function ($app) { return new Console\EventMakeCommand($app['files']); }); } @@ -196,7 +196,7 @@ protected function registerEventMakeCommand() */ protected function registerExceptionMakeCommand() { - $this->app->singleton(ExceptionMakeCommand::class, function ($app) { + $this->app->singleton(ExceptionMakeCommand::class, static function ($app) { return new Console\ExceptionMakeCommand($app['files']); }); } @@ -208,7 +208,7 @@ protected function registerExceptionMakeCommand() */ protected function registerFactoryMakeCommand() { - $this->app->singleton(FactoryMakeCommand::class, function ($app) { + $this->app->singleton(FactoryMakeCommand::class, static function ($app) { return new Console\FactoryMakeCommand($app['files']); }); } @@ -220,7 +220,7 @@ protected function registerFactoryMakeCommand() */ protected function registerJobMakeCommand() { - $this->app->singleton(JobMakeCommand::class, function ($app) { + $this->app->singleton(JobMakeCommand::class, static function ($app) { return new Console\JobMakeCommand($app['files']); }); } @@ -232,7 +232,7 @@ protected function registerJobMakeCommand() */ protected function registerListenerMakeCommand() { - $this->app->singleton(ListenerMakeCommand::class, function ($app) { + $this->app->singleton(ListenerMakeCommand::class, static function ($app) { return new Console\ListenerMakeCommand($app['files']); }); } @@ -244,7 +244,7 @@ protected function registerListenerMakeCommand() */ protected function registerMailMakeCommand() { - $this->app->singleton(MailMakeCommand::class, function ($app) { + $this->app->singleton(MailMakeCommand::class, static function ($app) { return new Console\MailMakeCommand($app['files']); }); } @@ -256,7 +256,7 @@ protected function registerMailMakeCommand() */ protected function registerMiddlewareMakeCommand() { - $this->app->singleton(MiddlewareMakeCommand::class, function ($app) { + $this->app->singleton(MiddlewareMakeCommand::class, static function ($app) { return new Console\MiddlewareMakeCommand($app['files']); }); } @@ -268,7 +268,7 @@ protected function registerMiddlewareMakeCommand() */ protected function registerMigrateMakeCommand() { - $this->app->singleton(MigrateMakeCommand::class, function ($app) { + $this->app->singleton(MigrateMakeCommand::class, static function ($app) { // Once we have the migration creator registered, we will create the command // and inject the creator. The creator is responsible for the actual file // creation of the migrations, and may be extended by these developers. @@ -287,7 +287,7 @@ protected function registerMigrateMakeCommand() */ protected function registerModelMakeCommand() { - $this->app->singleton(ModelMakeCommand::class, function ($app) { + $this->app->singleton(ModelMakeCommand::class, static function ($app) { return new Console\ModelMakeCommand($app['files']); }); } @@ -299,7 +299,7 @@ protected function registerModelMakeCommand() */ protected function registerNotificationMakeCommand() { - $this->app->singleton(NotificationMakeCommand::class, function ($app) { + $this->app->singleton(NotificationMakeCommand::class, static function ($app) { return new Console\NotificationMakeCommand($app['files']); }); } @@ -311,7 +311,7 @@ protected function registerNotificationMakeCommand() */ protected function registerObserverMakeCommand() { - $this->app->singleton(ObserverMakeCommand::class, function ($app) { + $this->app->singleton(ObserverMakeCommand::class, static function ($app) { return new Console\ObserverMakeCommand($app['files']); }); } @@ -323,7 +323,7 @@ protected function registerObserverMakeCommand() */ protected function registerPolicyMakeCommand() { - $this->app->singleton(PolicyMakeCommand::class, function ($app) { + $this->app->singleton(PolicyMakeCommand::class, static function ($app) { return new Console\PolicyMakeCommand($app['files']); }); } @@ -335,7 +335,7 @@ protected function registerPolicyMakeCommand() */ protected function registerProviderMakeCommand() { - $this->app->singleton(ProviderMakeCommand::class, function ($app) { + $this->app->singleton(ProviderMakeCommand::class, static function ($app) { return new Console\ProviderMakeCommand($app['files']); }); } @@ -347,7 +347,7 @@ protected function registerProviderMakeCommand() */ protected function registerRequestMakeCommand() { - $this->app->singleton(RequestMakeCommand::class, function ($app) { + $this->app->singleton(RequestMakeCommand::class, static function ($app) { return new Console\RequestMakeCommand($app['files']); }); } @@ -359,7 +359,7 @@ protected function registerRequestMakeCommand() */ protected function registerResourceMakeCommand() { - $this->app->singleton(ResourceMakeCommand::class, function ($app) { + $this->app->singleton(ResourceMakeCommand::class, static function ($app) { return new Console\ResourceMakeCommand($app['files']); }); } @@ -371,7 +371,7 @@ protected function registerResourceMakeCommand() */ protected function registerRuleMakeCommand() { - $this->app->singleton(RuleMakeCommand::class, function ($app) { + $this->app->singleton(RuleMakeCommand::class, static function ($app) { return new Console\RuleMakeCommand($app['files']); }); } @@ -383,7 +383,7 @@ protected function registerRuleMakeCommand() */ protected function registerScopeMakeCommand() { - $this->app->singleton(ScopeMakeCommand::class, function ($app) { + $this->app->singleton(ScopeMakeCommand::class, static function ($app) { return new Console\ScopeMakeCommand($app['files']); }); } @@ -395,7 +395,7 @@ protected function registerScopeMakeCommand() */ protected function registerSeederMakeCommand() { - $this->app->singleton(SeederMakeCommand::class, function ($app) { + $this->app->singleton(SeederMakeCommand::class, static function ($app) { return new Console\SeederMakeCommand($app['files']); }); } @@ -407,7 +407,7 @@ protected function registerSeederMakeCommand() */ protected function registerTestMakeCommand() { - $this->app->singleton(TestMakeCommand::class, function ($app) { + $this->app->singleton(TestMakeCommand::class, static function ($app) { return new Console\TestMakeCommand($app['files']); }); } @@ -419,7 +419,7 @@ protected function registerTestMakeCommand() */ protected function registerViewMakeCommand() { - $this->app->singleton(ViewMakeCommand::class, function ($app) { + $this->app->singleton(ViewMakeCommand::class, static function ($app) { return new Console\ViewMakeCommand($app['files']); }); } @@ -431,7 +431,7 @@ protected function registerViewMakeCommand() */ protected function registerNotificationTableCommand() { - $this->app->singleton(NotificationTableCommand::class, function ($app) { + $this->app->singleton(NotificationTableCommand::class, static function ($app) { return new Console\NotificationTableCommand($app['files'], $app['composer']); }); } @@ -443,7 +443,7 @@ protected function registerNotificationTableCommand() */ protected function registerQueueBatchesTableCommand() { - $this->app->singleton(BatchesTableCommand::class, function ($app) { + $this->app->singleton(BatchesTableCommand::class, static function ($app) { return new Console\BatchesTableCommand($app['files'], $app['composer']); }); } @@ -455,7 +455,7 @@ protected function registerQueueBatchesTableCommand() */ protected function registerQueueFailedTableCommand() { - $this->app->singleton(FailedTableCommand::class, function ($app) { + $this->app->singleton(FailedTableCommand::class, static function ($app) { return new Console\FailedTableCommand($app['files'], $app['composer']); }); } @@ -467,7 +467,7 @@ protected function registerQueueFailedTableCommand() */ protected function registerQueueTableCommand() { - $this->app->singleton(QueueTableCommand::class, function ($app) { + $this->app->singleton(QueueTableCommand::class, static function ($app) { return new Console\QueueTableCommand($app['files'], $app['composer']); }); } @@ -479,7 +479,7 @@ protected function registerQueueTableCommand() */ protected function registerSessionTableCommand() { - $this->app->singleton(SessionTableCommand::class, function ($app) { + $this->app->singleton(SessionTableCommand::class, static function ($app) { return new Console\SessionTableCommand($app['files'], $app['composer']); }); } @@ -491,7 +491,7 @@ protected function registerSessionTableCommand() */ protected function registerUserFactoryMakeCommand() { - $this->app->singleton(Console\UserFactoryMakeCommand::class, function ($app) { + $this->app->singleton(Console\UserFactoryMakeCommand::class, static function ($app) { return new Console\UserFactoryMakeCommand($app['files']); }); } @@ -503,7 +503,7 @@ protected function registerUserFactoryMakeCommand() */ protected function registerUserModelMakeCommand() { - $this->app->singleton(Console\UserModelMakeCommand::class, function ($app) { + $this->app->singleton(Console\UserModelMakeCommand::class, static function ($app) { return new Console\UserModelMakeCommand($app['files']); }); } From a534d6951e2b5d555d69822d27fcbf32c3338636 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 27 Sep 2023 09:39:17 +0800 Subject: [PATCH 22/28] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f36aec3c..56f8bb38 100644 --- a/composer.json +++ b/composer.json @@ -31,14 +31,15 @@ "php": "^8.1", "composer-runtime-api": "^2.2", "composer/semver": "^3.0", - "illuminate/database": "^10.23", - "illuminate/support": "^10.23", + "illuminate/console": "^10.25.1", + "illuminate/database": "^10.25.1", + "illuminate/support": "^10.25.1", "orchestra/canvas-core": "^8.8", "orchestra/testbench-core": "^8.11", "symfony/yaml": "^6.2" }, "require-dev": { - "laravel/framework": "^10.23", + "laravel/framework": "^10.25.1", "laravel/pint": "^1.6", "mockery/mockery": "^1.5.1", "phpstan/phpstan": "^1.10.5", From 0d53d4b69f01ab4bfbc802b4cd472ecc4e18fc84 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 3 Oct 2023 08:36:08 +0800 Subject: [PATCH 23/28] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 8 ++-- src/Console/CacheTableCommand.php | 42 +++++++++++++++++++ src/Console/NotificationTableCommand.php | 5 ++- src/Console/SessionTableCommand.php | 5 ++- src/LaravelServiceProvider.php | 17 ++++++++ .../Feature/Console/CacheTableCommandTest.php | 24 +++++++++++ workbench/tests/CacheTableCommandTest.php | 20 +++++++++ .../tests/NotificationTableCommandTest.php | 18 ++++++++ .../tests/QueueBatchesTableCommandTest.php | 18 ++++++++ .../tests/QueueFailedTableCommandTest.php | 18 ++++++++ workbench/tests/QueueTableCommandTest.php | 18 ++++++++ workbench/tests/SessionTableCommandTest.php | 18 ++++++++ 12 files changed, 203 insertions(+), 8 deletions(-) create mode 100644 src/Console/CacheTableCommand.php create mode 100644 tests/Feature/Console/CacheTableCommandTest.php create mode 100644 workbench/tests/CacheTableCommandTest.php create mode 100644 workbench/tests/NotificationTableCommandTest.php create mode 100644 workbench/tests/QueueBatchesTableCommandTest.php create mode 100644 workbench/tests/QueueFailedTableCommandTest.php create mode 100644 workbench/tests/QueueTableCommandTest.php create mode 100644 workbench/tests/SessionTableCommandTest.php diff --git a/composer.json b/composer.json index 56f8bb38..c5bdeb9e 100644 --- a/composer.json +++ b/composer.json @@ -31,15 +31,15 @@ "php": "^8.1", "composer-runtime-api": "^2.2", "composer/semver": "^3.0", - "illuminate/console": "^10.25.1", - "illuminate/database": "^10.25.1", - "illuminate/support": "^10.25.1", + "illuminate/console": "^10.26", + "illuminate/database": "^10.26", + "illuminate/support": "^10.26", "orchestra/canvas-core": "^8.8", "orchestra/testbench-core": "^8.11", "symfony/yaml": "^6.2" }, "require-dev": { - "laravel/framework": "^10.25.1", + "laravel/framework": "^10.26", "laravel/pint": "^1.6", "mockery/mockery": "^1.5.1", "phpstan/phpstan": "^1.10.5", diff --git a/src/Console/CacheTableCommand.php b/src/Console/CacheTableCommand.php new file mode 100644 index 00000000..bb0de540 --- /dev/null +++ b/src/Console/CacheTableCommand.php @@ -0,0 +1,42 @@ +addGeneratorPresetOptions(); + } + + /** + * Create a base migration file for the session. + * + * @param string $table + * @return string + */ + protected function createBaseMigration($table) + { + return $this->createBaseMigrationUsingCanvas($table); + } +} diff --git a/src/Console/NotificationTableCommand.php b/src/Console/NotificationTableCommand.php index f238d8b8..36a5891b 100644 --- a/src/Console/NotificationTableCommand.php +++ b/src/Console/NotificationTableCommand.php @@ -32,10 +32,11 @@ public function __construct(Filesystem $files, Composer $composer) /** * Create a base migration file for the notifications. * + * @param string $table * @return string */ - protected function createBaseMigration() + protected function createBaseMigration($table) { - return $this->createBaseMigrationUsingCanvas('notifications'); + return $this->createBaseMigrationUsingCanvas($table); } } diff --git a/src/Console/SessionTableCommand.php b/src/Console/SessionTableCommand.php index 9cbe0fa5..dc9a7666 100644 --- a/src/Console/SessionTableCommand.php +++ b/src/Console/SessionTableCommand.php @@ -32,10 +32,11 @@ public function __construct(Filesystem $files, Composer $composer) /** * Create a base migration file for the session. * + * @param string $table * @return string */ - protected function createBaseMigration() + protected function createBaseMigration($table) { - return $this->createBaseMigrationUsingCanvas('sessions'); + return $this->createBaseMigrationUsingCanvas($table); } } diff --git a/src/LaravelServiceProvider.php b/src/LaravelServiceProvider.php index 90fc1a3a..c39677ef 100644 --- a/src/LaravelServiceProvider.php +++ b/src/LaravelServiceProvider.php @@ -2,6 +2,7 @@ namespace Orchestra\Canvas; +use Illuminate\Cache\Console\CacheTableCommand; use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Database\Console\Factories\FactoryMakeCommand; use Illuminate\Database\Console\Migrations\MigrateMakeCommand; @@ -70,6 +71,7 @@ public function register() $this->registerTestMakeCommand(); $this->registerViewMakeCommand(); + $this->registerCacheTableCommand(); $this->registerNotificationTableCommand(); $this->registerQueueBatchesTableCommand(); $this->registerQueueFailedTableCommand(); @@ -107,6 +109,7 @@ public function register() Console\ViewMakeCommand::class, Console\BatchesTableCommand::class, + Console\CacheTableCommand::class, Console\FailedTableCommand::class, Console\NotificationTableCommand::class, Console\QueueTableCommand::class, @@ -424,6 +427,18 @@ protected function registerViewMakeCommand() }); } + /** + * Register the command. + * + * @return void + */ + protected function registerCacheTableCommand() + { + $this->app->singleton(CacheTableCommand::class, static function ($app) { + return new Console\CacheTableCommand($app['files'], $app['composer']); + }); + } + /** * Register the command. * @@ -569,6 +584,8 @@ public function provides() BatchesTableCommand::class, Console\BatchesTableCommand::class, + CacheTableCommand::class, + Console\CacheTableCommand::class, FailedTableCommand::class, Console\FailedTableCommand::class, NotificationTableCommand::class, diff --git a/tests/Feature/Console/CacheTableCommandTest.php b/tests/Feature/Console/CacheTableCommandTest.php new file mode 100644 index 00000000..5832bbd2 --- /dev/null +++ b/tests/Feature/Console/CacheTableCommandTest.php @@ -0,0 +1,24 @@ +artisan('cache:table', ['--preset' => 'canvas']) + ->assertSuccessful(); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'cache\', function (Blueprint $table) {', + 'Schema::create(\'cache_locks\', function (Blueprint $table) {', + 'Schema::dropIfExists(\'cache\');', + 'Schema::dropIfExists(\'cache_locks\');', + ], 'create_cache_table.php'); + } +} diff --git a/workbench/tests/CacheTableCommandTest.php b/workbench/tests/CacheTableCommandTest.php new file mode 100644 index 00000000..a02c35dc --- /dev/null +++ b/workbench/tests/CacheTableCommandTest.php @@ -0,0 +1,20 @@ +artisan('cache:table')->assertExitCode(0); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'cache\', function (Blueprint $table) {', + 'Schema::create(\'cache_locks\', function (Blueprint $table) {', + 'Schema::dropIfExists(\'cache\');', + 'Schema::dropIfExists(\'cache_locks\');', + ], 'create_cache_table.php'); + } +} diff --git a/workbench/tests/NotificationTableCommandTest.php b/workbench/tests/NotificationTableCommandTest.php new file mode 100644 index 00000000..cf956e49 --- /dev/null +++ b/workbench/tests/NotificationTableCommandTest.php @@ -0,0 +1,18 @@ +artisan('notifications:table')->assertExitCode(0); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'notifications\', function (Blueprint $table) {', + 'Schema::dropIfExists(\'notifications\');', + ], 'create_notifications_table.php'); + } +} diff --git a/workbench/tests/QueueBatchesTableCommandTest.php b/workbench/tests/QueueBatchesTableCommandTest.php new file mode 100644 index 00000000..d9356fc9 --- /dev/null +++ b/workbench/tests/QueueBatchesTableCommandTest.php @@ -0,0 +1,18 @@ +artisan('queue:batches-table')->assertExitCode(0); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'job_batches\', function (Blueprint $table) {', + 'Schema::dropIfExists(\'job_batches\');', + ], 'create_job_batches_table.php'); + } +} diff --git a/workbench/tests/QueueFailedTableCommandTest.php b/workbench/tests/QueueFailedTableCommandTest.php new file mode 100644 index 00000000..dd1a1d40 --- /dev/null +++ b/workbench/tests/QueueFailedTableCommandTest.php @@ -0,0 +1,18 @@ +artisan('queue:failed-table')->assertExitCode(0); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'failed_jobs\', function (Blueprint $table) {', + 'Schema::dropIfExists(\'failed_jobs\');', + ], 'create_failed_jobs_table.php'); + } +} diff --git a/workbench/tests/QueueTableCommandTest.php b/workbench/tests/QueueTableCommandTest.php new file mode 100644 index 00000000..d70b81ea --- /dev/null +++ b/workbench/tests/QueueTableCommandTest.php @@ -0,0 +1,18 @@ +artisan('queue:table')->assertExitCode(0); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'jobs\', function (Blueprint $table) {', + 'Schema::dropIfExists(\'jobs\');', + ], 'create_jobs_table.php'); + } +} diff --git a/workbench/tests/SessionTableCommandTest.php b/workbench/tests/SessionTableCommandTest.php new file mode 100644 index 00000000..cb491893 --- /dev/null +++ b/workbench/tests/SessionTableCommandTest.php @@ -0,0 +1,18 @@ +artisan('session:table')->assertExitCode(0); + + $this->assertMigrationFileContains([ + 'use Illuminate\Database\Migrations\Migration;', + 'return new class extends Migration', + 'Schema::create(\'sessions\', function (Blueprint $table) {', + 'Schema::dropIfExists(\'sessions\');', + ], 'create_sessions_table.php'); + } +} From 246833ff19f74db0b76d651eb4f36aa92d1af7d3 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 3 Oct 2023 08:44:45 +0800 Subject: [PATCH 24/28] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 2 +- src/Console/BatchesTableCommand.php | 13 ++++++++++++- src/Console/CacheTableCommand.php | 13 ++++++++++++- src/Console/FailedTableCommand.php | 13 ++++++++++++- src/Console/NotificationTableCommand.php | 13 ++++++++++++- src/Console/QueueTableCommand.php | 13 ++++++++++++- src/Console/SessionTableCommand.php | 13 ++++++++++++- 7 files changed, 73 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index c5bdeb9e..3495f9ea 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "illuminate/console": "^10.26", "illuminate/database": "^10.26", "illuminate/support": "^10.26", - "orchestra/canvas-core": "^8.8", + "orchestra/canvas-core": "^8.9", "orchestra/testbench-core": "^8.11", "symfony/yaml": "^6.2" }, diff --git a/src/Console/BatchesTableCommand.php b/src/Console/BatchesTableCommand.php index 1df3f2b3..8059f370 100644 --- a/src/Console/BatchesTableCommand.php +++ b/src/Console/BatchesTableCommand.php @@ -35,8 +35,19 @@ public function __construct(Filesystem $files, Composer $composer) * @param string $table * @return string */ - protected function createBaseMigration($table = 'job_batches') + protected function createBaseMigration($table) { return $this->createBaseMigrationUsingCanvas($table); } + + /** + * Determine whether a migration for the table already exists. + * + * @param string $table + * @return bool + */ + protected function migrationExists($table) + { + return $this->migrationExistsUsingCanvas($table); + } } diff --git a/src/Console/CacheTableCommand.php b/src/Console/CacheTableCommand.php index bb0de540..9e648cdc 100644 --- a/src/Console/CacheTableCommand.php +++ b/src/Console/CacheTableCommand.php @@ -30,7 +30,7 @@ public function __construct(Filesystem $files, Composer $composer) } /** - * Create a base migration file for the session. + * Create a base migration file for the table. * * @param string $table * @return string @@ -39,4 +39,15 @@ protected function createBaseMigration($table) { return $this->createBaseMigrationUsingCanvas($table); } + + /** + * Determine whether a migration for the table already exists. + * + * @param string $table + * @return bool + */ + protected function migrationExists($table) + { + return $this->migrationExistsUsingCanvas($table); + } } diff --git a/src/Console/FailedTableCommand.php b/src/Console/FailedTableCommand.php index 432cf6b6..fe3438df 100644 --- a/src/Console/FailedTableCommand.php +++ b/src/Console/FailedTableCommand.php @@ -35,8 +35,19 @@ public function __construct(Filesystem $files, Composer $composer) * @param string $table * @return string */ - protected function createBaseMigration($table = 'failed_jobs') + protected function createBaseMigration($table) { return $this->createBaseMigrationUsingCanvas($table); } + + /** + * Determine whether a migration for the table already exists. + * + * @param string $table + * @return bool + */ + protected function migrationExists($table) + { + return $this->migrationExistsUsingCanvas($table); + } } diff --git a/src/Console/NotificationTableCommand.php b/src/Console/NotificationTableCommand.php index 36a5891b..ab9eee2d 100644 --- a/src/Console/NotificationTableCommand.php +++ b/src/Console/NotificationTableCommand.php @@ -30,7 +30,7 @@ public function __construct(Filesystem $files, Composer $composer) } /** - * Create a base migration file for the notifications. + * Create a base migration file for the table. * * @param string $table * @return string @@ -39,4 +39,15 @@ protected function createBaseMigration($table) { return $this->createBaseMigrationUsingCanvas($table); } + + /** + * Determine whether a migration for the table already exists. + * + * @param string $table + * @return bool + */ + protected function migrationExists($table) + { + return $this->migrationExistsUsingCanvas($table); + } } diff --git a/src/Console/QueueTableCommand.php b/src/Console/QueueTableCommand.php index ed856fae..1b20e0b4 100644 --- a/src/Console/QueueTableCommand.php +++ b/src/Console/QueueTableCommand.php @@ -36,8 +36,19 @@ public function __construct(Filesystem $files, Composer $composer) * @param string $table * @return string */ - protected function createBaseMigration($table = 'jobs') + protected function createBaseMigration($table) { return $this->createBaseMigrationUsingCanvas($table); } + + /** + * Determine whether a migration for the table already exists. + * + * @param string $table + * @return bool + */ + protected function migrationExists($table) + { + return $this->migrationExistsUsingCanvas($table); + } } diff --git a/src/Console/SessionTableCommand.php b/src/Console/SessionTableCommand.php index dc9a7666..68a9f3e7 100644 --- a/src/Console/SessionTableCommand.php +++ b/src/Console/SessionTableCommand.php @@ -30,7 +30,7 @@ public function __construct(Filesystem $files, Composer $composer) } /** - * Create a base migration file for the session. + * Create a base migration file for the table. * * @param string $table * @return string @@ -39,4 +39,15 @@ protected function createBaseMigration($table) { return $this->createBaseMigrationUsingCanvas($table); } + + /** + * Determine whether a migration for the table already exists. + * + * @param string $table + * @return bool + */ + protected function migrationExists($table) + { + return $this->migrationExistsUsingCanvas($table); + } } From 4ac5d02741d8d8f683d8d14085a410e54228829f Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 6 Oct 2023 07:21:42 +0800 Subject: [PATCH 25/28] Update FUNDING.yaml --- .github/FUNDING.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yaml b/.github/FUNDING.yaml index b7ee86d4..fbf58cea 100644 --- a/.github/FUNDING.yaml +++ b/.github/FUNDING.yaml @@ -1,6 +1,6 @@ # These are supported funding model platforms -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +github: crynobone patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username From 1d4a2caf90cb38dfb3acfea00f2e118516269565 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 6 Oct 2023 12:02:24 +0800 Subject: [PATCH 26/28] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a2407618..94ce88e1 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Code Generators for Laravel Applications and Packages **Canvas** replicates all of the `make` artisan commands available in your basic Laravel application. It allows everyone to use it: * outside of Laravel installation such as when building Laravel packages. -* with Laravel by allowing few customization to the stub resolved class and namespace. +* with Laravel by allowing a few customizations to the stub resolved class and namespace. [![tests](https://github.com/orchestral/canvas/workflows/tests/badge.svg?branch=8.x)](https://github.com/orchestral/canvas/actions?query=workflow%3Atests+branch%3A8.x) [![Latest Stable Version](https://poser.pugx.org/orchestra/canvas/v/stable)](https://packagist.org/packages/orchestra/canvas) @@ -15,7 +15,7 @@ Code Generators for Laravel Applications and Packages ## Installation -To install through composer, run the following command from terminal: +To install through composer, run the following command from the terminal: composer require --dev "orchestra/canvas" @@ -47,13 +47,13 @@ As a Laravel developer, you should be familiar with the following commands: | `make:seeder` | Create a new seeder class | | `make:test` | Create a new test class | -Which can be execute via: +Which can be executed via: php artisan make:migration CreatePostsTable --create With **Canvas**, you can run the equivalent command via: - composer exec canvas make:migration CreatePostsTable -- --create + vendor/bin/canvas make:migration CreatePostsTable --create ### `canvas.yaml` Preset file @@ -63,7 +63,7 @@ To get started you can first create `canvas.yaml` in the root directory of your You can run the following command to create the file: - composer exec canvas preset laravel + vendor/bin/canvas preset laravel Which will output the following as `canvas.yaml`: @@ -80,7 +80,7 @@ model: You can run the following command to create the file: - composer exec canvas preset package + vendor/bin/canvas preset package Which will output the following as `canvas.yaml`: @@ -119,7 +119,7 @@ testing: Alternatively, you can set `--namespace` option to ensure the namespace is used in the file: - ./vendor/bin/canvas preset package --namespace="Foo\Bar" + vendor/bin/canvas preset package --namespace="Foo\Bar" ```yaml preset: package @@ -153,4 +153,4 @@ testing: ### Integration with Laravel -By default, you can always use `composer exec canvas` for Laravel and Packages environment. However, with the Package Discovery `Orchestra\Canvas\LaravelServiceProvider` will be installed automatically and override all default `make` command available via artisan so you can use it without changing anything. +By default, you can always use `composer exec canvas` for Laravel and Packages environment. However, with the Package Discovery `Orchestra\Canvas\LaravelServiceProvider` will be installed automatically and override all default `make` commands available via artisan so you can use it without changing anything. From 6c9744dfd7b37292822ee8669d47f7991e0535bf Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 6 Oct 2023 12:02:47 +0800 Subject: [PATCH 27/28] Update FUNDING.yaml --- .github/FUNDING.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yaml b/.github/FUNDING.yaml index fbf58cea..927c3771 100644 --- a/.github/FUNDING.yaml +++ b/.github/FUNDING.yaml @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl liberapay: crynobone issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username -custom: ["https://paypal.me/crynobone"] +custom: # ["https://paypal.me/crynobone"] From 397880cae191357fd998c45e5d10f005ec2da316 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sun, 8 Oct 2023 20:55:02 +0800 Subject: [PATCH 28/28] wip Signed-off-by: Mior Muhammad Zaki --- .../workflows/{update-skeleton.yaml => update-stubs.yaml} | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) rename .github/workflows/{update-skeleton.yaml => update-stubs.yaml} (85%) diff --git a/.github/workflows/update-skeleton.yaml b/.github/workflows/update-stubs.yaml similarity index 85% rename from .github/workflows/update-skeleton.yaml rename to .github/workflows/update-stubs.yaml index b3bb6ae3..3cc180e6 100644 --- a/.github/workflows/update-skeleton.yaml +++ b/.github/workflows/update-stubs.yaml @@ -1,11 +1,11 @@ -name: "update-skeleton" +name: "update-stubs" on: workflow_dispatch: jobs: update: - name: Update Skeleton + name: Update Stubs runs-on: ubuntu-latest continue-on-error: false @@ -27,4 +27,5 @@ jobs: - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 with: - commit_message: Update Skeleton + commit_message: Update Stubs +