Skip to content

Commit d733924

Browse files
committed
Macroable, pint and github action updates
1 parent aca5d54 commit d733924

File tree

18 files changed

+313
-127
lines changed

18 files changed

+313
-127
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/code-style.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/run-tests.yml

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
on: push
2+
name: CI
3+
4+
jobs:
5+
phpunit:
6+
runs-on: ubuntu-24.04
7+
timeout-minutes: 5
8+
9+
strategy:
10+
fail-fast: true
11+
matrix:
12+
php: [ 8.0, 8.1, 8.2, 8.3, 8.4 ]
13+
laravel: [ 7.*, 8.*, 9.*, 10.*, 11.*, 12.* ]
14+
include:
15+
- php: 8.0
16+
laravel: 7.*
17+
phpunit: 9.*
18+
testbench: 5.*
19+
larastan: 1.*
20+
- php: 8.0
21+
laravel: 8.*
22+
phpunit: 9.*
23+
testbench: 6.*
24+
larastan: 1.*
25+
- php: 8.0
26+
laravel: 9.*
27+
phpunit: 9.*
28+
testbench: 7.*
29+
larastan: 2.*
30+
31+
- php: 8.1
32+
laravel: 8.*
33+
phpunit: 9.*
34+
testbench: 6.*
35+
larastan: 1.*
36+
- php: 8.1
37+
laravel: 9.*
38+
phpunit: 9.*
39+
testbench: 7.*
40+
larastan: 2.*
41+
- php: 8.1
42+
laravel: 10.*
43+
phpunit: 10.*
44+
testbench: 8.*
45+
larastan: 2.*
46+
47+
- php: 8.2
48+
laravel: 8.*
49+
phpunit: 9.*
50+
testbench: 6.*
51+
larastan: 1.*
52+
- php: 8.2
53+
laravel: 9.*
54+
phpunit: 9.*
55+
testbench: 7.*
56+
larastan: 2.*
57+
- php: 8.2
58+
laravel: 10.*
59+
phpunit: 10.*
60+
testbench: 8.*
61+
larastan: 2.*
62+
- php: 8.2
63+
laravel: 11.*
64+
phpunit: 10.*
65+
testbench: 9.*
66+
larastan: 2.*
67+
- php: 8.2
68+
laravel: 12.*
69+
phpunit: 11.*
70+
testbench: 10.*
71+
larastan: 3.*
72+
73+
- php: 8.3
74+
laravel: 8.*
75+
phpunit: 9.*
76+
testbench: 6.*
77+
larastan: 1.*
78+
- php: 8.3
79+
laravel: 9.*
80+
phpunit: 9.*
81+
testbench: 7.*
82+
larastan: 2.*
83+
- php: 8.3
84+
laravel: 10.*
85+
phpunit: 10.*
86+
testbench: 8.*
87+
larastan: 2.*
88+
- php: 8.3
89+
laravel: 11.*
90+
phpunit: 11.*
91+
testbench: 9.*
92+
larastan: 2.*
93+
- php: 8.3
94+
laravel: 12.*
95+
phpunit: 11.*
96+
testbench: 10.*
97+
larastan: 3.*
98+
99+
- php: 8.4
100+
laravel: 8.*
101+
phpunit: 9.*
102+
testbench: 6.*
103+
larastan: 1.*
104+
- php: 8.4
105+
laravel: 9.*
106+
phpunit: 9.*
107+
testbench: 7.*
108+
larastan: 2.*
109+
- php: 8.4
110+
laravel: 10.*
111+
phpunit: 10.*
112+
testbench: 8.*
113+
larastan: 2.*
114+
- php: 8.4
115+
laravel: 11.*
116+
phpunit: 11.*
117+
testbench: 9.*
118+
larastan: 2.*
119+
- php: 8.4
120+
laravel: 12.*
121+
phpunit: 11.*
122+
testbench: 10.*
123+
larastan: 3.*
124+
125+
exclude:
126+
- php: 8.0
127+
laravel: 10.*
128+
- php: 8.0
129+
laravel: 11.*
130+
- php: 8.0
131+
laravel: 12.*
132+
- php: 8.1
133+
laravel: 7.*
134+
- php: 8.1
135+
laravel: 11.*
136+
- php: 8.1
137+
laravel: 12.*
138+
- php: 8.2
139+
laravel: 7.*
140+
- php: 8.3
141+
laravel: 7.*
142+
- php: 8.4
143+
laravel: 7.*
144+
145+
name: Laravel Actions Tests - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
146+
147+
steps:
148+
- name: Checkout code
149+
uses: actions/checkout@v4
150+
151+
- name: Cache dependencies
152+
uses: actions/cache@v4
153+
with:
154+
path: ~/.composer/cache/files
155+
key: dependencies-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
156+
157+
- name: Setup PHP
158+
uses: shivammathur/setup-php@v2
159+
with:
160+
php-version: ${{ matrix.php }}
161+
extensions: curl, mbstring, zip, pcntl, iconv
162+
coverage: none
163+
tools: composer:v2
164+
165+
- name: Install dependencies
166+
run: |
167+
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
168+
composer require "phpunit/phpunit:${{ matrix.phpunit }}" --no-interaction --no-update
169+
composer require "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
170+
composer require "nunomaduro/larastan:${{ matrix.larastan }}" --no-interaction --no-update
171+
composer update --prefer-dist --no-interaction
172+
composer dump
173+
174+
- name: Execute tests
175+
run: vendor/bin/phpunit tests/
176+
177+
pint:
178+
runs-on: ubuntu-24.04
179+
timeout-minutes: 5
180+
181+
name: Pint Style Check
182+
steps:
183+
- name: Checkout code
184+
uses: actions/checkout@v4
185+
186+
- name: Cache dependencies
187+
uses: actions/cache@v4
188+
with:
189+
path: ~/.composer/cache/files
190+
key: dependencies-composer-${{ hashFiles('composer.json') }}
191+
192+
- name: Setup PHP
193+
uses: shivammathur/setup-php@v2
194+
with:
195+
php-version: 8.3
196+
tools: composer:v2
197+
198+
- name: Install dependencies
199+
run: |
200+
composer install --no-interaction
201+
composer dump
202+
203+
- name: Execute Pint
204+
run: composer pint-check

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,29 @@ public function index (Action $action)
141141
}
142142
```
143143

144+
## Macros
145+
146+
There are times when you may want to add something extra to your actions. We can leverage macros for this!
147+
148+
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!
149+
150+
```php
151+
// In your service provider
152+
Action::macro('defer', function($action, ...$arguments) {
153+
return Inertia::defer(fn () => $action::act(...$arguments));
154+
});
155+
156+
// In your controller
157+
return Inertia::render('Users/Index')
158+
->with('users', GetUsers::defer());
159+
```
160+
161+
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.
162+
163+
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!
164+
165+
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.
166+
144167
## Handling Failures
145168

146169
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.

pint.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,26 @@
2525
"yield"
2626
]
2727
},
28+
"class_definition": {
29+
"multi_line_extends_each_single_line": true,
30+
"single_item_single_line": true,
31+
"single_line": false
32+
},
2833
"concat_space": {
2934
"spacing": "one"
3035
},
3136
"explicit_string_variable": true,
3237
"method_chaining_indentation": true,
3338
"new_with_braces": true,
39+
"nullable_type_declaration_for_default_null_value": true,
3440
"ordered_traits": true,
35-
"phpdoc_separation": true
41+
"php_unit_method_casing": {
42+
"case": "camel_case"
43+
},
44+
"php_unit_test_annotation": {
45+
"style": "prefix"
46+
},
47+
"phpdoc_separation": true,
48+
"single_line_empty_body": true
3649
}
3750
}

0 commit comments

Comments
 (0)