@@ -109,6 +109,84 @@ public function output_generates_routes_for_mixed_resources(): void
109
109
$ this ->assertEquals (['updated ' => ['routes/api.php ' , 'routes/web.php ' ]], $ this ->subject ->output ($ tree ));
110
110
}
111
111
112
+ #[Test]
113
+ public function output_creates_api_routes_file_when_missing (): void
114
+ {
115
+ $ this ->filesystem ->expects ('exists ' )
116
+ ->with ('routes/api.php ' )
117
+ ->andReturn (false );
118
+
119
+ $ this ->filesystem ->expects ('stub ' )
120
+ ->with ('routes.api.stub ' )
121
+ ->andReturn ($ this ->stub ('routes.api.stub ' ));
122
+
123
+ $ this ->filesystem ->expects ('put ' )
124
+ ->with ('routes/api.php ' , $ this ->stub ('routes.api.stub ' ));
125
+
126
+ $ this ->filesystem ->expects ('append ' )
127
+ ->with ('routes/api.php ' , $ this ->fixture ('routes/api-routes.php ' ));
128
+
129
+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/api-routes-example.yaml ' ));
130
+ $ tree = $ this ->blueprint ->analyze ($ tokens );
131
+
132
+ $ this ->assertEquals (['updated ' => ['routes/api.php ' ]], $ this ->subject ->output ($ tree ));
133
+ }
134
+
135
+ #[Test]
136
+ public function output_does_not_create_api_routes_file_when_it_exists (): void
137
+ {
138
+ $ this ->filesystem ->shouldReceive ('exists ' )
139
+ ->with ('routes/api.php ' )
140
+ ->andReturn (true );
141
+
142
+ $ this ->filesystem ->expects ('put ' )
143
+ ->with ('routes/api.php ' , $ this ->anything ())
144
+ ->never ();
145
+
146
+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/api-routes-example.yaml ' ));
147
+ $ tree = $ this ->blueprint ->analyze ($ tokens );
148
+
149
+ $ this ->assertEquals (['updated ' => ['routes/api.php ' ]], $ this ->subject ->output ($ tree ));
150
+ }
151
+
152
+ #[Test]
153
+ public function output_adds_api_route_line_to_bootstrap_if_missing (): void
154
+ {
155
+ $ this ->filesystem ->expects ('get ' )
156
+ ->with ('bootstrap/app.php ' )
157
+ ->andReturn ("web: __DIR__.'/../routes/web.php', " );
158
+
159
+ $ this ->filesystem ->shouldReceive ('replaceInFile ' )
160
+ ->with (
161
+ 'web: __DIR__. \'/../routes/web.php \', ' ,
162
+ 'web: __DIR__. \'/../routes/web.php \', ' . PHP_EOL . ' api: __DIR__. \'/../routes/api.php \', ' ,
163
+ 'bootstrap/app.php '
164
+ )
165
+ ->once ();
166
+
167
+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/api-routes-example.yaml ' ));
168
+ $ tree = $ this ->blueprint ->analyze ($ tokens );
169
+
170
+ $ this ->assertEquals (['updated ' => ['routes/api.php ' ]], $ this ->subject ->output ($ tree ));
171
+ }
172
+
173
+ #[Test]
174
+ public function output_uncomments_api_route_line_in_bootstrap_if_commented (): void
175
+ {
176
+ $ this ->filesystem ->expects ('get ' )
177
+ ->with ('bootstrap/app.php ' )
178
+ ->andReturn ("// api: \nweb: __DIR__.'/../routes/web.php', " );
179
+
180
+ $ this ->filesystem ->shouldReceive ('replaceInFile ' )
181
+ ->with ('// api: ' , 'api: ' , 'bootstrap/app.php ' )
182
+ ->once ();
183
+
184
+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ('drafts/api-routes-example.yaml ' ));
185
+ $ tree = $ this ->blueprint ->analyze ($ tokens );
186
+
187
+ $ this ->assertEquals (['updated ' => ['routes/api.php ' ]], $ this ->subject ->output ($ tree ));
188
+ }
189
+
112
190
public static function controllerTreeDataProvider (): array
113
191
{
114
192
return [
0 commit comments