4
4
5
5
use Blueprint \Lexers \StatementLexer ;
6
6
use Blueprint \Models \Statements \DispatchStatement ;
7
+ use Blueprint \Models \Statements \EloquentStatement ;
7
8
use Blueprint \Models \Statements \FireStatement ;
8
- use Blueprint \Models \Statements \SendStatement ;
9
+ use Blueprint \Models \Statements \RedirectStatement ;
9
10
use Blueprint \Models \Statements \RenderStatement ;
11
+ use Blueprint \Models \Statements \SendStatement ;
12
+ use Blueprint \Models \Statements \SessionStatement ;
10
13
use Blueprint \Models \Statements \ValidateStatement ;
11
14
use PHPUnit \Framework \TestCase ;
12
15
@@ -235,4 +238,95 @@ public function it_returns_a_validate_statement()
235
238
236
239
$ this ->assertSame (['title ' , 'author_id ' , 'content ' ], $ actual [0 ]->data ());
237
240
}
241
+
242
+ /**
243
+ * @test
244
+ * @dataProvider eloquentTokensProvider
245
+ */
246
+ public function it_returns_an_eloquent_statement ($ operation , $ reference )
247
+ {
248
+ $ tokens = [
249
+ $ operation => $ reference
250
+ ];
251
+
252
+ $ actual = $ this ->subject ->analyze ($ tokens );
253
+
254
+ $ this ->assertCount (1 , $ actual );
255
+ $ this ->assertInstanceOf (EloquentStatement::class, $ actual [0 ]);
256
+
257
+ $ this ->assertSame ($ operation , $ actual [0 ]->operation ());
258
+ $ this ->assertSame ($ reference , $ actual [0 ]->reference ());
259
+ }
260
+
261
+ /**
262
+ * @test
263
+ * @dataProvider sessionTokensProvider
264
+ */
265
+ public function it_returns_a_session_statement ($ operation , $ reference )
266
+ {
267
+ $ tokens = [
268
+ $ operation => $ reference
269
+ ];
270
+
271
+ $ actual = $ this ->subject ->analyze ($ tokens );
272
+
273
+ $ this ->assertCount (1 , $ actual );
274
+ $ this ->assertInstanceOf (SessionStatement::class, $ actual [0 ]);
275
+
276
+ $ this ->assertSame ($ operation , $ actual [0 ]->operation ());
277
+ $ this ->assertSame ($ reference , $ actual [0 ]->reference ());
278
+ }
279
+
280
+ /**
281
+ * @test
282
+ */
283
+ public function it_returns_a_redirect_statement ()
284
+ {
285
+ $ tokens = [
286
+ 'redirect ' => 'route.index '
287
+ ];
288
+
289
+ $ actual = $ this ->subject ->analyze ($ tokens );
290
+
291
+ $ this ->assertCount (1 , $ actual );
292
+ $ this ->assertInstanceOf (RedirectStatement::class, $ actual [0 ]);
293
+
294
+ $ this ->assertEquals ('route.index ' , $ actual [0 ]->route ());
295
+ $ this ->assertSame ([], $ actual [0 ]->data ());
296
+ }
297
+
298
+ /**
299
+ * @test
300
+ */
301
+ public function it_returns_a_redirect_statement_with_data ()
302
+ {
303
+ $ tokens = [
304
+ 'redirect ' => 'route.show with:foo, bar, baz '
305
+ ];
306
+
307
+ $ actual = $ this ->subject ->analyze ($ tokens );
308
+
309
+ $ this ->assertCount (1 , $ actual );
310
+ $ this ->assertInstanceOf (RedirectStatement::class, $ actual [0 ]);
311
+
312
+ $ this ->assertEquals ('route.show ' , $ actual [0 ]->route ());
313
+ $ this ->assertEquals (['foo ' , 'bar ' , 'baz ' ], $ actual [0 ]->data ());
314
+ }
315
+
316
+ public function eloquentTokensProvider ()
317
+ {
318
+ return [
319
+ ['save ' , 'post ' ],
320
+ ['update ' , 'post ' ],
321
+ ['delete ' , 'post.id ' ],
322
+ ];
323
+ }
324
+
325
+ public function sessionTokensProvider ()
326
+ {
327
+ return [
328
+ ['flash ' , 'post.title ' ],
329
+ ['store ' , 'post.id ' ],
330
+ ];
331
+ }
238
332
}
0 commit comments