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 — CrudButton-fixees ( a4c9f3...1a6e15 )
by Pedro
15:19
created

CrudPanelFiltersTest   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 198
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 3
Metric Value
eloc 112
dl 0
loc 198
c 4
b 1
f 3
rs 10
wmc 18

18 Methods

Rating   Name   Duplication   Size   Complexity  
A testItEnablesTheFiltersButConsiderThemDisableIfEmpty() 0 4 1
A testItCanAddFiltersToCrudPanel() 0 5 1
A testItCanClearFilters() 0 6 1
A testItCanGetTheViewWithNamespace() 0 7 1
A testItCanRemoveAFilterAttribute() 0 8 1
A testWhenActiveAndWhenInactiveAliases() 0 13 1
A testItCanAddAFilterAfterOtherFilter() 0 9 1
A testIfNotActiveAlias() 0 7 1
A testItCanCreateAFilterFluently() 0 23 1
A testItCanCheckIfFilterWasApplied() 0 6 1
A testItCanRemoveAFilter() 0 8 1
A testWhenNotActiveAlias() 0 7 1
A testItCanMakeAFilterFirst() 0 8 1
A testElseAlias() 0 7 1
A testItCanAddAFilterBeforeOtherFilter() 0 8 1
A testItCanGetAllFilterViewNamespacesWithFallbacks() 0 6 1
A testItCanMakeAFilterLast() 0 8 1
A testItCanCheckIfFilterIsActiveFromRequest() 0 11 1
1
<?php
2
3
namespace Backpack\CRUD\Tests\Unit\CrudPanel;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudFilter;
6
use Backpack\CRUD\Tests\Unit\Models\User;
7
use Config;
8
9
/**
10
 * @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Filters
11
 * @covers Backpack\CRUD\app\Library\CrudPanel\CrudFilter
12
 */
13
class CrudPanelFiltersTest extends BaseCrudPanelTest
14
{
15
    protected $testFilter = [[
16
        'name'  => 'my_filter',
17
        'type'  => 'simple',
18
        'label' => 'filter label',
19
    ], false, false, false];
20
21
    protected $testFilter_2 = [[
22
        'name'  => 'my_filter_2',
23
        'label' => 'filter label 2',
24
    ], false, false, false];
25
26
    public function testItEnablesTheFiltersButConsiderThemDisableIfEmpty()
27
    {
28
        $this->crudPanel->enableFilters();
29
        $this->assertFalse($this->crudPanel->filtersEnabled());
30
    }
31
32
    public function testItCanAddFiltersToCrudPanel()
33
    {
34
        $this->crudPanel->addFilter(...$this->testFilter);
0 ignored issues
show
Bug introduced by
$this->testFilter is expanded, but the parameter $options of Backpack\CRUD\app\Librar...\CrudPanel::addFilter() does not expect variable arguments. ( Ignorable by Annotation )

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

34
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
35
36
        $this->assertCount(1, $this->crudPanel->filters());
37
    }
38
39
    public function testItCanClearFilters()
40
    {
41
        $this->crudPanel->addFilter(...$this->testFilter);
0 ignored issues
show
Bug introduced by
$this->testFilter is expanded, but the parameter $options of Backpack\CRUD\app\Librar...\CrudPanel::addFilter() does not expect variable arguments. ( Ignorable by Annotation )

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

41
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
42
43
        $this->crudPanel->clearFilters();
44
        $this->assertCount(0, $this->crudPanel->filters());
45
    }
46
47
    public function testItCanCheckIfFilterIsActiveFromRequest()
48
    {
49
        $this->crudPanel->setModel(User::class);
50
        $request = request()->create('/admin/users', 'GET', ['my_custom_filter' => 'foo']);
51
        $request->setRouteResolver(function () use ($request) {
52
            return (new Route('GET', 'admin/users', ['UserCrudController', 'index']))->bind($request);
0 ignored issues
show
Bug introduced by
The type Backpack\CRUD\Tests\Unit\CrudPanel\Route was not found. Did you mean Route? If so, make sure to prefix the type with \.
Loading history...
53
        });
54
        $this->crudPanel->setRequest($request);
55
56
        $isActive = CrudFilter::name('my_custom_filter')->isActive();
0 ignored issues
show
Bug introduced by
The method isActive() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

56
        $isActive = CrudFilter::name('my_custom_filter')->/** @scrutinizer ignore-call */ isActive();
Loading history...
57
        $this->assertTrue($isActive);
58
    }
59
60
    public function testItCanCreateAFilterFluently()
61
    {
62
        CrudFilter::name('my_filter')
63
                    ->type('simple')
0 ignored issues
show
Bug introduced by
The method type() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

63
                    ->/** @scrutinizer ignore-call */ type('simple')
Loading history...
64
                    ->label('custom_label')
65
                    ->options(['test' => 'test'])
66
                    ->view('simple')
67
                    ->viewNamespace('crud::filters')
68
                    ->ifActive(function () {
69
                        return true;
70
                    })
71
                    ->ifInactive(function () {
72
                        return true;
73
                    });
74
75
        $this->assertCount(1, $this->crudPanel->filters());
76
        $filter = $this->crudPanel->filters()[0];
77
        $this->assertTrue(is_callable($filter->fallbackLogic));
78
        $this->assertTrue(is_callable($filter->logic));
79
        $this->assertEquals(['test' => 'test'], $filter->values);
80
        $this->assertEquals('custom_label', $filter->label);
81
        $this->assertEquals('simple', $filter->type);
82
        $this->assertEquals('simple', $filter->view);
83
    }
84
85
    public function testWhenActiveAndWhenInactiveAliases()
86
    {
87
        $filter = CrudFilter::name('my_filter')
88
                        ->whenActive(function () {
0 ignored issues
show
Bug introduced by
The method whenActive() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

88
                        ->/** @scrutinizer ignore-call */ whenActive(function () {
Loading history...
89
                            return true;
90
                        })
91
                        ->whenInactive(function () {
92
                            return true;
93
                        });
94
95
        $this->assertCount(1, $this->crudPanel->filters());
96
        $this->assertTrue(is_callable($filter->fallbackLogic));
97
        $this->assertTrue(is_callable($filter->logic));
98
    }
99
100
    public function testWhenNotActiveAlias()
101
    {
102
        $filter = CrudFilter::name('my_filter')->whenNotActive(function () {
0 ignored issues
show
Bug introduced by
The method whenNotActive() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

102
        $filter = CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ whenNotActive(function () {
Loading history...
103
            return true;
104
        });
105
        $this->assertCount(1, $this->crudPanel->filters());
106
        $this->assertTrue(is_callable($filter->fallbackLogic));
107
    }
108
109
    public function testIfNotActiveAlias()
110
    {
111
        $filter = CrudFilter::name('my_filter')->ifNotActive(function () {
0 ignored issues
show
Bug introduced by
The method ifNotActive() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

111
        $filter = CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ ifNotActive(function () {
Loading history...
112
            return true;
113
        });
114
        $this->assertCount(1, $this->crudPanel->filters());
115
        $this->assertTrue(is_callable($filter->fallbackLogic));
116
    }
117
118
    public function testElseAlias()
119
    {
120
        $filter = CrudFilter::name('my_filter')->else(function () {
0 ignored issues
show
Bug introduced by
The method else() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

120
        $filter = CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ else(function () {
Loading history...
121
            return true;
122
        });
123
        $this->assertCount(1, $this->crudPanel->filters());
124
        $this->assertTrue(is_callable($filter->fallbackLogic));
125
    }
126
127
    public function testItCanAddAFilterBeforeOtherFilter()
128
    {
129
        $this->crudPanel->addFilter(...$this->testFilter);
0 ignored issues
show
Bug introduced by
$this->testFilter is expanded, but the parameter $options of Backpack\CRUD\app\Librar...\CrudPanel::addFilter() does not expect variable arguments. ( Ignorable by Annotation )

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

129
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
130
        CrudFilter::name('test_filter_2')->label('just_an_hack_before_fix_gets_merged')->before('my_filter');
0 ignored issues
show
Bug introduced by
The method label() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

130
        CrudFilter::name('test_filter_2')->/** @scrutinizer ignore-call */ label('just_an_hack_before_fix_gets_merged')->before('my_filter');
Loading history...
131
        $filterCollection = $this->crudPanel->filters();
132
        $this->assertCount(2, $filterCollection);
133
        $firstFilter = $filterCollection[0];
134
        $this->assertEquals('test_filter_2', $firstFilter->name);
135
    }
136
137
    public function testItCanAddAFilterAfterOtherFilter()
138
    {
139
        $this->crudPanel->addFilter(...$this->testFilter);
0 ignored issues
show
Bug introduced by
$this->testFilter is expanded, but the parameter $options of Backpack\CRUD\app\Librar...\CrudPanel::addFilter() does not expect variable arguments. ( Ignorable by Annotation )

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

139
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
140
        $this->crudPanel->addFilter(...$this->testFilter_2);
141
        CrudFilter::name('test_filter_2')->label('just_an_hack_before_fix_gets_merged')->after('my_filter');
142
        $filterCollection = $this->crudPanel->filters();
143
        $this->assertCount(3, $filterCollection);
144
        $secondFilter = $filterCollection[1];
145
        $this->assertEquals('test_filter_2', $secondFilter->name);
146
    }
147
148
    public function testItCanMakeAFilterFirst()
149
    {
150
        $this->crudPanel->addFilter(...$this->testFilter);
0 ignored issues
show
Bug introduced by
$this->testFilter is expanded, but the parameter $options of Backpack\CRUD\app\Librar...\CrudPanel::addFilter() does not expect variable arguments. ( Ignorable by Annotation )

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

150
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
151
        CrudFilter::name('test_filter_2')->label('just_an_hack_before_fix_gets_merged')->makeFirst();
152
        $filterCollection = $this->crudPanel->filters();
153
        $this->assertCount(2, $filterCollection);
154
        $firstFilter = $filterCollection[0];
155
        $this->assertEquals('test_filter_2', $firstFilter->name);
156
    }
157
158
    public function testItCanMakeAFilterLast()
159
    {
160
        $this->crudPanel->addFilter(...$this->testFilter);
0 ignored issues
show
Bug introduced by
$this->testFilter is expanded, but the parameter $options of Backpack\CRUD\app\Librar...\CrudPanel::addFilter() does not expect variable arguments. ( Ignorable by Annotation )

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

160
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
161
        $this->crudPanel->addFilter(...$this->testFilter_2);
162
        CrudFilter::name('my_filter')->makeLast();
0 ignored issues
show
Bug introduced by
The method makeLast() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

162
        CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ makeLast();
Loading history...
163
        $filterCollection = $this->crudPanel->filters();
164
        $this->assertCount(2, $filterCollection);
165
        $this->assertEquals(['my_filter_2', 'my_filter'], $filterCollection->pluck('name')->toArray());
166
    }
167
168
    public function testItCanRemoveAFilter()
169
    {
170
        $this->crudPanel->addFilter(...$this->testFilter);
0 ignored issues
show
Bug introduced by
$this->testFilter is expanded, but the parameter $options of Backpack\CRUD\app\Librar...\CrudPanel::addFilter() does not expect variable arguments. ( Ignorable by Annotation )

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

170
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
171
        $this->crudPanel->addFilter(...$this->testFilter_2);
172
        CrudFilter::name('my_filter')->remove();
0 ignored issues
show
Bug introduced by
The method remove() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

172
        CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ remove();
Loading history...
173
        $filterCollection = $this->crudPanel->filters();
174
        $this->assertCount(1, $filterCollection);
175
        $this->assertEquals(['my_filter_2'], $filterCollection->pluck('name')->toArray());
176
    }
177
178
    public function testItCanRemoveAFilterAttribute()
179
    {
180
        $this->crudPanel->addFilter(...$this->testFilter);
0 ignored issues
show
Bug introduced by
$this->testFilter is expanded, but the parameter $options of Backpack\CRUD\app\Librar...\CrudPanel::addFilter() does not expect variable arguments. ( Ignorable by Annotation )

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

180
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
181
        $this->crudPanel->addFilter(...$this->testFilter_2);
182
        CrudFilter::name('my_filter')->forget('type');
0 ignored issues
show
Bug introduced by
The method forget() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

182
        CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ forget('type');
Loading history...
183
        $filterCollection = $this->crudPanel->filters();
184
        $this->assertCount(2, $filterCollection);
185
        $this->assertFalse($filterCollection[0]->type);
186
    }
187
188
    public function testItCanGetTheViewWithNamespace()
189
    {
190
        $this->crudPanel->addFilter(...$this->testFilter);
0 ignored issues
show
Bug introduced by
$this->testFilter is expanded, but the parameter $options of Backpack\CRUD\app\Librar...\CrudPanel::addFilter() does not expect variable arguments. ( Ignorable by Annotation )

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

190
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
191
        $namespacedFilterView = CrudFilter::name('my_filter')->getViewWithNamespace();
0 ignored issues
show
Bug introduced by
The method getViewWithNamespace() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

191
        $namespacedFilterView = CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ getViewWithNamespace();
Loading history...
192
        $filterCollection = $this->crudPanel->filters();
193
        $this->assertCount(1, $filterCollection);
194
        $this->assertEquals($filterCollection[0]->viewNamespace.'.'.$filterCollection[0]->view, $namespacedFilterView);
195
    }
196
197
    public function testItCanGetAllFilterViewNamespacesWithFallbacks()
198
    {
199
        Config::set('backpack.crud.view_namespaces', ['filters' => ['pro::filters']]);
200
        $this->crudPanel->addFilter(...$this->testFilter);
0 ignored issues
show
Bug introduced by
$this->testFilter is expanded, but the parameter $options of Backpack\CRUD\app\Librar...\CrudPanel::addFilter() does not expect variable arguments. ( Ignorable by Annotation )

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

200
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
201
        $filterNamespaceWithFallback = CrudFilter::name('my_filter')->getNamespacedViewWithFallbacks();
0 ignored issues
show
Bug introduced by
The method getNamespacedViewWithFallbacks() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

201
        $filterNamespaceWithFallback = CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ getNamespacedViewWithFallbacks();
Loading history...
202
        $this->assertEquals(['pro::filters.simple'], $filterNamespaceWithFallback);
203
    }
204
205
    public function testItCanCheckIfFilterWasApplied()
206
    {
207
        $this->crudPanel->addFilter(...$this->testFilter);
0 ignored issues
show
Bug introduced by
$this->testFilter is expanded, but the parameter $options of Backpack\CRUD\app\Librar...\CrudPanel::addFilter() does not expect variable arguments. ( Ignorable by Annotation )

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

207
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
208
        $filter = CrudFilter::name('my_filter');
209
        $this->assertTrue($filter->wasApplied());
0 ignored issues
show
Bug introduced by
The method wasApplied() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

209
        $this->assertTrue($filter->/** @scrutinizer ignore-call */ wasApplied());
Loading history...
210
        $this->assertFalse($filter->wasNotApplied());
0 ignored issues
show
Bug introduced by
The method wasNotApplied() does not exist on Backpack\CRUD\app\Library\CrudPanel\CrudPanel. 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

210
        $this->assertFalse($filter->/** @scrutinizer ignore-call */ wasNotApplied());
Loading history...
211
    }
212
}
213