Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

test_it_can_use_a_custom_uploader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 7
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 15
rs 10
1
<?php
2
3
namespace Backpack\CRUD\Tests\Feature;
4
5
use Backpack\CRUD\Tests\config\CrudPanel\BaseDBCrudPanel;
6
use Backpack\CRUD\Tests\config\Http\Controllers\UploaderConfigurationCrudController;
7
use Backpack\CRUD\Tests\config\Models\Uploader;
8
use Backpack\CRUD\Tests\config\Models\User;
9
use Backpack\CRUD\Tests\config\Uploads\HasUploadedFiles;
10
use Illuminate\Support\Facades\Storage;
11
12
/**
13
 * @covers Backpack\CRUD\app\Library\Uploaders\Uploader
14
 * @covers Backpack\CRUD\app\Library\Uploaders\SingleFile
15
 * @covers Backpack\CRUD\app\Library\Uploaders\MultipleFiles
16
 * @covers Backpack\CRUD\app\Library\Uploaders\Support\RegisterUploadEvents
17
 * @covers Backpack\CRUD\app\Library\Uploaders\Support\UploadersRepository
18
 * @covers Backpack\CRUD\app\Library\Uploaders\Support\FileNameGenerator
19
 */
20
class UploadersConfigurationTest extends BaseDBCrudPanel
21
{
22
    use HasUploadedFiles;
23
24
    protected string $testBaseUrl;
25
26
    protected function defineRoutes($router)
27
    {
28
        $router->crud(config('backpack.base.route_prefix').'/uploader-configuration', UploaderConfigurationCrudController::class);
29
    }
30
31
    protected function setUp(): void
32
    {
33
        parent::setUp();
34
        $this->testBaseUrl = config('backpack.base.route_prefix').'/uploader-configuration';
35
        Storage::fake('uploaders');
36
        $this->actingAs(User::find(1));
0 ignored issues
show
Bug introduced by
It seems like Backpack\CRUD\Tests\config\Models\User::find(1) can also be of type Illuminate\Database\Eloq...gHasThroughRelationship and null; however, parameter $user of Orchestra\Testbench\TestCase::actingAs() does only seem to accept Illuminate\Contracts\Auth\Authenticatable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        $this->actingAs(/** @scrutinizer ignore-type */ User::find(1));
Loading history...
37
    }
38
39
    public function test_it_can_access_the_uploaders_create_page()
40
    {
41
        $response = $this->get($this->testBaseUrl.'/create');
42
        $response->assertStatus(200);
43
    }
44
45
    public function test_it_can_store_uploaded_files_using_our_file_name_generator()
46
    {
47
        $response = $this->post($this->testBaseUrl, [
48
            'upload' => $this->getUploadedFile('avatar1.jpg'),
49
            'upload_multiple' => $this->getUploadedFiles(['avatar2.jpg', 'avatar3.jpg']),
50
        ]);
51
52
        $response->assertStatus(302);
53
54
        $response->assertRedirect($this->testBaseUrl);
55
56
        $this->assertDatabaseCount('uploaders', 1);
57
58
        $files = Storage::disk('uploaders')->allFiles();
59
60
        $this->assertEquals(3, count($files));
61
62
        foreach ($files as $file) {
63
            $this->assertMatchesRegularExpression('/avatar\d{1}-[a-zA-Z0-9]{4}\.jpg/', $file);
64
        }
65
66
        // get the entry from database and also make sure the file names are stored correctly
67
        $entry = Uploader::first();
68
        $this->assertNotNull($entry);
69
        $this->assertMatchesRegularExpression('/avatar\d{1}-[a-zA-Z0-9]{4}\.jpg/', $entry->upload);
0 ignored issues
show
Bug introduced by
The property upload does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
70
        $this->assertMatchesRegularExpression('/avatar\d{1}-[a-zA-Z0-9]{4}\.jpg/', $entry->upload_multiple[0]);
0 ignored issues
show
Bug introduced by
The property upload_multiple does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
71
        $this->assertMatchesRegularExpression('/avatar\d{1}-[a-zA-Z0-9]{4}\.jpg/', $entry->upload_multiple[1]);
72
    }
73
74
    public function test_it_validates_the_file_namer_invalid_string()
75
    {
76
        $this->expectException(\Exception::class);
77
78
        $response = $this->get($this->testBaseUrl.'/invalid-file-namer');
79
80
        $response->assertStatus(500);
81
82
        throw $response->exception;
83
    }
84
85
    public function test_it_validates_the_file_namer_invalid_class()
86
    {
87
        $this->expectException(\Exception::class);
88
89
        $response = $this->get($this->testBaseUrl.'/invalid-file-namer-class');
90
91
        $response->assertStatus(500);
92
93
        throw $response->exception;
94
    }
95
96
    public function test_it_can_use_a_custom_uploader()
97
    {
98
        $response = $this->post($this->testBaseUrl.'/custom-uploader', [
99
            'upload' => $this->getUploadedFile('avatar1.jpg'),
100
        ]);
101
102
        $response->assertStatus(302);
103
104
        $response->assertRedirect($this->testBaseUrl);
105
106
        $this->assertDatabaseCount('uploaders', 1);
107
108
        $files = Storage::disk('uploaders')->allFiles();
109
110
        $this->assertEquals(1, count($files));
111
    }
112
113
    public function test_it_validates_the_custom_uploader_class()
114
    {
115
        $this->expectException(\Exception::class);
116
117
        $response = $this->post($this->testBaseUrl.'/custom-invalid-uploader', [
118
            'upload' => $this->getUploadedFile('avatar1.jpg'),
119
        ]);
120
121
        $response->assertStatus(500);
122
123
        throw $response->exception;
124
    }
125
}
126