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

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

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\AdminBundle\Form\Type\Filter\NumberType;
17
use Sonata\DoctrinePHPCRAdminBundle\Filter\NumberFilter;
18
19
class NumberFilterTest extends BaseTestCase
20
{
21
    public function setUp(): void
22
    {
23
        parent::setUp();
24
        $this->filter = new NumberFilter();
25
    }
26
27
    public function testFilterNullData(): void
28
    {
29
        $res = $this->filter->filter($this->proxyQuery, null, 'somefield', null);
30
        $this->assertNull($res);
31
        $this->assertFalse($this->filter->isActive());
32
    }
33
34
    public function testFilterEmptyArrayData(): void
35
    {
36
        $res = $this->filter->filter($this->proxyQuery, null, 'somefield', []);
37
        $this->assertNull($res);
38
        $this->assertFalse($this->filter->isActive());
39
    }
40
41
    public function testFilterEmptyArrayDataSpecifiedType(): void
42
    {
43
        $res = $this->filter->filter($this->proxyQuery, null, 'somefield', ['type' => NumberType::TYPE_EQUAL]);
44
        $this->assertNull($res);
45
        $this->assertFalse($this->filter->isActive());
46
    }
47
48
    public function testFilterEmptyArrayDataWithMeaninglessValue(): void
49
    {
50
        $this->proxyQuery->expects($this->never())
51
            ->method('getQueryBuilder');
52
53
        $this->filter->filter($this->proxyQuery, null, 'somefield', ['type' => NumberType::TYPE_EQUAL, 'value' => ' ']);
54
        $this->assertFalse($this->filter->isActive());
55
    }
56
57
    public function getFilters()
58
    {
59
        return [
60
            ['gte', NumberType::TYPE_GREATER_EQUAL, 2],
61
            ['gt', NumberType::TYPE_GREATER_THAN, 3],
62
            ['lte', NumberType::TYPE_LESS_EQUAL, 4],
63
            ['lt', NumberType::TYPE_LESS_THAN, 5],
64
            ['eq', NumberType::TYPE_EQUAL, 6],
65
            ['eq', 'default', 7],
66
        ];
67
    }
68
69
    /**
70
     * @dataProvider getFilters
71
     */
72
    public function testFilterSwitch($operatorMethod, $choiceType, $expectedValue = 'somevalue'): 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...
73
    {
74
        $this->filter->filter(
75
            $this->proxyQuery,
76
            null,
77
            'somefield',
78
            ['type' => $choiceType, 'value' => $expectedValue]
79
        );
80
81
        $opDynamic = $this->qbTester->getNode('where.constraint.operand_dynamic');
82
        $opStatic = $this->qbTester->getNode('where.constraint.operand_static');
83
84
        $this->assertSame('a', $opDynamic->getAlias());
85
        $this->assertSame('somefield', $opDynamic->getField());
86
        $this->assertSame($expectedValue, $opStatic->getValue());
87
88
        $this->assertTrue($this->filter->isActive());
89
    }
90
}
91