Skip to content

Commit 735d20f

Browse files
committed
merge props test
1 parent 289222e commit 735d20f

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/Inertia.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* @method static \Inertia\LazyProp lazy(callable $callback)
1818
* @method static \Inertia\DeferProp defer(callable $callback, string $group = 'default')
1919
* @method static \Inertia\AlwaysProp always(mixed $value)
20+
* @method static \Inertia\MergeProp merge(mixed $value)
2021
* @method static \Inertia\Response render(string $component, array|\Illuminate\Contracts\Support\Arrayable $props = [])
2122
* @method static \Symfony\Component\HttpFoundation\Response location(string|\Symfony\Component\HttpFoundation\RedirectResponse $url)
2223
* @method static void macro(string $name, object|callable $macro)

tests/MergePropTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

tests/ResponseFactoryTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Inertia\DeferProp;
1616
use Inertia\Inertia;
1717
use Inertia\LazyProp;
18+
use Inertia\MergeProp;
1819
use Inertia\OptionalProp;
1920
use Inertia\ResponseFactory;
2021
use Inertia\Tests\Stubs\ExampleMiddleware;
@@ -173,6 +174,26 @@ public function test_can_create_deferred_prop(): void
173174
$this->assertInstanceOf(DeferProp::class, $deferredProp);
174175
}
175176

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+
176197
public function test_can_create_optional_prop(): void
177198
{
178199
$factory = new ResponseFactory();

0 commit comments

Comments
 (0)