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

Passed
Pull Request — fix-uploaders (#5518)
by Cristian
26:32 queued 11:32
created

UploadersConfigurationTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 35
c 1
b 0
f 1
dl 0
loc 78
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A test_it_validates_the_file_namer_invalid_string() 0 11 1
A defineRoutes() 0 3 1
A test_it_can_access_the_uploaders_create_page() 0 4 1
A test_it_validates_the_file_namer_invalid_class() 0 11 1
A setUp() 0 6 1
A test_it_can_store_uploaded_files_using_our_file_name_generator() 0 27 2
1
<?php
2
3
namespace Backpack\CRUD\Tests\Feature;
4
5
use Backpack\CRUD\Tests\config\CrudPanel\BaseDBCrudPanel;
6
use Backpack\CRUD\Tests\config\HasUploadedFiles;
7
use Backpack\CRUD\Tests\config\Http\Controllers\UploaderConfigurationCrudController;
8
use Backpack\CRUD\Tests\config\Models\Uploader;
9
use Backpack\CRUD\Tests\config\Models\User;
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));
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
            'upload' => $this->getUploadedFile('avatar1.jpg'),
80
        ]);
81
82
        $response->assertStatus(500);
83
84
        throw $response->exception;
85
    }
86
87
    public function test_it_validates_the_file_namer_invalid_class()
88
    {
89
        $this->expectException(\Exception::class);
90
91
        $response = $this->get($this->testBaseUrl.'/invalid-file-namer-class', [
92
            'upload' => $this->getUploadedFile('avatar1.jpg'),
93
        ]);
94
95
        $response->assertStatus(500);
96
97
        throw $response->exception;
98
    }
99
}
100