Passed
Push — master ( 4573fb...494e83 )
by Mario
02:34
created

testUpdateMorphToManyInexistent()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
c 0
b 0
f 0
rs 8.8571
eloc 32
nc 1
nop 0
cc 1
1
<?php
2
3
namespace RafflesArgentina\ResourceController;
4
5
use Orchestra\Testbench\TestCase;
6
7
class WorksWithRelationsTest extends TestCase
8
{
9
    use BaseTest;
10
11
    function testStoreHasOne()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
    {
13
        $fillables = [
14
            'name' => 'Mario',
15
            'email' => '[email protected]',
16
            'password' => bcrypt(str_random()),
17
            'hasOneRelated' => [
18
                'a' => 'blah blah blah',
19
                'b' => 'blah blah blah',
20
                'c' => 'blah blah blah',
21
            ]
22
        ];
23
24
        $this->post('/test', $fillables)
25
            ->assertRedirect('/test')
26
            ->assertSessionHas('rafflesargentina.status.success');
27
28
        $user = \RafflesArgentina\ResourceController\Models\User::first();
29
        $this->assertTrue(!is_null($user->hasOneRelated));
30
31
        $user->forceDelete();
32
33
        $this->json('POST', '/test', $fillables)
34
            ->assertStatus(200)
35
            ->assertSessionHas('rafflesargentina.status.success');
36
        $user = \RafflesArgentina\ResourceController\Models\User::first();
37
        $this->assertTrue(!is_null($user->hasOneRelated));
38
39
        //dd($user->hasOneRelated->toJson());
40
    }
41
42
    function testStoreMorphOne()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
43
    {
44
        $fillables = [
45
            'name' => 'Mario',
46
            'email' => '[email protected]',
47
            'password' => bcrypt(str_random()),
48
            'morphOneRelated' => [
49
                'a' => 'blah blah blah',
50
                'b' => 'blah blah blah',
51
                'c' => 'blah blah blah',
52
            ]
53
        ];
54
55
        $this->post('/test', $fillables)
56
            ->assertRedirect('/test')
57
            ->assertSessionHas('rafflesargentina.status.success');
58
59
        $user = \RafflesArgentina\ResourceController\Models\User::first();
60
        $this->assertTrue(!is_null($user->morphOneRelated));
61
62
        $user->forceDelete();
63
64
        $this->json('POST', '/test', $fillables)
65
            ->assertStatus(200)
66
            ->assertSessionHas('rafflesargentina.status.success');
67
        $user = \RafflesArgentina\ResourceController\Models\User::first();
68
        $this->assertTrue(!is_null($user->morphOneRelated));
69
70
        //dd($user->hasOneRelated->toJson());
71
    }
72
73
    function testStoreBelongsTo()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
74
    {
75
        $fillables = [
76
            'name' => 'Mario',
77
            'email' => '[email protected]',
78
            'password' => bcrypt(str_random()),
79
            'belongsToRelated' => [
80
                'a' => 'blah blah blah',
81
                'b' => 'blah blah blah',
82
                'c' => 'blah blah blah',
83
            ]
84
        ];
85
86
        $this->post('/test', $fillables)
87
            ->assertRedirect('/test');
88
89
        $user = \RafflesArgentina\ResourceController\Models\User::first();
90
        $this->assertTrue(!is_null($user->belongsToRelated));
91
92
        $user->forceDelete();
93
94
        $this->json('POST', '/test', $fillables)->assertStatus(200);
95
        $user = \RafflesArgentina\ResourceController\Models\User::first();
96
        $this->assertTrue(!is_null($user->belongsToRelated));
97
98
        //dd($user->belongsToRelated->toJson());
99
    }
100
101
    function testStoreHasMany()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
102
    {
103
        $fillables = [
104
            'name' => 'Mario',
105
            'email' => '[email protected]',
106
            'password' => bcrypt(str_random()),
107
            'hasManyRelated' => [
108
                '1' => [
109
                    'a' => 'blah blah blah',
110
                    'b' => 'blah blah blah',
111
                    'c' => 'blah blah blah',
112
                ],
113
                '2' => [
114
                    'a' => 'bleh bleh bleh',
115
                    'b' => 'bleh bleh bleh',
116
                    'c' => 'bleh bleh bleh',
117
                ],
118
                '3' => [
119
                    'a' => 'blih blih blih',
120
                    'b' => 'blih blih blih',
121
                    'c' => 'blih blih blih',
122
                ],
123
                '4' => [
124
                    'a' => 'bloh bloh bloh',
125
                    'b' => 'bloh bloh bloh',
126
                    'c' => 'bloh bloh bloh',
127
                ],
128
                '5' => [
129
                    'a' => 'bluh bluh bluh',
130
                    'b' => 'bluh bluh bluh',
131
                    'c' => 'bluh bluh bluh',
132
                ]
133
            ]
134
        ];
135
136
        $this->post('/test', $fillables)->assertRedirect('/test');
137
        $user = \RafflesArgentina\ResourceController\Models\User::first();
138
        $this->assertTrue($user->hasManyRelated->count() === 5);
139
140
        $user->forceDelete();
141
142
        $this->json('POST', '/test', $fillables)->assertStatus(200);
143
        $user = \RafflesArgentina\ResourceController\Models\User::first();
144
        $this->assertTrue($user->hasManyRelated->count() === 5);
145
146
        //dd($user->hasManyRelated->toJson());
147
    }
148
149
    function testStoreMorphMany()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
150
    {
151
        $fillables = [
152
            'name' => 'Mario',
153
            'email' => '[email protected]',
154
            'password' => bcrypt(str_random()),
155
            'morphManyRelated' => [
156
                '1' => [
157
                    'a' => 'blah blah blah',
158
                    'b' => 'blah blah blah',
159
                    'c' => 'blah blah blah',
160
                ],
161
                '2' => [
162
                    'a' => 'bleh bleh bleh',
163
                    'b' => 'bleh bleh bleh',
164
                    'c' => 'bleh bleh bleh',
165
                ],
166
                '3' => [
167
                    'a' => 'blih blih blih',
168
                    'b' => 'blih blih blih',
169
                    'c' => 'blih blih blih',
170
                ],
171
                '4' => [
172
                    'a' => 'bloh bloh bloh',
173
                    'b' => 'bloh bloh bloh',
174
                    'c' => 'bloh bloh bloh',
175
                ],
176
                '5' => [
177
                    'a' => 'bluh bluh bluh',
178
                    'b' => 'bluh bluh bluh',
179
                    'c' => 'bluh bluh bluh',
180
                ]
181
            ]
182
        ];
183
184
        $this->post('/test', $fillables)->assertRedirect('/test');
185
        $user = \RafflesArgentina\ResourceController\Models\User::first();
186
        $this->assertTrue($user->morphManyRelated->count() === 5);
187
188
        $user->forceDelete();
189
190
        $this->json('POST', '/test', $fillables)->assertStatus(200);
191
        $user = \RafflesArgentina\ResourceController\Models\User::first();
192
        $this->assertTrue($user->morphManyRelated->count() === 5);
193
194
        //dd($user->hasManyRelated->toJson());
195
    }
196
197
    function testStoreBelongsToManyExistent()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
198
    {
199
        $related = factory(\RafflesArgentina\ResourceController\Models\Related::class, 5)->create();
200
201
        $existent = [];
202
        foreach ($related as $id => $model) {
203
            $existent[$model->id] = $model->getAttributes();
204
        }
205
206
        $fillables = [
207
            'name' => 'Mario',
208
            'email' => '[email protected]',
209
            'password' => bcrypt(str_random()),
210
            'belongsToManyRelated' => $existent,
211
        ];
212
213
        $this->post('/test', $fillables)->assertRedirect('/test');
214
        $user = \RafflesArgentina\ResourceController\Models\User::with('belongsToManyRelated')->first();
215
        $this->assertTrue($user->belongsToManyRelated->count() === 5);
216
217
        $user->forceDelete();
218
219
        $this->json('POST', '/test', $fillables)->assertStatus(200);
220
        $user = \RafflesArgentina\ResourceController\Models\User::first();
221
        $this->assertTrue($user->belongsToManyRelated->count() === 5);
222
223
        //dd($user->belongsToManyRelated->toJson());
224
    }
225
226
    function testStoreMorphToManyExistent()
227
    {
228
        $related = factory(\RafflesArgentina\ResourceController\Models\Related::class, 5)->create();
229
230
        $existent = [];
231
        foreach ($related as $id => $model) {
232
            $existent[$model->id] = $model->getAttributes();
233
        }
234
235
        $fillables = [
236
            'name' => 'Mario',
237
            'email' => '[email protected]',
238
            'password' => bcrypt(str_random()),
239
            'morphToManyRelated' => $existent,
240
        ];
241
242
        $this->post('/test', $fillables)->assertRedirect('/test');
243
244
        $user = \RafflesArgentina\ResourceController\Models\User::with('morphToManyRelated')->first();
245
246
        $this->assertTrue($user->morphToManyRelated->count() === 5);
0 ignored issues
show
Bug introduced by
The property morphToManyRelated does not exist on RafflesArgentina\ResourceController\Models\User. Did you mean morphManyRelated?
Loading history...
247
248
        $user->forceDelete();
249
250
        $this->json('POST', '/test', $fillables)->assertStatus(200);
251
        $user = \RafflesArgentina\ResourceController\Models\User::first();
252
        $this->assertTrue($user->morphTOManyRelated->count() === 5);
0 ignored issues
show
Bug introduced by
The property morphTOManyRelated does not exist on RafflesArgentina\ResourceController\Models\User. Did you mean morphManyRelated?
Loading history...
253
254
        //dd($user->belongsToManyRelated->toJson());
255
    }
256
257
    function testStoreBelongsToManyInexistent()
258
    {
259
        $fillables = [
260
            'name' => 'Mario',
261
            'email' => '[email protected]',
262
            'password' => bcrypt(str_random()),
263
            'belongsToManyRelated' => [
264
                '1' => [
265
                    'a' => 'blah blah blah',
266
                    'b' => 'blah blah blah',
267
                    'c' => 'blah blah blah',
268
                ],
269
                '2' => [
270
                    'a' => 'bleh bleh bleh',
271
                    'b' => 'bleh bleh bleh',
272
                    'c' => 'bleh bleh bleh',
273
                ],
274
                '3' => [
275
                    'a' => 'blih blih blih',
276
                    'b' => 'blih blih blih',
277
                    'c' => 'blih blih blih',
278
                ],
279
                '4' => [
280
                    'a' => 'bloh bloh bloh',
281
                    'b' => 'bloh bloh bloh',
282
                    'c' => 'bloh bloh bloh',
283
                ],
284
                '5' => [
285
                    'a' => 'bluh bluh bluh',
286
                    'b' => 'bluh bluh bluh',
287
                    'c' => 'bluh bluh bluh',
288
                ]
289
            ]
290
        ];
291
292
        $this->post('/test', $fillables)->assertRedirect('/test');
293
        $user = \RafflesArgentina\ResourceController\Models\User::with('belongsToManyRelated')->first();
294
        $this->assertTrue($user->belongsToManyRelated->count() === 5);
295
296
        $user->forceDelete();
297
298
        $this->json('POST', '/test', $fillables)->assertStatus(200);
299
        $user = \RafflesArgentina\ResourceController\Models\User::first();
300
        $this->assertTrue($user->belongsToManyRelated->count() === 5);
301
302
        //dd($user->belongsToManyRelated->toJson());
303
    }
304
305
    function testStoreMorphToManyInexistent()
306
    {
307
        $fillables = [
308
            'name' => 'Mario',
309
            'email' => '[email protected]',
310
            'password' => bcrypt(str_random()),
311
            'morphToManyRelated' => [
312
                '1' => [
313
                    'a' => 'blah blah blah',
314
                    'b' => 'blah blah blah',
315
                    'c' => 'blah blah blah',
316
                ],
317
                '2' => [
318
                    'a' => 'bleh bleh bleh',
319
                    'b' => 'bleh bleh bleh',
320
                    'c' => 'bleh bleh bleh',
321
                ],
322
                '3' => [
323
                    'a' => 'blih blih blih',
324
                    'b' => 'blih blih blih',
325
                    'c' => 'blih blih blih',
326
                ],
327
                '4' => [
328
                    'a' => 'bloh bloh bloh',
329
                    'b' => 'bloh bloh bloh',
330
                    'c' => 'bloh bloh bloh',
331
                ],
332
                '5' => [
333
                    'a' => 'bluh bluh bluh',
334
                    'b' => 'bluh bluh bluh',
335
                    'c' => 'bluh bluh bluh',
336
                ]
337
            ]
338
        ];
339
340
        $this->post('/test', $fillables)->assertRedirect('/test');
341
        $user = \RafflesArgentina\ResourceController\Models\User::with('morphToManyRelated')->first();
342
        $this->assertTrue($user->morphToManyRelated->count() === 5);
0 ignored issues
show
Bug introduced by
The property morphToManyRelated does not exist on RafflesArgentina\ResourceController\Models\User. Did you mean morphManyRelated?
Loading history...
343
344
        $user->forceDelete();
345
346
        $this->json('POST', '/test', $fillables)->assertStatus(200);
347
        $user = \RafflesArgentina\ResourceController\Models\User::first();
348
        $this->assertTrue($user->morphToManyRelated->count() === 5);
349
350
        //dd($user->belongsToManyRelated->toJson());
351
    }
352
353
    function testUpdateHasOne()
354
    {
355
        $fillables = [
356
            'name' => 'Mario',
357
            'email' => '[email protected]',
358
            'password' => bcrypt(str_random()),
359
            'hasOneRelated' => [
360
                'a' => 'blah blah blah',
361
                'b' => 'blah blah blah',
362
                'c' => 'blah blah blah',
363
            ]
364
        ];
365
366
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
367
        $this->put('/test/1', $fillables)->assertRedirect('/test');
368
        $this->assertTrue(!is_null($user->hasOneRelated));
369
370
        $user->forceDelete();
371
372
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
373
        $this->json('PUT', '/test/2', $fillables)->assertStatus(200);
374
        $this->assertTrue(!is_null($user->hasOneRelated));
375
    }
376
377
    function testUpdateMorphOne()
378
    {
379
        $fillables = [
380
            'name' => 'Mario',
381
            'email' => '[email protected]',
382
            'password' => bcrypt(str_random()),
383
            'morphOneRelated' => [
384
                'a' => 'blah blah blah',
385
                'b' => 'blah blah blah',
386
                'c' => 'blah blah blah',
387
            ]
388
        ];
389
390
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
391
        $this->put('/test/1', $fillables)->assertRedirect('/test');
392
        $this->assertTrue(!is_null($user->morphOneRelated));
393
394
        $user->forceDelete();
395
396
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
397
        $this->json('PUT', '/test/2', $fillables)->assertStatus(200);
398
        $this->assertTrue(!is_null($user->morphOneRelated));
399
    }
400
401
    function testUpdateBelongsTo()
402
    {
403
        $fillables = [
404
            'name' => 'Mario',
405
            'email' => '[email protected]',
406
            'password' => bcrypt(str_random()),
407
            'belongsToRelated' => [
408
                'a' => 'blah blah blah',
409
                'b' => 'blah blah blah',
410
                'c' => 'blah blah blah',
411
            ]
412
        ];
413
414
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
415
        $this->put('/test/1', $fillables)->assertRedirect('/test');
416
        $user = \RafflesArgentina\ResourceController\Models\User::first();
417
        $this->assertTrue(!is_null($user->belongsToRelated));
418
419
        $user->forceDelete();
420
421
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
422
        $this->json('PUT', '/test/2', $fillables)->assertStatus(200);
423
        $user = \RafflesArgentina\ResourceController\Models\User::first();
424
        $this->assertTrue(!is_null($user->belongsToRelated));
425
    }
426
427
    function testUpdateHasMany()
428
    {
429
        $fillables = [
430
            'name' => 'Mario',
431
            'email' => '[email protected]',
432
            'password' => bcrypt(str_random()),
433
            'hasManyRelated' => [
434
                '1' => [
435
                    'a' => 'blah blah blah',
436
                    'b' => 'blah blah blah',
437
                    'c' => 'blah blah blah',
438
                ],
439
                '2' => [
440
                    'a' => 'bleh bleh bleh',
441
                    'b' => 'bleh bleh bleh',
442
                    'c' => 'bleh bleh bleh',
443
                ],
444
                '3' => [
445
                    'a' => 'blih blih blih',
446
                    'b' => 'blih blih blih',
447
                    'c' => 'blih blih blih',
448
                ],
449
                '4' => [
450
                    'a' => 'bloh bloh bloh',
451
                    'b' => 'bloh bloh bloh',
452
                    'c' => 'bloh bloh bloh',
453
                ],
454
                '5' => [
455
                    'a' => 'bluh bluh bluh',
456
                    'b' => 'bluh bluh bluh',
457
                    'c' => 'bluh bluh bluh',
458
                ]
459
            ]
460
        ];
461
462
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
463
        $this->put('/test/1', $fillables)->assertRedirect('/test');
464
        $this->assertTrue($user->hasManyRelated->count() === 5);
465
466
        $user->forceDelete();
467
468
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
469
        $this->json('PUT', '/test/2', $fillables)->assertStatus(200);
470
        $this->assertTrue($user->hasManyRelated->count() === 5);
471
    }
472
473
    function testUpdateMorphMany()
474
    {
475
        $fillables = [
476
            'name' => 'Mario',
477
            'email' => '[email protected]',
478
            'password' => bcrypt(str_random()),
479
            'morphManyRelated' => [
480
                '1' => [
481
                    'a' => 'blah blah blah',
482
                    'b' => 'blah blah blah',
483
                    'c' => 'blah blah blah',
484
                ],
485
                '2' => [
486
                    'a' => 'bleh bleh bleh',
487
                    'b' => 'bleh bleh bleh',
488
                    'c' => 'bleh bleh bleh',
489
                ],
490
                '3' => [
491
                    'a' => 'blih blih blih',
492
                    'b' => 'blih blih blih',
493
                    'c' => 'blih blih blih',
494
                ],
495
                '4' => [
496
                    'a' => 'bloh bloh bloh',
497
                    'b' => 'bloh bloh bloh',
498
                    'c' => 'bloh bloh bloh',
499
                ],
500
                '5' => [
501
                    'a' => 'bluh bluh bluh',
502
                    'b' => 'bluh bluh bluh',
503
                    'c' => 'bluh bluh bluh',
504
                ]
505
            ]
506
        ];
507
508
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
509
        $this->put('/test/1', $fillables)->assertRedirect('/test');
510
        $this->assertTrue($user->morphManyRelated->count() === 5);
511
512
        $user->forceDelete();
513
514
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
515
        $this->json('PUT', '/test/2', $fillables)->assertStatus(200);
516
        $this->assertTrue($user->morphManyRelated->count() === 5);
517
    }
518
519
    function testUpdateBelongsToManyExistent()
520
    {
521
        $related = factory(\RafflesArgentina\ResourceController\Models\Related::class, 5)->create();
522
523
        $existent = [];
524
        foreach ($related as $id => $model) {
525
            $existent[$model->id] = $model->getAttributes();
526
        }
527
528
        $fillables = [
529
            'name' => 'Mario',
530
            'email' => '[email protected]',
531
            'password' => bcrypt(str_random()),
532
            'belongsToManyRelated' => $existent
533
        ];
534
535
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
536
        $this->put('/test/1', $fillables)->assertRedirect('/test');
537
        $this->assertTrue($user->belongsToManyRelated->count() === 5);
538
539
        $user->forceDelete();
540
541
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
542
        $this->json('PUT','/test/2', $fillables)->assertStatus(200);
543
        $this->assertTrue($user->belongsToManyRelated->count() === 5);
544
    }
545
546
    function testUpdateMorphToManyExistent()
547
    {
548
        $related = factory(\RafflesArgentina\ResourceController\Models\Related::class, 5)->create();
549
550
        $existent = [];
551
        foreach ($related as $id => $model) {
552
            $existent[$model->id] = $model->getAttributes();
553
        }
554
555
        $fillables = [
556
            'name' => 'Mario',
557
            'email' => '[email protected]',
558
            'password' => bcrypt(str_random()),
559
            'morphToManyRelated' => $existent
560
        ];
561
562
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
563
        $this->put('/test/1', $fillables)->assertRedirect('/test');
564
        $this->assertTrue($user->morphToManyRelated->count() === 5);
565
566
        $user->forceDelete();
567
568
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
569
        $this->json('PUT','/test/2', $fillables)->assertStatus(200);
570
        $this->assertTrue($user->morphToManyRelated->count() === 5);
571
    }
572
573
    function testUpdateBelongsToManyInexistent()
574
    {
575
        $fillables = [
576
            'name' => 'Mario',
577
            'email' => '[email protected]',
578
            'password' => bcrypt(str_random()),
579
            'belongsToManyRelated' => [
580
                '1' => [
581
                    'a' => 'blah blah blah',
582
                    'b' => 'blah blah blah',
583
                    'c' => 'blah blah blah',
584
                ],
585
                '2' => [
586
                    'a' => 'bleh bleh bleh',
587
                    'b' => 'bleh bleh bleh',
588
                    'c' => 'bleh bleh bleh',
589
                ],
590
                '3' => [
591
                    'a' => 'blih blih blih',
592
                    'b' => 'blih blih blih',
593
                    'c' => 'blih blih blih',
594
                ],
595
                '4' => [
596
                    'a' => 'bloh bloh bloh',
597
                    'b' => 'bloh bloh bloh',
598
                    'c' => 'bloh bloh bloh',
599
                ],
600
                '5' => [
601
                    'a' => 'bluh bluh bluh',
602
                    'b' => 'bluh bluh bluh',
603
                    'c' => 'bluh bluh bluh',
604
                ]
605
            ]
606
        ];
607
608
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
609
        $this->put('/test/1', $fillables)->assertRedirect('/test');
610
        $this->assertTrue($user->belongsToManyRelated->count() === 5);
611
612
        $user->forceDelete();
613
614
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
615
        $this->json('PUT','/test/2', $fillables)->assertStatus(200);
616
        $this->assertTrue($user->belongsToManyRelated->count() === 5);
617
    }
618
619
    function testUpdateMorphToManyInexistent()
620
    {
621
        $fillables = [
622
            'name' => 'Mario',
623
            'email' => '[email protected]',
624
            'password' => bcrypt(str_random()),
625
            'morphToManyRelated' => [
626
                '1' => [
627
                    'a' => 'blah blah blah',
628
                    'b' => 'blah blah blah',
629
                    'c' => 'blah blah blah',
630
                ],
631
                '2' => [
632
                    'a' => 'bleh bleh bleh',
633
                    'b' => 'bleh bleh bleh',
634
                    'c' => 'bleh bleh bleh',
635
                ],
636
                '3' => [
637
                    'a' => 'blih blih blih',
638
                    'b' => 'blih blih blih',
639
                    'c' => 'blih blih blih',
640
                ],
641
                '4' => [
642
                    'a' => 'bloh bloh bloh',
643
                    'b' => 'bloh bloh bloh',
644
                    'c' => 'bloh bloh bloh',
645
                ],
646
                '5' => [
647
                    'a' => 'bluh bluh bluh',
648
                    'b' => 'bluh bluh bluh',
649
                    'c' => 'bluh bluh bluh',
650
                ]
651
            ]
652
        ];
653
654
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
655
        $this->put('/test/1', $fillables)->assertRedirect('/test');
656
        $this->assertTrue($user->morphToManyRelated->count() === 5);
657
658
        $user->forceDelete();
659
660
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
661
        $this->json('PUT','/test/2', $fillables)->assertStatus(200);
662
        $this->assertTrue($user->morphToManyRelated->count() === 5);
663
    }
664
}
665