Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .github/workflows/ci.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/code-style.yml

This file was deleted.

204 changes: 204 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
on: push
name: CI

jobs:
phpunit:
runs-on: ubuntu-24.04
timeout-minutes: 5

strategy:
fail-fast: true
matrix:
php: [ 8.0, 8.1, 8.2, 8.3, 8.4 ]
laravel: [ 7.*, 8.*, 9.*, 10.*, 11.*, 12.* ]
include:
- php: 8.0
laravel: 7.*
phpunit: 9.*
testbench: 5.*
larastan: 1.*
- php: 8.0
laravel: 8.*
phpunit: 9.*
testbench: 6.*
larastan: 1.*
- php: 8.0
laravel: 9.*
phpunit: 9.*
testbench: 7.*
larastan: 2.*

- php: 8.1
laravel: 8.*
phpunit: 9.*
testbench: 6.*
larastan: 1.*
- php: 8.1
laravel: 9.*
phpunit: 9.*
testbench: 7.*
larastan: 2.*
- php: 8.1
laravel: 10.*
phpunit: 10.*
testbench: 8.*
larastan: 2.*

- php: 8.2
laravel: 8.*
phpunit: 9.*
testbench: 6.*
larastan: 1.*
- php: 8.2
laravel: 9.*
phpunit: 9.*
testbench: 7.*
larastan: 2.*
- php: 8.2
laravel: 10.*
phpunit: 10.*
testbench: 8.*
larastan: 2.*
- php: 8.2
laravel: 11.*
phpunit: 10.*
testbench: 9.*
larastan: 2.*
- php: 8.2
laravel: 12.*
phpunit: 11.*
testbench: 10.*
larastan: 3.*

- php: 8.3
laravel: 8.*
phpunit: 9.*
testbench: 6.*
larastan: 1.*
- php: 8.3
laravel: 9.*
phpunit: 9.*
testbench: 7.*
larastan: 2.*
- php: 8.3
laravel: 10.*
phpunit: 10.*
testbench: 8.*
larastan: 2.*
- php: 8.3
laravel: 11.*
phpunit: 11.*
testbench: 9.*
larastan: 2.*
- php: 8.3
laravel: 12.*
phpunit: 11.*
testbench: 10.*
larastan: 3.*

- php: 8.4
laravel: 8.*
phpunit: 9.*
testbench: 6.*
larastan: 1.*
- php: 8.4
laravel: 9.*
phpunit: 9.*
testbench: 7.*
larastan: 2.*
- php: 8.4
laravel: 10.*
phpunit: 10.*
testbench: 8.*
larastan: 2.*
- php: 8.4
laravel: 11.*
phpunit: 11.*
testbench: 9.*
larastan: 2.*
- php: 8.4
laravel: 12.*
phpunit: 11.*
testbench: 10.*
larastan: 3.*

exclude:
- php: 8.0
laravel: 10.*
- php: 8.0
laravel: 11.*
- php: 8.0
laravel: 12.*
- php: 8.1
laravel: 7.*
- php: 8.1
laravel: 11.*
- php: 8.1
laravel: 12.*
- php: 8.2
laravel: 7.*
- php: 8.3
laravel: 7.*
- php: 8.4
laravel: 7.*

name: Laravel Actions Tests - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, iconv
coverage: none
tools: composer:v2

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer require "phpunit/phpunit:${{ matrix.phpunit }}" --no-interaction --no-update
composer require "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer require "nunomaduro/larastan:${{ matrix.larastan }}" --no-interaction --no-update
composer update --prefer-dist --no-interaction
composer dump

- name: Execute tests
run: vendor/bin/phpunit tests/

pint:
runs-on: ubuntu-24.04
timeout-minutes: 5

name: Pint Style Check
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
tools: composer:v2

- name: Install dependencies
run: |
composer install --no-interaction
composer dump

- name: Execute Pint
run: composer pint-check
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,29 @@ public function index (Action $action)
}
```

## Macros

There are times when you may want to add something extra to your actions. We can leverage macros for this!

Here is an example were we are leveraging Inertia's defer functionality directly on our action. The macro then just calls `act()` on the action class when the deferred prop is requested!

```php
// In your service provider
Action::macro('defer', function($action, ...$arguments) {
return Inertia::defer(fn () => $action::act(...$arguments));
});

// In your controller
return Inertia::render('Users/Index')
->with('users', GetUsers::defer());
```

Note how the originating class is passed into the macro function as the first parameter. This is very important, otherwise the macro will be unaware of which action you are actually running as macros are technically run on the parent action class. You are also free to do what you want regarding the subsequent $arguments, but it is considered best practice to pack/unpack the arguments with the spread operator to ensure the actions are as flexible as possible.

Also take note the `defer()` is defined on the `Kirschbaum\Actions\Action` class, not on the `GetUsers` action class. Individual actions are not macroable in and of themselves. The macro `defer()` will also be available to every action in your application, not just the `GetUsers` action!

Before and after events will not be fired when using macros. They will get fired however if you use an action's `act()`, `actWhen()`, or `actUnless()` methods with the macro function.

## Handling Failures

We all know Chuck Norris isn't going to fail us, but he isn't the only one using this... Handling failures is pretty easy with Actions. Out of the box, any exceptions thrown by your Action classes get handled by Laravel's exception handler. If you'd rather implement your own logic during a failure, add a `failed()` method to your Action. It's that easy! You can return data from your `failed()` method if you choose as well.
Expand Down
15 changes: 14 additions & 1 deletion pint.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,26 @@
"yield"
]
},
"class_definition": {
"multi_line_extends_each_single_line": true,
"single_item_single_line": true,
"single_line": false
},
"concat_space": {
"spacing": "one"
},
"explicit_string_variable": true,
"method_chaining_indentation": true,
"new_with_braces": true,
"nullable_type_declaration_for_default_null_value": true,
"ordered_traits": true,
"phpdoc_separation": true
"php_unit_method_casing": {
"case": "camel_case"
},
"php_unit_test_annotation": {
"style": "prefix"
},
"phpdoc_separation": true,
"single_line_empty_body": true
}
}
Loading