File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 17
17
* @method static \Inertia\LazyProp lazy(callable $callback)
18
18
* @method static \Inertia\DeferProp defer(callable $callback, string $group = 'default')
19
19
* @method static \Inertia\AlwaysProp always(mixed $value)
20
+ * @method static \Inertia\MergeProp merge(mixed $value)
20
21
* @method static \Inertia\Response render(string $component, array|\Illuminate\Contracts\Support\Arrayable $props = [])
21
22
* @method static \Symfony\Component\HttpFoundation\Response location(string|\Symfony\Component\HttpFoundation\RedirectResponse $url)
22
23
* @method static void macro(string $name, object|callable $macro)
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Inertia \Tests ;
4
+
5
+ use Illuminate \Http \Request ;
6
+ use Inertia \MergeProp ;
7
+
8
+ class MergePropTest extends TestCase
9
+ {
10
+ public function test_can_invoke_with_a_callback (): void
11
+ {
12
+ $ mergeProp = new MergeProp (function () {
13
+ return 'A merge prop value ' ;
14
+ });
15
+
16
+ $ this ->assertSame ('A merge prop value ' , $ mergeProp ());
17
+ }
18
+
19
+ public function test_can_invoke_with_a_non_callback (): void
20
+ {
21
+ $ mergeProp = new MergeProp (['key ' => 'value ' ]);
22
+
23
+ $ this ->assertSame (['key ' => 'value ' ], $ mergeProp ());
24
+ }
25
+
26
+ public function test_can_resolve_bindings_when_invoked (): void
27
+ {
28
+ $ mergeProp = new MergeProp (function (Request $ request ) {
29
+ return $ request ;
30
+ });
31
+
32
+ $ this ->assertInstanceOf (Request::class, $ mergeProp ());
33
+ }
34
+ }
Original file line number Diff line number Diff line change 15
15
use Inertia \DeferProp ;
16
16
use Inertia \Inertia ;
17
17
use Inertia \LazyProp ;
18
+ use Inertia \MergeProp ;
18
19
use Inertia \OptionalProp ;
19
20
use Inertia \ResponseFactory ;
20
21
use Inertia \Tests \Stubs \ExampleMiddleware ;
@@ -173,6 +174,26 @@ public function test_can_create_deferred_prop(): void
173
174
$ this ->assertInstanceOf (DeferProp::class, $ deferredProp );
174
175
}
175
176
177
+ public function test_can_create_merged_prop (): void
178
+ {
179
+ $ factory = new ResponseFactory ();
180
+ $ mergedProp = $ factory ->merge (function () {
181
+ return 'A merged value ' ;
182
+ });
183
+
184
+ $ this ->assertInstanceOf (MergeProp::class, $ mergedProp );
185
+ }
186
+
187
+ public function test_can_create_deferred_and_merged_prop (): void
188
+ {
189
+ $ factory = new ResponseFactory ();
190
+ $ deferredProp = $ factory ->defer (function () {
191
+ return 'A deferred + merged value ' ;
192
+ })->merge ();
193
+
194
+ $ this ->assertInstanceOf (DeferProp::class, $ deferredProp );
195
+ }
196
+
176
197
public function test_can_create_optional_prop (): void
177
198
{
178
199
$ factory = new ResponseFactory ();
You can’t perform that action at this time.
0 commit comments