25
25
26
26
class MakeResourceTest extends TestCase
27
27
{
28
-
29
28
/**
30
29
* @return void
31
30
*/
@@ -60,6 +59,33 @@ public function test(): void
60
59
$ this ->assertResourceCreated ();
61
60
}
62
61
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
+
63
89
public function testServer (): void
64
90
{
65
91
config ()->set ('jsonapi.servers ' , [
@@ -104,9 +130,14 @@ public function testInvalidServer(): void
104
130
}
105
131
106
132
/**
133
+ * @param string $namespacedModel
134
+ * @param string $model
107
135
* @return void
108
136
*/
109
- private function assertResourceCreated (): void
137
+ private function assertResourceCreated (
138
+ string $ namespacedModel = 'App\Models\Post ' ,
139
+ string $ model = 'Post '
140
+ ): void
110
141
{
111
142
$ this ->assertFileExists ($ path = app_path ('JsonApi/V1/Posts/PostResource.php ' ));
112
143
$ content = file_get_contents ($ path );
@@ -115,6 +146,8 @@ private function assertResourceCreated(): void
115
146
'namespace App\JsonApi\V1\Posts; ' ,
116
147
'use LaravelJsonApi\Core\Resources\JsonApiResource; ' ,
117
148
'class PostResource extends JsonApiResource ' ,
149
+ "use {$ namespacedModel }; " ,
150
+ "@property {$ model } \$resource " ,
118
151
];
119
152
120
153
foreach ($ tests as $ expected ) {
0 commit comments