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
Push — add-uploaders-tests ( 86a98c...2f90b7 )
by Pedro
10:47
created

UploadersInternalsTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
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
use PHPUnit\Framework\Attributes\Group;
11
12
class UploadersInternalsTest extends BaseCrudPanel
13
{
14
    protected $uploaderRepository;
15
16
    public function setUp(): void
17
    {
18
        parent::setUp();
19
        $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

19
        /** @scrutinizer ignore-call */ 
20
        $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...
20
    }
21
22
    public function test_it_registers_default_uploaders()
23
    {
24
        $this->assertTrue($this->uploaderRepository->hasUploadFor('image', 'withFiles'));
25
        $this->assertTrue($this->uploaderRepository->hasUploadFor('upload', 'withFiles'));
26
        $this->assertTrue($this->uploaderRepository->hasUploadFor('upload_multiple', 'withFiles'));
27
28
        $this->assertFalse($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles'));
29
    }
30
31
    public function test_it_registers_default_uploaders_classes()
32
    {
33
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), UploaderInterface::class, true));
34
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('upload', 'withFiles'), UploaderInterface::class, true));
35
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('upload_multiple', 'withFiles'), UploaderInterface::class, true));
36
    }
37
38
    public function test_it_throws_exception_if_uploader_or_group_is_not_registered()
39
    {
40
        $this->expectException(\Exception::class);
41
42
        $this->uploaderRepository->getUploadFor('dropzone', 'withFiles');
43
    }
44
45
    public function test_it_can_add_more_uploaders()
46
    {
47
        $this->uploaderRepository->addUploaderClasses([
48
            'dropzone' => SingleFile::class,
49
        ], 'withFiles');
50
51
        $this->assertTrue($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles'));
52
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('dropzone', 'withFiles'), UploaderInterface::class, true));
53
    }
54
55
    public function test_it_validates_uploaders_when_adding()
56
    {
57
        $this->expectException(\Exception::class);
58
59
        $this->uploaderRepository->addUploaderClasses([
60
            'dropzone' => 'InvalidClass',
61
        ], 'withFiles');
62
    }
63
64
    public function test_it_can_replace_defined_uploaders()
65
    {
66
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), SingleBase64Image::class, true));
67
68
        $this->uploaderRepository->addUploaderClasses([
69
            'image'    => SingleFile::class,
70
            'dropzone' => SingleFile::class,
71
        ], 'withFiles');
72
73
        $this->assertTrue($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles'));
74
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('dropzone', 'withFiles'), SingleFile::class, true));
75
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), SingleFile::class, true));
76
    }
77
78
    public function test_it_can_register_uploaders_in_a_new_group()
79
    {
80
        $this->assertFalse($this->uploaderRepository->hasUploadFor('image', 'newGroup'));
81
82
        $this->uploaderRepository->addUploaderClasses([
83
            'image' => SingleFile::class,
84
        ], 'newGroup');
85
86
        $this->assertTrue($this->uploaderRepository->hasUploadFor('image', 'newGroup'));
87
        $this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'newGroup'), SingleFile::class, true));
88
    }
89
90
    public function test_it_can_register_repeatable_uploaders()
91
    {
92
        CRUD::field('gallery')->subfields([
93
            [
94
                'name'      => 'image',
95
                'type'      => 'image',
96
                'withFiles' => true,
97
            ],
98
        ]);
99
100
        $this->assertTrue($this->uploaderRepository->hasRepeatableUploadersFor('gallery'));
101
    }
102
103
    public function test_it_throws_exceptio_if_uploader_doesnt_exist()
104
    {
105
        $this->expectException(\Exception::class);
106
        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

106
        CRUD::field('upload')->type('custom_type')->/** @scrutinizer ignore-call */ withFiles();
Loading history...
107
    }
108
109
    public function test_it_validates_a_custom_uploader()
110
    {
111
        $this->expectException(\Exception::class);
112
        CRUD::field('upload')->type('upload')->withFiles(['uploader' => 'InvalidClass']);
113
    }
114
115
    public function test_it_sets_the_prefix_on_field()
116
    {
117
        CRUD::field('upload')->type('upload')->withFiles(['path' => 'test']);
118
119
        $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

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