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 Failed
Pull Request — main (#5478)
by Pedro
27:58
created

UploadersInternalsTest   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 53
c 2
b 0
f 0
dl 0
loc 128
rs 10
wmc 15

15 Methods

Rating   Name   Duplication   Size   Complexity  
A test_it_sets_the_disk_on_field() 0 5 1
A test_it_throws_exception_if_uploader_or_group_is_not_registered() 0 5 1
A test_it_registers_default_uploaders_classes() 0 5 1
A test_it_throws_exceptio_if_uploader_doesnt_exist() 0 4 1
A test_it_can_add_more_uploaders() 0 8 1
A test_it_can_replace_defined_uploaders() 0 12 1
A test_it_can_register_repeatable_uploaders() 0 11 1
A test_it_registers_default_uploaders() 0 7 1
A test_it_can_set_temporary_options() 0 6 1
A test_it_validates_a_custom_uploader() 0 4 1
A setUp() 0 4 1
A test_it_validates_uploaders_when_adding() 0 7 1
A test_it_sets_the_prefix_on_field() 0 5 1
A test_it_can_register_uploaders_in_a_new_group() 0 10 1
A test_it_can_get_the_uploaders_registered_macros() 0 3 1
1
<?php
2
3
namespace Backpack\CRUD\Tests\Unit\Uploaders;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
6
use Backpack\CRUD\app\Library\Uploaders\SingleBase64Image;
7
use Backpack\CRUD\app\Library\Uploaders\SingleFile;
8
use Backpack\CRUD\app\Library\Uploaders\Support\Interfaces\UploaderInterface;
9
use Backpack\CRUD\Tests\config\CrudPanel\BaseCrudPanel;
10
11
class UploadersInternalsTest extends BaseCrudPanel
12
{
13
    protected $uploaderRepository;
14
15
    public function setUp(): void
16
    {
17
        parent::setUp();
18
        $this->uploaderRepository = $this->app->make('UploadersRepository');
0 ignored issues
show
Bug introduced by
The method make() does not exist on null. ( Ignorable by Annotation )

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

18
        /** @scrutinizer ignore-call */ 
19
        $this->uploaderRepository = $this->app->make('UploadersRepository');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
    }
20
21
    public function test_it_registers_default_uploaders()
22
    {
23
        $this->assertTrue($this->uploaderRepository->hasUploadFor('image', 'withFiles'));
24
        $this->assertTrue($this->uploaderRepository->hasUploadFor('upload', 'withFiles'));
25
        $this->assertTrue($this->uploaderRepository->hasUploadFor('upload_multiple', 'withFiles'));
26
27
        $this->assertFalse($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles'));
28
    }
29
30
    public function test_it_registers_default_uploaders_classes()
31
    {
32
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), UploaderInterface::class, true));
33
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('upload', 'withFiles'), UploaderInterface::class, true));
34
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('upload_multiple', 'withFiles'), UploaderInterface::class, true));
35
    }
36
37
    public function test_it_throws_exception_if_uploader_or_group_is_not_registered()
38
    {
39
        $this->expectException(\Exception::class);
40
41
        $this->uploaderRepository->getUploadFor('dropzone', 'withFiles');
42
    }
43
44
    public function test_it_can_add_more_uploaders()
45
    {
46
        $this->uploaderRepository->addUploaderClasses([
47
            'dropzone' => SingleFile::class,
48
        ], 'withFiles');
49
50
        $this->assertTrue($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles'));
51
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('dropzone', 'withFiles'), UploaderInterface::class, true));
52
    }
53
54
    public function test_it_validates_uploaders_when_adding()
55
    {
56
        $this->expectException(\Exception::class);
57
58
        $this->uploaderRepository->addUploaderClasses([
59
            'dropzone' => 'InvalidClass',
60
        ], 'withFiles');
61
    }
62
63
    public function test_it_can_replace_defined_uploaders()
64
    {
65
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), SingleBase64Image::class, true));
66
67
        $this->uploaderRepository->addUploaderClasses([
68
            'image' => SingleFile::class,
69
            'dropzone' => SingleFile::class,
70
        ], 'withFiles');
71
72
        $this->assertTrue($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles'));
73
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('dropzone', 'withFiles'), SingleFile::class, true));
74
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), SingleFile::class, true));
75
    }
76
77
    public function test_it_can_register_uploaders_in_a_new_group()
78
    {
79
        $this->assertFalse($this->uploaderRepository->hasUploadFor('image', 'newGroup'));
80
81
        $this->uploaderRepository->addUploaderClasses([
82
            'image' => SingleFile::class,
83
        ], 'newGroup');
84
85
        $this->assertTrue($this->uploaderRepository->hasUploadFor('image', 'newGroup'));
86
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'newGroup'), SingleFile::class, true));
87
    }
88
89
    public function test_it_can_register_repeatable_uploaders()
90
    {
91
        CRUD::field('gallery')->subfields([
92
            [
93
                'name' => 'image',
94
                'type' => 'image',
95
                'withFiles' => true,
96
            ],
97
        ]);
98
99
        $this->assertTrue($this->uploaderRepository->hasRepeatableUploadersFor('gallery'));
100
    }
101
102
    public function test_it_throws_exceptio_if_uploader_doesnt_exist()
103
    {
104
        $this->expectException(\Exception::class);
105
        CRUD::field('upload')->type('custom_type')->withFiles();
0 ignored issues
show
Bug introduced by
The method withFiles() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudField. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

105
        CRUD::field('upload')->type('custom_type')->/** @scrutinizer ignore-call */ withFiles();
Loading history...
106
    }
107
108
    public function test_it_validates_a_custom_uploader()
109
    {
110
        $this->expectException(\Exception::class);
111
        CRUD::field('upload')->type('upload')->withFiles(['uploader' => 'InvalidClass']);
112
    }
113
114
    public function test_it_sets_the_prefix_on_field()
115
    {
116
        CRUD::field('upload')->type('upload')->withFiles(['path' => 'test']);
117
118
        $this->assertEquals('test/', CRUD::getFields()['upload']['prefix']);
0 ignored issues
show
Bug introduced by
The method getFields() does not exist on Backpack\CRUD\app\Librar...udPanel\CrudPanelFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

118
        $this->assertEquals('test/', CRUD::/** @scrutinizer ignore-call */ getFields()['upload']['prefix']);
Loading history...
119
    }
120
121
    public function test_it_sets_the_disk_on_field()
122
    {
123
        CRUD::field('upload')->type('upload')->withFiles(['disk' => 'test']);
124
125
        $this->assertEquals('test', CRUD::getFields()['upload']['disk']);
126
    }
127
128
    public function test_it_can_set_temporary_options()
129
    {
130
        CRUD::field('upload')->type('upload')->withFiles(['temporaryUrl' => true]);
131
132
        $this->assertTrue(CRUD::getFields()['upload']['temporary']);
133
        $this->assertEquals(1, CRUD::getFields()['upload']['expiration']);
134
    }
135
136
    public function test_it_can_get_the_uploaders_registered_macros()
137
    {
138
        $this->assertContains('withFiles', $this->uploaderRepository->getUploadersGroupsNames());
139
    }
140
}
141