17
17
use Illuminate \Foundation \Testing \RefreshDatabase ;
18
18
use Orchestra \Testbench \Concerns \WithWorkbench ;
19
19
use Orchestra \Testbench \TestCase ;
20
+ use Workbench \Database \Factories \AuthorFactory ;
21
+ use Workbench \Database \Factories \BookFactory ;
22
+ use Workbench \Database \Factories \WithAccessorFactory ;
20
23
21
24
class EloquentTest extends TestCase
22
25
{
@@ -26,6 +29,8 @@ class EloquentTest extends TestCase
26
29
27
30
public function testSearchFilter (): void
28
31
{
32
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
33
+
29
34
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
30
35
$ book = $ response ->json ()['member ' ][0 ];
31
36
@@ -35,18 +40,24 @@ public function testSearchFilter(): void
35
40
36
41
public function testValidateSearchFilter (): void
37
42
{
43
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
44
+
38
45
$ response = $ this ->get ('/api/books?isbn=a ' , ['Accept ' => ['application/ld+json ' ]]);
39
46
$ this ->assertSame ($ response ->json ()['detail ' ], 'The isbn field must be at least 2 characters. ' );
40
47
}
41
48
42
49
public function testSearchFilterRelation (): void
43
50
{
51
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
52
+
44
53
$ response = $ this ->get ('/api/books?author=1 ' , ['Accept ' => ['application/ld+json ' ]]);
45
54
$ this ->assertSame ($ response ->json ()['member ' ][0 ]['author ' ], '/api/authors/1 ' );
46
55
}
47
56
48
57
public function testPropertyFilter (): void
49
58
{
59
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
60
+
50
61
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
51
62
$ book = $ response ->json ()['member ' ][0 ];
52
63
@@ -60,6 +71,8 @@ public function testPropertyFilter(): void
60
71
61
72
public function testPartialSearchFilter (): void
62
73
{
74
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
75
+
63
76
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
64
77
$ book = $ response ->json ()['member ' ][0 ];
65
78
@@ -76,6 +89,8 @@ public function testPartialSearchFilter(): void
76
89
77
90
public function testDateFilterEqual (): void
78
91
{
92
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
93
+
79
94
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
80
95
$ book = $ response ->json ()['member ' ][0 ];
81
96
$ updated = $ this ->patchJson (
@@ -93,6 +108,8 @@ public function testDateFilterEqual(): void
93
108
94
109
public function testDateFilterIncludeNull (): void
95
110
{
111
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
112
+
96
113
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
97
114
$ book = $ response ->json ()['member ' ][0 ];
98
115
$ updated = $ this ->patchJson (
@@ -110,6 +127,8 @@ public function testDateFilterIncludeNull(): void
110
127
111
128
public function testDateFilterExcludeNull (): void
112
129
{
130
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
131
+
113
132
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
114
133
$ book = $ response ->json ()['member ' ][0 ];
115
134
$ updated = $ this ->patchJson (
@@ -127,6 +146,8 @@ public function testDateFilterExcludeNull(): void
127
146
128
147
public function testDateFilterGreaterThan (): void
129
148
{
149
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
150
+
130
151
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
131
152
$ bookBefore = $ response ->json ()['member ' ][0 ];
132
153
$ updated = $ this ->patchJson (
@@ -155,9 +176,10 @@ public function testDateFilterGreaterThan(): void
155
176
156
177
public function testDateFilterLowerThanEqual (): void
157
178
{
179
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
158
180
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
159
181
$ bookBefore = $ response ->json ()['member ' ][0 ];
160
- $ updated = $ this ->patchJson (
182
+ $ this ->patchJson (
161
183
$ bookBefore ['@id ' ],
162
184
['publicationDate ' => '0001-02-18 00:00:00 ' ],
163
185
[
@@ -184,6 +206,7 @@ public function testDateFilterLowerThanEqual(): void
184
206
185
207
public function testDateFilterBetween (): void
186
208
{
209
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
187
210
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
188
211
$ book = $ response ->json ()['member ' ][0 ];
189
212
$ updated = $ this ->patchJson (
@@ -223,6 +246,7 @@ public function testDateFilterBetween(): void
223
246
224
247
public function testSearchFilterWithPropertyPlaceholder (): void
225
248
{
249
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
226
250
$ response = $ this ->get ('/api/authors ' , ['Accept ' => ['application/ld+json ' ]])->json ();
227
251
$ author = $ response ['member ' ][0 ];
228
252
@@ -235,12 +259,14 @@ public function testSearchFilterWithPropertyPlaceholder(): void
235
259
236
260
public function testOrderFilterWithPropertyPlaceholder (): void
237
261
{
262
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
238
263
$ res = $ this ->get ('/api/authors?order[id]=desc ' , ['Accept ' => ['application/ld+json ' ]])->json ();
239
264
$ this ->assertSame ($ res ['member ' ][0 ]['id ' ], 10 );
240
265
}
241
266
242
267
public function testOrFilter (): void
243
268
{
269
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
244
270
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]])->json ()['member ' ];
245
271
$ book = $ response [0 ];
246
272
$ book2 = $ response [1 ];
@@ -251,6 +277,7 @@ public function testOrFilter(): void
251
277
252
278
public function testRangeLowerThanFilter (): void
253
279
{
280
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
254
281
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
255
282
$ bookBefore = $ response ->json ()['member ' ][0 ];
256
283
$ this ->patchJson (
@@ -279,6 +306,7 @@ public function testRangeLowerThanFilter(): void
279
306
280
307
public function testRangeLowerThanEqualFilter (): void
281
308
{
309
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
282
310
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
283
311
$ bookBefore = $ response ->json ()['member ' ][0 ];
284
312
$ this ->patchJson (
@@ -308,6 +336,7 @@ public function testRangeLowerThanEqualFilter(): void
308
336
309
337
public function testRangeGreaterThanFilter (): void
310
338
{
339
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
311
340
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
312
341
$ bookBefore = $ response ->json ()['member ' ][0 ];
313
342
$ updated = $ this ->patchJson (
@@ -336,6 +365,7 @@ public function testRangeGreaterThanFilter(): void
336
365
337
366
public function testRangeGreaterThanEqualFilter (): void
338
367
{
368
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
339
369
$ response = $ this ->get ('/api/books ' , ['Accept ' => ['application/ld+json ' ]]);
340
370
$ bookBefore = $ response ->json ()['member ' ][0 ];
341
371
$ updated = $ this ->patchJson (
@@ -365,12 +395,14 @@ public function testRangeGreaterThanEqualFilter(): void
365
395
366
396
public function testWrongOrderFilter (): void
367
397
{
398
+ BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
368
399
$ res = $ this ->get ('/api/authors?order[name]=something ' , ['Accept ' => ['application/ld+json ' ]]);
369
400
$ this ->assertEquals ($ res ->getStatusCode (), 422 );
370
401
}
371
402
372
403
public function testWithAccessor (): void
373
404
{
405
+ WithAccessorFactory::new ()->create ();
374
406
$ res = $ this ->get ('/api/with_accessors/1 ' , ['Accept ' => ['application/ld+json ' ]]);
375
407
$ this ->assertArraySubset (['name ' => 'test ' ], $ res ->json ());
376
408
}
0 commit comments