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
Push — we-need-more-tests ( c50978 )
by Pedro
41:43 queued 26:44
created

CrudPanelFiltersTest::testItCanMakeAFilterFirst()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 8
rs 10
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 testItCanCreateAFilterFluently()
48
    {
49
        CrudFilter::name('my_filter')
50
                    ->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

50
                    ->/** @scrutinizer ignore-call */ type('simple')
Loading history...
51
                    ->label('custom_label')
52
                    ->options(['test' => 'test'])
53
                    ->view('simple')
54
                    ->viewNamespace('crud::filters')
55
                    ->ifActive(function () {
56
                    return true;
57
                })
58
                    ->ifInactive(function () {
59
                    return true;
60
                });
61
62
        $this->assertCount(1, $this->crudPanel->filters());
63
        $filter = $this->crudPanel->filters()[0];
64
        $this->assertTrue(is_callable($filter->fallbackLogic));
65
        $this->assertTrue(is_callable($filter->logic));
66
        $this->assertEquals(['test' => 'test'], $filter->values);
67
        $this->assertEquals('custom_label', $filter->label);
68
        $this->assertEquals('simple', $filter->type);
69
        $this->assertEquals('simple', $filter->view);
70
    }
71
72
    public function testWhenActiveAndWhenInactiveAliases()
73
    {
74
        $filter = CrudFilter::name('my_filter')
75
                        ->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

75
                        ->/** @scrutinizer ignore-call */ whenActive(function () {
Loading history...
76
                            return true;
77
                        })
78
                        ->whenInactive(function () {
79
                            return true;
80
                        });
81
82
        $this->assertCount(1, $this->crudPanel->filters());
83
        $this->assertTrue(is_callable($filter->fallbackLogic));
84
        $this->assertTrue(is_callable($filter->logic));
85
    }
86
87
    public function testWhenNotActiveAlias()
88
    {
89
        $filter = CrudFilter::name('my_filter')->whenNotActive(function () {return true;});
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

89
        $filter = CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ whenNotActive(function () {return true;});
Loading history...
90
        $this->assertCount(1, $this->crudPanel->filters());
91
        $this->assertTrue(is_callable($filter->fallbackLogic));
92
    }
93
94
    public function testIfNotActiveAlias()
95
    {
96
        $filter = CrudFilter::name('my_filter')->ifNotActive(function () {return true;});
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

96
        $filter = CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ ifNotActive(function () {return true;});
Loading history...
97
        $this->assertCount(1, $this->crudPanel->filters());
98
        $this->assertTrue(is_callable($filter->fallbackLogic));
99
    }
100
101
    public function testElseAlias()
102
    {
103
        $filter = CrudFilter::name('my_filter')->else(function () {return true;});   
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

103
        $filter = CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ else(function () {return true;});   
Loading history...
104
        $this->assertCount(1, $this->crudPanel->filters());
105
        $this->assertTrue(is_callable($filter->fallbackLogic));
106
    }
107
108
    public function testItCanAddAFilterBeforeOtherFilter()
109
    {
110
        $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

110
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
111
        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

111
        CrudFilter::name('test_filter_2')->/** @scrutinizer ignore-call */ label('just_an_hack_before_fix_gets_merged')->before('my_filter');
Loading history...
112
        $filterCollection = $this->crudPanel->filters();
113
        $this->assertCount(2, $filterCollection);
114
        $firstFilter = $filterCollection[0];
115
        $this->assertEquals('test_filter_2', $firstFilter->name); 
116
    }
117
118
    public function testItCanAddAFilterAfterOtherFilter()
119
    {
120
        $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

120
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
121
        $this->crudPanel->addFilter(...$this->testFilter_2);
122
        CrudFilter::name('test_filter_2')->label('just_an_hack_before_fix_gets_merged')->after('my_filter');
123
        $filterCollection = $this->crudPanel->filters();
124
        $this->assertCount(3, $filterCollection);
125
        $secondFilter = $filterCollection[1];
126
        $this->assertEquals('test_filter_2', $secondFilter->name); 
127
    }
128
129
    public function testItCanMakeAFilterFirst()
130
    {
131
        $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

131
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
132
        CrudFilter::name('test_filter_2')->label('just_an_hack_before_fix_gets_merged')->makeFirst();
133
        $filterCollection = $this->crudPanel->filters();
134
        $this->assertCount(2, $filterCollection);
135
        $firstFilter = $filterCollection[0];
136
        $this->assertEquals('test_filter_2', $firstFilter->name); 
137
    }
138
139
    public function testItCanMakeAFilterLast()
140
    {
141
        $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

141
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
142
        $this->crudPanel->addFilter(...$this->testFilter_2);
143
        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

143
        CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ makeLast();
Loading history...
144
        $filterCollection = $this->crudPanel->filters();
145
        $this->assertCount(2, $filterCollection);
146
        $this->assertEquals(['my_filter_2', 'my_filter'], $filterCollection->pluck('name')->toArray()); 
147
    }
148
149
    public function testItCanRemoveAFilter()
150
    {
151
        $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

151
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
152
        $this->crudPanel->addFilter(...$this->testFilter_2);
153
        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

153
        CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ remove();
Loading history...
154
        $filterCollection = $this->crudPanel->filters();
155
        $this->assertCount(1, $filterCollection);
156
        $this->assertEquals(['my_filter_2'], $filterCollection->pluck('name')->toArray()); 
157
    }
158
159
    public function testItCanRemoveAFilterAttribute()
160
    {
161
        $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

161
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
162
        $this->crudPanel->addFilter(...$this->testFilter_2);
163
        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

163
        CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ forget('type');
Loading history...
164
        $filterCollection = $this->crudPanel->filters();
165
        $this->assertCount(2, $filterCollection);
166
        $this->assertFalse($filterCollection[0]->type); 
167
    }
168
169
    public function testItCanGetTheViewWithNamespace()
170
    {
171
        $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

171
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter); 
Loading history...
172
        $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

172
        $namespacedFilterView = CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ getViewWithNamespace();
Loading history...
173
        $filterCollection = $this->crudPanel->filters();
174
        $this->assertCount(1, $filterCollection);
175
        $this->assertEquals($filterCollection[0]->viewNamespace.'.'.$filterCollection[0]->view, $namespacedFilterView); 
176
    }
177
178
    public function testItCanGetAllFilterViewNamespacesWithFallbacks()
179
    {
180
        Config::set('backpack.crud.view_namespaces', ['filters' => ['pro::filters']]);
181
        $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

181
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
182
        $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

182
        $filterNamespaceWithFallback = CrudFilter::name('my_filter')->/** @scrutinizer ignore-call */ getNamespacedViewWithFallbacks();
Loading history...
183
        $this->assertEquals(['pro::filters.simple'], $filterNamespaceWithFallback);
184
    }
185
186
    public function testItCanCheckIfFilterWasApplied()
187
    {
188
        $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

188
        $this->crudPanel->addFilter(/** @scrutinizer ignore-type */ ...$this->testFilter);
Loading history...
189
        $filter = CrudFilter::name('my_filter');
190
        $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

190
        $this->assertTrue($filter->/** @scrutinizer ignore-call */ wasApplied());
Loading history...
191
        $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

191
        $this->assertFalse($filter->/** @scrutinizer ignore-call */ wasNotApplied());
Loading history...
192
    }
193
194
    public function testItCanCheckIfFilterIsActiveFromRequest()
195
    {
196
        $this->crudPanel->setModel(User::class);
197
        $request = request()->create('/admin/users', 'GET', ['my_custom_filter' => 'foo']);
198
        $request->setRouteResolver(function () use ($request) {
199
            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...
200
        });
201
        $this->crudPanel->setRequest($request);
202
203
        $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

203
        $isActive = CrudFilter::name('my_custom_filter')->/** @scrutinizer ignore-call */ isActive();
Loading history...
204
        $this->assertTrue($isActive);
205
    }
206
}
207