File tree Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 14
14
"autoload" : {
15
15
"psr-4" : {
16
16
"Inertia\\ " : " src"
17
- }
17
+ },
18
+ "files" : [
19
+ " ./helpers.php"
20
+ ]
18
21
},
19
22
"autoload-dev" : {
20
23
"psr-4" : {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ if (! function_exists ('inertia ' )) {
4
+ /**
5
+ * Inertia helper.
6
+ *
7
+ * @param null|string $component
8
+ * @param array $props
9
+ * @return \Inertia\ResponseFactory|\Inertia\Response
10
+ */
11
+ function inertia ($ component = null , $ props = []) {
12
+ $ instance = \Inertia \Inertia::getFacadeRoot ();
13
+
14
+ if ($ component ) {
15
+ return $ instance ->render ($ component , $ props );
16
+ }
17
+
18
+ return $ instance ;
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Tests ;
4
+
5
+ use Inertia \Inertia ;
6
+ use Inertia \ResponseFactory ;
7
+ use Inertia \Response ;
8
+
9
+ class HelperTest extends TestCase
10
+ {
11
+ public function test_the_helper_function_returns_an_instance_of_the_response_factory ()
12
+ {
13
+ $ this ->assertInstanceOf (ResponseFactory::class, inertia ());
14
+ }
15
+
16
+ public function test_the_helper_function_returns_a_response_instance ()
17
+ {
18
+ $ this ->assertInstanceOf (Response::class, inertia ('User/Edit ' , ['user ' => ['name ' => 'George ' ]]));
19
+ }
20
+
21
+ public function test_the_instance_is_the_same_as_the_facade_instance ()
22
+ {
23
+ Inertia::share ('key ' , 'value ' );
24
+ $ this ->assertEquals ('value ' , inertia ()->getShared ('key ' ));
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments