Skip to content

Commit d1c3d34

Browse files
committed
Update config file flags & adjust tests
1 parent 66bd366 commit d1c3d34

File tree

6 files changed

+45
-74
lines changed

6 files changed

+45
-74
lines changed

config/inertia.php

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,7 @@
44

55
/*
66
|--------------------------------------------------------------------------
7-
| Force top-level property interaction
8-
|--------------------------------------------------------------------------
9-
|
10-
| This setting allows you to toggle the automatic property interaction
11-
| check for your page's top-level properties. While this feature is
12-
| useful in property scopes, it is generally not as useful on the
13-
| top-level of the page, as it forces you to interact with each
14-
| (shared) property on the page, or to use the `etc` method.
15-
|
16-
*/
17-
18-
'force_top_level_property_interaction' => false,
19-
20-
/*
21-
|--------------------------------------------------------------------------
22-
| Page
7+
| Testing
238
|--------------------------------------------------------------------------
249
|
2510
| The values described here are used to locate Inertia components on the
@@ -29,27 +14,17 @@
2914
|
3015
*/
3116

32-
'page' => [
17+
'testing' => [
3318

34-
/**
35-
* Determines whether assertions should check that Inertia page components
36-
* actually exist on the filesystem instead of just checking responses.
37-
*/
38-
'should_exist' => true,
19+
'ensure_pages_exist' => true,
3920

40-
/*
41-
* A list of root paths to your Inertia page components.
42-
*/
43-
'paths' => [
21+
'page_paths' => [
4422

4523
resource_path('js/Pages'),
4624

4725
],
4826

49-
/*
50-
* A list of valid Inertia page component extensions.
51-
*/
52-
'extensions' => [
27+
'page_extensions' => [
5328

5429
'js',
5530
'svelte',

src/ServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public function register()
2323
'inertia'
2424
);
2525

26-
$this->app->bind('inertia.view.finder', function ($app) {
26+
$this->app->bind('inertia.testing.view-finder', function ($app) {
2727
return new FileViewFinder(
2828
$app['files'],
29-
$app['config']->get('inertia.page.paths'),
30-
$app['config']->get('inertia.page.extensions')
29+
$app['config']->get('inertia.testing.page_paths'),
30+
$app['config']->get('inertia.testing.page_extensions')
3131
);
3232
});
3333
}

src/Testing/Concerns/PageObject.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public function component(string $value = null, $shouldExist = null): self
1212
{
1313
PHPUnit::assertSame($value, $this->component, 'Unexpected Inertia page component.');
1414

15-
if ($shouldExist || (is_null($shouldExist) && config('inertia.page.should_exist', true))) {
15+
if ($shouldExist || (is_null($shouldExist) && config('inertia.testing.ensure_pages_exist', true))) {
1616
try {
17-
app('inertia.view.finder')->find($value);
17+
app('inertia.testing.view-finder')->find($value);
1818
} catch (InvalidArgumentException $exception) {
1919
PHPUnit::fail(sprintf('Inertia page component file [%s] does not exist.', $value));
2020
}

src/Testing/TestResponseMacros.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ public function assertInertia()
1717

1818
$callback($assert);
1919

20-
if (config('inertia.force_top_level_property_interaction', true)) {
21-
$assert->interacted();
22-
}
23-
2420
return $this;
2521
};
2622
}

tests/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public function setUp(): void
2626
View::addLocation(__DIR__.'/Stubs');
2727

2828
Inertia::setRootView('welcome');
29-
config()->set('inertia.page.should_exist', false);
30-
config()->set('inertia.page.paths', [realpath(__DIR__)]);
29+
config()->set('inertia.testing.ensure_pages_exist', false);
30+
config()->set('inertia.testing.page_paths', [realpath(__DIR__)]);
3131
}
3232

3333
/**

tests/Testing/AssertTest.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function the_component_exists_on_the_filesystem(): void
7171
Inertia::render('Stubs/ExamplePage')
7272
);
7373

74-
config()->set('inertia.page.should_exist', true);
74+
config()->set('inertia.testing.ensure_pages_exist', true);
7575
$response->assertInertia(function (Assert $inertia) {
7676
$inertia->component('Stubs/ExamplePage');
7777
});
@@ -84,7 +84,7 @@ public function the_component_does_not_exist_on_the_filesystem(): void
8484
Inertia::render('foo')
8585
);
8686

87-
config()->set('inertia.page.should_exist', true);
87+
config()->set('inertia.testing.ensure_pages_exist', true);
8888
$this->expectException(AssertionFailedError::class);
8989
$this->expectExceptionMessage('Inertia page component file [foo] does not exist.');
9090

@@ -100,7 +100,7 @@ public function it_can_force_enable_the_component_file_existence(): void
100100
Inertia::render('foo')
101101
);
102102

103-
config()->set('inertia.page.should_exist', false);
103+
config()->set('inertia.testing.ensure_pages_exist', false);
104104
$this->expectException(AssertionFailedError::class);
105105
$this->expectExceptionMessage('Inertia page component file [foo] does not exist.');
106106

@@ -116,7 +116,7 @@ public function it_can_force_disable_the_component_file_existence_check(): void
116116
Inertia::render('foo')
117117
);
118118

119-
config()->set('inertia.page.should_exist', true);
119+
config()->set('inertia.testing.ensure_pages_exist', true);
120120

121121
$response->assertInertia(function (Assert $inertia) {
122122
$inertia->component('foo', false);
@@ -130,8 +130,8 @@ public function the_component_does_not_exist_on_the_filesystem_when_it_does_not_
130130
Inertia::render('fixtures/ExamplePage')
131131
);
132132

133-
config()->set('inertia.page.should_exist', true);
134-
config()->set('inertia.page.paths', [realpath(__DIR__)]);
133+
config()->set('inertia.testing.ensure_pages_exist', true);
134+
config()->set('inertia.testing.page_paths', [realpath(__DIR__)]);
135135
$this->expectException(AssertionFailedError::class);
136136
$this->expectExceptionMessage('Inertia page component file [fixtures/ExamplePage] does not exist.');
137137

@@ -147,8 +147,8 @@ public function the_component_does_not_exist_on_the_filesystem_when_it_does_not_
147147
Inertia::render('fixtures/ExamplePage')
148148
);
149149

150-
config()->set('inertia.page.should_exist', true);
151-
config()->set('inertia.page.extensions', ['bin', 'exe', 'svg']);
150+
config()->set('inertia.testing.ensure_pages_exist', true);
151+
config()->set('inertia.testing.page_extensions', ['bin', 'exe', 'svg']);
152152
$this->expectException(AssertionFailedError::class);
153153
$this->expectExceptionMessage('Inertia page component file [fixtures/ExamplePage] does not exist.');
154154

@@ -943,76 +943,76 @@ public function it_fails_when_it_does_not_interact_with_all_props_in_the_scope_a
943943
}
944944

945945
/** @test */
946-
public function it_does_not_fail_when_not_interacting_with_every_top_level_prop_by_default(): void
946+
public function it_can_disable_the_interaction_check_for_the_current_scope(): void
947947
{
948948
$response = $this->makeMockRequest(
949949
Inertia::render('foo', [
950-
'foo' => 'bar',
951-
'bar' => 'baz',
950+
'bar' => true,
952951
])
953952
);
954953

955954
$response->assertInertia(function (Assert $inertia) {
956-
$inertia->has('foo');
955+
$inertia->etc();
957956
});
958957
}
959958

960959
/** @test */
961-
public function it_fails_when_not_interacting_with_every_top_level_prop_while_the_force_setting_is_enabled(): void
960+
public function it_cannot_disable_the_interaction_check_for_any_other_scopes(): void
962961
{
963962
$response = $this->makeMockRequest(
964963
Inertia::render('foo', [
965-
'foo' => 'bar',
966-
'bar' => 'baz',
964+
'bar' => true,
965+
'baz' => [
966+
'foo' => 'bar',
967+
'example' => 'value',
968+
],
967969
])
968970
);
969971

970-
config()->set('inertia.force_top_level_property_interaction', true);
971-
972972
$this->expectException(AssertionFailedError::class);
973-
$this->expectExceptionMessage('Unexpected Inertia properties were found on the root level.');
973+
$this->expectExceptionMessage('Unexpected Inertia properties were found in scope [baz].');
974974

975975
$response->assertInertia(function (Assert $inertia) {
976-
$inertia->has('foo');
976+
$inertia
977+
->etc()
978+
->has('baz', function (Assert $inertia) {
979+
$inertia->where('foo', 'bar');
980+
});
977981
});
978982
}
979983

980984
/** @test */
981-
public function it_can_disable_the_interaction_check_for_the_current_scope(): void
985+
public function it_does_not_fail_when_not_interacting_with_every_top_level_prop(): void
982986
{
983987
$response = $this->makeMockRequest(
984988
Inertia::render('foo', [
985-
'bar' => true,
989+
'foo' => 'bar',
990+
'bar' => 'baz',
986991
])
987992
);
988993

989994
$response->assertInertia(function (Assert $inertia) {
990-
$inertia->etc();
995+
$inertia->has('foo');
991996
});
992997
}
993998

994999
/** @test */
995-
public function it_cannot_disable_the_interaction_check_for_any_other_scopes(): void
1000+
public function it_fails_when_not_interacting_with_every_top_level_prop_while_the_interacted_flag_is_set(): void
9961001
{
9971002
$response = $this->makeMockRequest(
9981003
Inertia::render('foo', [
999-
'bar' => true,
1000-
'baz' => [
1001-
'foo' => 'bar',
1002-
'example' => 'value',
1003-
],
1004+
'foo' => 'bar',
1005+
'bar' => 'baz',
10041006
])
10051007
);
10061008

10071009
$this->expectException(AssertionFailedError::class);
1008-
$this->expectExceptionMessage('Unexpected Inertia properties were found in scope [baz].');
1010+
$this->expectExceptionMessage('Unexpected Inertia properties were found on the root level.');
10091011

10101012
$response->assertInertia(function (Assert $inertia) {
10111013
$inertia
1012-
->etc()
1013-
->has('baz', function (Assert $inertia) {
1014-
$inertia->where('foo', 'bar');
1015-
});
1014+
->has('foo')
1015+
->interacted();
10161016
});
10171017
}
10181018

0 commit comments

Comments
 (0)