Skip to content

Commit 9237365

Browse files
Add test
1 parent 95898e5 commit 9237365

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/MiddlewareTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Inertia\AlwaysProp;
1313
use Inertia\Inertia;
1414
use Inertia\Middleware;
15+
use Inertia\Tests\Stubs\CustomOncePropsResolverMiddleware;
1516
use Inertia\Tests\Stubs\CustomUrlResolverMiddleware;
1617
use Inertia\Tests\Stubs\ExampleMiddleware;
1718
use LogicException;
@@ -146,6 +147,24 @@ public function test_the_url_can_be_resolved_with_a_custom_resolver()
146147
]);
147148
}
148149

150+
public function test_the_once_props_can_be_resolved_with_a_custom_resolver()
151+
{
152+
$this->prepareMockEndpoint(middleware: new CustomOncePropsResolverMiddleware);
153+
154+
$response = $this->withoutExceptionHandling()->get('/', [
155+
'X-Inertia' => 'true',
156+
]);
157+
158+
$response->assertSuccessful();
159+
$response->assertJson([
160+
'component' => 'User/Edit',
161+
'onceProps' => [
162+
'once' => true,
163+
'appName' => 'test',
164+
],
165+
]);
166+
}
167+
149168
public function test_validation_errors_are_registered_as_of_default(): void
150169
{
151170
Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Inertia\Tests\Stubs;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Routing\ResponseFactory;
7+
use Inertia\Middleware;
8+
use PHPUnit\Framework\Assert;
9+
10+
class CustomOncePropsResolverMiddleware extends Middleware
11+
{
12+
public function oncePropsResolver()
13+
{
14+
return function ($request, ResponseFactory $otherDependency) {
15+
Assert::assertInstanceOf(Request::class, $request);
16+
Assert::assertInstanceOf(ResponseFactory::class, $otherDependency);
17+
18+
return [
19+
'once' => true,
20+
'appName' => 'test',
21+
];
22+
};
23+
}
24+
}

0 commit comments

Comments
 (0)