Passed
Push — master ( cf44a0...dc02e6 )
by Mario
02:42
created

testPutHasOneFileUpload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace RafflesArgentina\ResourceController;
4
5
use Illuminate\Http\UploadedFile;
6
use Illuminate\Support\Facades\Storage;
7
8
use Orchestra\Testbench\TestCase;
9
10
class WorksWithFileUploadsTest extends TestCase
11
{
12
    use BaseTest;
13
14
    /**
15
     * @coversNothing
16
     */
17
    function testPostHasOneFileUpload()
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...
18
    {
19
        Storage::fake('uploads');
20
21
        $this->post(
22
            '/test', [
23
                'name' => 'Mario',
24
                'email' => '[email protected]',
25
                'password' => str_random(),
26
                'hasOneFileUpload' => [
27
                    UploadedFile::fake()->image('test.jpeg')
28
                ],
29
            ]
30
        )->assertRedirect('/test')
31
            ->assertSessionHas('rafflesargentina.status.success');
32
33
        $user = \RafflesArgentina\ResourceController\Models\User::first();
34
        $this->assertTrue(!is_null($user->hasOneFileUpload));
35
    }
36
37
    /**
38
     * @coversNothing
39
     */
40
    function testPostMorphOneFileUpload()
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...
41
    {
42
        Storage::fake('uploads');
43
44
        $this->post(
45
            '/test', [
46
            'name' => 'Mario',
47
            'email' => '[email protected]',
48
            'password' => str_random(),
49
                'morphOneFileUpload' => [
50
                    UploadedFile::fake()->image('test.jpeg')
51
                ],
52
            ]
53
        )->assertRedirect('/test')
54
            ->assertSessionHas('rafflesargentina.status.success');
55
56
        $user = \RafflesArgentina\ResourceController\Models\User::first();
57
        $this->assertTrue(!is_null($user->morphOneFileUpload));
58
    }
59
60
    /**
61
     * @coversNothing
62
     */
63
    function testPostBelongsToFileUpload()
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...
64
    {
65
        $user = \RafflesArgentina\ResourceController\Models\User::first();
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
66
67
        Storage::fake('uploads');
68
69
        $this->post(
70
            '/test', [
71
            'name' => 'Mario',
72
            'email' => '[email protected]',
73
            'password' => str_random(),
74
                'belongsToFileUpload' => [
75
                    UploadedFile::fake()->image('test.jpeg')
76
                ],
77
            ]
78
        )->assertRedirect('/test')
79
            ->assertSessionHas('rafflesargentina.status.success');
80
81
        $user = \RafflesArgentina\ResourceController\Models\User::first();
82
        $this->assertTrue(!is_null($user->belongsToFileUpload));
83
    }
84
85
    /**
86
     * @coversNothing
87
     */
88
    function testPostHasManyFileUploads()
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...
89
    {
90
        Storage::fake('uploads');
91
92
        $this->post(
93
            '/test', [
94
            'name' => 'Mario',
95
            'email' => '[email protected]',
96
            'password' => str_random(),
97
            'hasManyFileUploads' => [
98
                UploadedFile::fake()->image('test.jpeg'),
99
                UploadedFile::fake()->create('document.pdf')
100
            ]
101
            ]
102
        )->assertRedirect('/test')
103
            ->assertSessionHas('rafflesargentina.status.success');
104
105
        $user = \RafflesArgentina\ResourceController\Models\User::first();
106
        $this->assertTrue($user->hasManyFileUploads->count() === 2);
107
    }
108
109
    /**
110
     * @coversNothing
111
     */
112
    function testPostMorphManyFileUploads()
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...
113
    {
114
        $user = \RafflesArgentina\ResourceController\Models\User::first();
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
115
116
        Storage::fake('uploads');
117
118
        $this->post(
119
            '/test', [
120
            'name' => 'Mario',
121
            'email' => '[email protected]',
122
            'password' => str_random(),
123
            'morphManyFileUploads' => [
124
                UploadedFile::fake()->image('test.jpeg'),
125
                UploadedFile::fake()->create('document.pdf')
126
            ],
127
            ]
128
        )->assertRedirect('/test')
129
            ->assertSessionHas('rafflesargentina.status.success');
130
131
        $user = \RafflesArgentina\ResourceController\Models\User::first();
132
        $this->assertTrue($user->morphManyFileUploads->count() === 2);
133
    }
134
135
    /**
136
     * @coversNothing
137
     */
138
    function testPostBelongsToManyFileUploads()
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...
139
    {
140
        $user = \RafflesArgentina\ResourceController\Models\User::first();
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
141
142
        Storage::fake('uploads');
143
144
        $this->post(
145
            '/test', [
146
            'name' => 'Mario',
147
            'email' => '[email protected]',
148
            'password' => str_random(),
149
            'belongsToManyFileUploads' => [
150
                UploadedFile::fake()->image('test.jpeg'),
151
                UploadedFile::fake()->create('document.pdf')
152
            ],
153
            ]
154
        )->assertRedirect('/test')
155
            ->assertSessionHas('rafflesargentina.status.success');
156
157
        $user = \RafflesArgentina\ResourceController\Models\User::first();
158
        $this->assertTrue($user->belongsToManyFileUploads->count() === 2);
159
    }
160
161
    /**
162
     * @coversNothing
163
     */
164
    function testPostMorphToManyFileUploads()
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...
165
    {
166
        $user = \RafflesArgentina\ResourceController\Models\User::first();
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
167
168
        Storage::fake('uploads');
169
170
        $this->post(
171
            '/test', [
172
            'name' => 'Mario',
173
            'email' => '[email protected]',
174
            'password' => str_random(),
175
            'morphToManyFileUploads' => [
176
                '1' => UploadedFile::fake()->image('test.jpeg'),
177
                '2' => UploadedFile::fake()->create('document.pdf')
178
            ],
179
            ]
180
        )->assertRedirect('/test')
181
            ->assertSessionHas('rafflesargentina.status.success');
182
183
        $user = \RafflesArgentina\ResourceController\Models\User::first();
184
        $this->assertTrue($user->morphToManyFileUploads->count() === 2);
185
    }
186
187
    /**
188
     * @coversNothing
189
     */
190
    function testPutHasOneFileUpload()
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...
191
    {
192
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
193
194
        Storage::fake('uploads');
195
196
        $this->put(
197
            '/test/1', [
198
                'hasOneFileUpload' => [
199
                    UploadedFile::fake()->image('test.jpeg')
200
                ],
201
            ]
202
        )->assertRedirect('/test')
203
            ->assertSessionHas('rafflesargentina.status.success');
204
205
        $this->assertTrue(!is_null($user->hasOneFileUpload));
206
    }
207
208
    /**
209
     * @coversNothing
210
     */
211
    function testPutMorphOneFileUpload()
212
    {
213
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
214
215
        Storage::fake('uploads');
216
217
        $this->put(
218
            '/test/1', [
219
                'morphOneFileUpload' => [
220
                    UploadedFile::fake()->image('test.jpeg')
221
                ],
222
            ]
223
        )->assertRedirect('/test')
224
            ->assertSessionHas('rafflesargentina.status.success');
225
226
        $this->assertTrue(!is_null($user->morphOneFileUpload));
227
    }
228
229
    /**
230
     * @coversNothing
231
     */
232
    function testPutBelongsToFileUpload()
233
    {
234
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
235
236
        Storage::fake('uploads');
237
238
        $this->put(
239
            '/test/1', [
240
                'belongsToFileUpload' => [
241
                    UploadedFile::fake()->image('test.jpeg')
242
                ],
243
            ]
244
        )->assertRedirect('/test')
245
            ->assertSessionHas('rafflesargentina.status.success');
246
247
        $user->refresh();
248
        $this->assertTrue(!is_null($user->belongsToFileUpload));
249
    }
250
251
    /**
252
     * @coversNothing
253
     */
254
    function testPutHasManyFileUploads()
255
    {
256
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
257
258
        Storage::fake('uploads');
259
260
        $this->put(
261
            '/test/1', [
262
            'hasManyFileUploads' => [
263
                UploadedFile::fake()->image('test.jpeg'),
264
                UploadedFile::fake()->create('document.pdf')
265
            ]
266
            ]
267
        )->assertRedirect('/test')
268
            ->assertSessionHas('rafflesargentina.status.success');
269
270
        $this->assertTrue($user->hasManyFileUploads->count() === 2);
271
    }
272
273
    /**
274
     * @coversNothing
275
     */
276
    function testPutMorphManyFileUploads()
277
    {
278
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
279
280
        Storage::fake('uploads');
281
282
        $this->put(
283
            '/test/1', [
284
            'morphManyFileUploads' => [
285
                UploadedFile::fake()->image('test.jpeg'),
286
                UploadedFile::fake()->create('document.pdf')
287
            ],
288
            ]
289
        )->assertRedirect('/test')
290
            ->assertSessionHas('rafflesargentina.status.success');
291
292
        $this->assertTrue($user->morphManyFileUploads->count() === 2);
293
    }
294
295
    /**
296
     * @coversNothing
297
     */
298
    function testPutBelongsToManyFileUploads()
299
    {
300
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
301
302
        Storage::fake('uploads');
303
304
        $this->put(
305
            '/test/1', [
306
            'belongsToManyFileUploads' => [
307
                UploadedFile::fake()->image('test.jpeg'),
308
                UploadedFile::fake()->create('document.pdf')
309
            ],
310
            ]
311
        )->assertRedirect('/test')
312
            ->assertSessionHas('rafflesargentina.status.success');
313
314
        $this->assertTrue($user->belongsToManyFileUploads->count() === 2);
315
    }
316
317
    /**
318
     * @coversNothing
319
     */
320
    function testPutMorphToManyFileUploads()
321
    {
322
        $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create();
323
324
        Storage::fake('uploads');
325
326
        $this->put(
327
            '/test/1', [
328
            'morphToManyFileUploads' => [
329
                '1' => UploadedFile::fake()->image('test.jpeg'),
330
                '2' => UploadedFile::fake()->create('document.pdf')
331
            ],
332
            ]
333
        )->assertRedirect('/test')
334
            ->assertSessionHas('rafflesargentina.status.success');
335
336
        $this->assertTrue($user->morphToManyFileUploads->count() === 2);
337
    }
338
}
339