From a6fcb87030960e2f6cf64f25dfa844d606a461dd Mon Sep 17 00:00:00 2001 From: Nasrul Hazim Bin Mohamad Date: Sat, 25 Feb 2023 09:28:37 +0800 Subject: [PATCH] Update unit test --- ...-code-style-issues.yml => fix-styling.yml} | 7 +++-- composer.json | 14 +++++----- src/Commands/LaravelActionCommand.php | 6 ++++- tests/LaravelActionTest.php | 26 ++++++++++++++++++- 4 files changed, 42 insertions(+), 11 deletions(-) rename .github/workflows/{fix-php-code-style-issues.yml => fix-styling.yml} (81%) diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-styling.yml similarity index 81% rename from .github/workflows/fix-php-code-style-issues.yml rename to .github/workflows/fix-styling.yml index 970633c..39a77e7 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-styling.yml @@ -1,6 +1,9 @@ name: Fix PHP code style issues -on: [push] +on: + push: + paths: + - '**.php' jobs: php-code-styling: @@ -13,7 +16,7 @@ jobs: ref: ${{ github.head_ref }} - name: Fix PHP code style issues - uses: aglipanci/laravel-pint-action@1.0.0 + uses: aglipanci/laravel-pint-action@2.1.0 - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 diff --git a/composer.json b/composer.json index cd46cb8..644ae0c 100644 --- a/composer.json +++ b/composer.json @@ -18,20 +18,20 @@ "require": { "php": "^8.1", "bekwoh/laravel-contract": "^1.0", - "illuminate/contracts": "^9.0", - "spatie/laravel-package-tools": "^1.13.0" + "illuminate/contracts": "^9.0|^10.0", + "spatie/laravel-package-tools": "^1.14.0" }, "require-dev": { "laravel/pint": "^1.0", - "nunomaduro/collision": "^6.0", + "nunomaduro/collision": "^7.0", "nunomaduro/larastan": "^2.0.1", - "orchestra/testbench": "^7.0", - "pestphp/pest": "^1.21", - "pestphp/pest-plugin-laravel": "^1.1", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^2.0", + "pestphp/pest-plugin-laravel": "^2.0", "phpstan/extension-installer": "^1.1", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5 | ^10.0" }, "autoload": { "psr-4": { diff --git a/src/Commands/LaravelActionCommand.php b/src/Commands/LaravelActionCommand.php index d56977c..ee1b425 100644 --- a/src/Commands/LaravelActionCommand.php +++ b/src/Commands/LaravelActionCommand.php @@ -129,7 +129,11 @@ protected function getModelNamespace() public function throwExceptionIfMissingModel() { - if (empty($this->option('model')) && ! $this->option('menu') && ! $this->option('api')) { + if (! $this->option('create-update')) { + return; + } + + if (empty($this->option('model'))) { throw new RuntimeException('Missing model option.'); } } diff --git a/tests/LaravelActionTest.php b/tests/LaravelActionTest.php index 0c5df65..4537607 100644 --- a/tests/LaravelActionTest.php +++ b/tests/LaravelActionTest.php @@ -8,10 +8,34 @@ $this->assertTrue(in_array('make:action', $commands)); }); -it('can make an action', function () { +it('can make an action with model option', function () { Artisan::call('make:action CreateOrUpdateUser --model=User'); $this->assertTrue( file_exists(base_path('app/Actions/CreateOrUpdateUser.php')) ); unlink(base_path('app/Actions/CreateOrUpdateUser.php')); }); + +it('can make an action without model option', function () { + Artisan::call('make:action CreateNewInvoice'); + $this->assertTrue( + file_exists(base_path('app/Actions/CreateNewInvoice.php')) + ); + unlink(base_path('app/Actions/CreateNewInvoice.php')); +}); + +it('can make an API action', function () { + Artisan::call('make:action StoreInvoiceDetails --api'); + $this->assertTrue( + file_exists(base_path('app/Actions/Api/StoreInvoiceDetails.php')) + ); + unlink(base_path('app/Actions/Api/StoreInvoiceDetails.php')); +}); + +it('can make a menu action', function () { + Artisan::call('make:action Sidebar --menu'); + $this->assertTrue( + file_exists(base_path('app/Actions/Builder/Menu/Sidebar.php')) + ); + unlink(base_path('app/Actions/Builder/Menu/Sidebar.php')); +});