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

tests/Unit/Filter/BooleanFilterTest.php (1 issue)

parameters are used.

Unused Code Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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);
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
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