2525
2626class MakeResourceTest extends TestCase
2727{
28-
2928 /**
3029 * @return void
3130 */
@@ -60,6 +59,33 @@ public function test(): void
6059 $ this ->assertResourceCreated ();
6160 }
6261
62+ public function testModelWithoutNamespace (): void
63+ {
64+ config ()->set ('jsonapi.servers ' , [
65+ 'v1 ' => Server::class,
66+ ]);
67+
68+ $ result = $ this ->artisan ('jsonapi:resource posts --model BlogPost ' );
69+
70+ $ this ->assertSame (0 , $ result );
71+ $ this ->assertResourceCreated ('App\Models\BlogPost ' , 'BlogPost ' );
72+ }
73+
74+ public function testModelWithNamespace (): void
75+ {
76+ config ()->set ('jsonapi.servers ' , [
77+ 'v1 ' => Server::class,
78+ ]);
79+
80+ $ result = $ this ->artisan ('jsonapi:resource ' , [
81+ 'name ' => 'posts ' ,
82+ '--model ' => '\App\Foo\Bar\BlogPost ' ,
83+ ]);
84+
85+ $ this ->assertSame (0 , $ result );
86+ $ this ->assertResourceCreated ('App\Foo\Bar\BlogPost ' , 'BlogPost ' );
87+ }
88+
6389 public function testServer (): void
6490 {
6591 config ()->set ('jsonapi.servers ' , [
@@ -104,9 +130,14 @@ public function testInvalidServer(): void
104130 }
105131
106132 /**
133+ * @param string $namespacedModel
134+ * @param string $model
107135 * @return void
108136 */
109- private function assertResourceCreated (): void
137+ private function assertResourceCreated (
138+ string $ namespacedModel = 'App\Models\Post ' ,
139+ string $ model = 'Post '
140+ ): void
110141 {
111142 $ this ->assertFileExists ($ path = app_path ('JsonApi/V1/Posts/PostResource.php ' ));
112143 $ content = file_get_contents ($ path );
@@ -115,6 +146,8 @@ private function assertResourceCreated(): void
115146 'namespace App\JsonApi\V1\Posts; ' ,
116147 'use LaravelJsonApi\Core\Resources\JsonApiResource; ' ,
117148 'class PostResource extends JsonApiResource ' ,
149+ "use {$ namespacedModel }; " ,
150+ "@property {$ model } \$resource " ,
118151 ];
119152
120153 foreach ($ tests as $ expected ) {
0 commit comments