Completed
Push — master ( 6b2632...1706e7 )
by
unknown
07:57 queued 10s
created

BooleanFilterTest::getFilters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Unit\Filter;
15
16
use Sonata\CoreBundle\Form\Type\BooleanType;
17
use Sonata\DoctrinePHPCRAdminBundle\Filter\BooleanFilter;
18
19
class BooleanFilterTest extends BaseTestCase
20
{
21
    /**
22
     * @var BooleanFilter
23
     */
24
    private $filter;
25
26
    public function setUp(): void
27
    {
28
        parent::setUp();
29
        $this->filter = new BooleanFilter();
30
    }
31
32
    public function testFilterNullData(): void
33
    {
34
        $this->filter->filter($this->proxyQuery, null, 'somefield', null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
        $this->assertFalse($this->filter->isActive());
36
    }
37
38
    public function testFilterEmptyArrayData(): void
39
    {
40
        $this->filter->filter($this->proxyQuery, null, 'somefield', []);
41
        $this->assertFalse($this->filter->isActive());
42
    }
43
44
    public function testFilterEmptyArrayDataSpecifiedType(): void
45
    {
46
        $this->filter->filter($this->proxyQuery, null, 'somefield', ['type' => BooleanType::TYPE_YES]);
47
        $this->assertFalse($this->filter->isActive());
48
    }
49
50
    public function testFilterEmptyArrayDataWithMeaninglessValue(): void
51
    {
52
        $this->filter->filter($this->proxyQuery, null, 'somefield', ['type' => BooleanType::TYPE_YES, 'value' => 'someValue']);
53
        $this->assertFalse($this->filter->isActive());
54
    }
55
56
    public function getFilters()
57
    {
58
        return [
59
            ['eq', BooleanType::TYPE_YES, true],
60
            ['eq', BooleanType::TYPE_NO, false],
61
        ];
62
    }
63
64
    /**
65
     * @dataProvider getFilters
66
     */
67
    public function testFilterSwitch($operatorMethod, $value, $expectedValue): void
0 ignored issues
show
Unused Code introduced by
The parameter $operatorMethod is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
    {
69
        $this->filter->filter(
70
            $this->proxyQuery,
71
            null,
72
            'somefield',
73
            ['type' => '', 'value' => $value]
74
        );
75
76
        $opDynamic = $this->qbTester->getNode('where.constraint.operand_dynamic');
77
        $opStatic = $this->qbTester->getNode('where.constraint.operand_static');
78
79
        $this->assertSame('a', $opDynamic->getAlias());
80
        $this->assertSame('somefield', $opDynamic->getField());
81
        $this->assertSame($expectedValue, $opStatic->getValue());
82
83
        $this->assertTrue($this->filter->isActive());
84
    }
85
}
86