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

testPostMorphToManyFileUploads()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
rs 9.4285
eloc 13
nc 1
nop 0
cc 1
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
    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...
15
    {
16
        $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...
17
18
        Storage::fake('uploads');
19
20
        $this->post('/test', [
21
            'name' => 'Mario',
22
            'email' => '[email protected]',
23
            'password' => str_random(),
24
            'hasOneFileUpload' => [
25
                UploadedFile::fake()->image('test.jpeg')
26
            ],
27
        ])->assertRedirect('/test')
28
          ->assertSessionHas('rafflesargentina.status.success');
29
30
        $user = \RafflesArgentina\ResourceController\Models\User::first();
31
        $this->assertTrue(!is_null($user->hasOneFileUpload));
32
    }
33
34
    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...
35
    {
36
        $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...
37
38
        Storage::fake('uploads');
39
40
        $this->post('/test', [
41
            'name' => 'Mario',
42
            'email' => '[email protected]',
43
            'password' => str_random(),
44
            'morphOneFileUpload' => [
45
                UploadedFile::fake()->image('test.jpeg')
46
            ],
47
        ])->assertRedirect('/test')
48
          ->assertSessionHas('rafflesargentina.status.success');
49
50
        $user = \RafflesArgentina\ResourceController\Models\User::first();
51
        $this->assertTrue(!is_null($user->morphOneFileUpload));
52
    }
53
54
    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...
55
    {
56
        $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...
57
58
        Storage::fake('uploads');
59
60
        $this->post('/test', [
61
            'name' => 'Mario',
62
            'email' => '[email protected]',
63
            'password' => str_random(),
64
            'belongsToFileUpload' => [
65
                UploadedFile::fake()->image('test.jpeg')
66
            ],
67
        ])->assertRedirect('/test')
68
          ->assertSessionHas('rafflesargentina.status.success');
69
70
        $user = \RafflesArgentina\ResourceController\Models\User::first();
71
        $this->assertTrue(!is_null($user->belongsToFileUpload));
72
    }
73
74
    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...
75
    {
76
        $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...
77
78
        Storage::fake('uploads');
79
80
        $this->post('/test', [
81
            'name' => 'Mario',
82
            'email' => '[email protected]',
83
            'password' => str_random(),
84
            'hasManyFileUploads' => [
85
                '1' => UploadedFile::fake()->image('test.jpeg'),
86
                '2' => UploadedFile::fake()->create('document.pdf')
87
            ],
88
        ])->assertRedirect('/test')
89
          ->assertSessionHas('rafflesargentina.status.success');
90
91
        $user = \RafflesArgentina\ResourceController\Models\User::first();
92
        $this->assertTrue($user->hasManyFileUploads->count() === 2);
93
    }
94
95
    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...
96
    {
97
        $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...
98
99
        Storage::fake('uploads');
100
101
        $this->post('/test', [
102
            'name' => 'Mario',
103
            'email' => '[email protected]',
104
            'password' => str_random(),
105
            'morphManyFileUploads' => [
106
                '1' => UploadedFile::fake()->image('test.jpeg'),
107
                '2' => UploadedFile::fake()->create('document.pdf')
108
            ],
109
        ])->assertRedirect('/test')
110
          ->assertSessionHas('rafflesargentina.status.success');
111
112
        $user = \RafflesArgentina\ResourceController\Models\User::first();
113
        $this->assertTrue($user->morphManyFileUploads->count() === 2);
114
    }
115
116
    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...
117
    {
118
        $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...
119
120
        Storage::fake('uploads');
121
122
        $this->post('/test', [
123
            'name' => 'Mario',
124
            'email' => '[email protected]',
125
            'password' => str_random(),
126
            'belongsToManyFileUploads' => [
127
                '1' => UploadedFile::fake()->image('test.jpeg'),
128
                '2' => UploadedFile::fake()->create('document.pdf')
129
            ],
130
        ])->assertRedirect('/test')
131
          ->assertSessionHas('rafflesargentina.status.success');
132
133
        $user = \RafflesArgentina\ResourceController\Models\User::first();
134
        $this->assertTrue($user->belongsToManyFileUploads->count() === 2);
135
    }
136
137
    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...
138
    {
139
        $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...
140
141
        Storage::fake('uploads');
142
143
        $this->post('/test', [
144
            'name' => 'Mario',
145
            'email' => '[email protected]',
146
            'password' => str_random(),
147
            'morphToManyFileUploads' => [
148
                '1' => UploadedFile::fake()->image('test.jpeg'),
149
                '2' => UploadedFile::fake()->create('document.pdf')
150
            ],
151
        ])->assertRedirect('/test')
152
          ->assertSessionHas('rafflesargentina.status.success');
153
154
        $user = \RafflesArgentina\ResourceController\Models\User::first();
155
        $this->assertTrue($user->morphToManyFileUploads->count() === 2);
0 ignored issues
show
Bug introduced by
The property morphToManyFileUploads does not seem to exist on RafflesArgentina\ResourceController\Models\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
156
    }
157
}
158