Completed
Push — master ( 4c26f1...ff6f36 )
by Maximilian
14s
created

tests/Filter/NumberFilterTest.php (1 issue)

Severity

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
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Filter;
13
14
use Sonata\AdminBundle\Form\Type\Filter\NumberType;
15
use Sonata\DoctrinePHPCRAdminBundle\Filter\NumberFilter;
16
17
class NumberFilterTest extends BaseTestCase
18
{
19
    public function setUp()
20
    {
21
        parent::setUp();
22
        $this->filter = new NumberFilter();
23
    }
24
25
    public function testFilterNullData()
26
    {
27
        $res = $this->filter->filter($this->proxyQuery, null, 'somefield', null);
28
        $this->assertNull($res);
29
        $this->assertFalse($this->filter->isActive());
30
    }
31
32
    public function testFilterEmptyArrayData()
33
    {
34
        $res = $this->filter->filter($this->proxyQuery, null, 'somefield', array());
35
        $this->assertNull($res);
36
        $this->assertFalse($this->filter->isActive());
37
    }
38
39
    public function testFilterEmptyArrayDataSpecifiedType()
40
    {
41
        $res = $this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => NumberType::TYPE_EQUAL));
42
        $this->assertNull($res);
43
        $this->assertFalse($this->filter->isActive());
44
    }
45
46
    public function testFilterEmptyArrayDataWithMeaninglessValue()
47
    {
48
        $this->proxyQuery->expects($this->never())
49
            ->method('getQueryBuilder');
50
51
        $this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => NumberType::TYPE_EQUAL, 'value' => ' '));
52
        $this->assertFalse($this->filter->isActive());
53
    }
54
55
    public function getFilters()
56
    {
57
        return array(
58
            array('gte', NumberType::TYPE_GREATER_EQUAL, 2),
59
            array('gt', NumberType::TYPE_GREATER_THAN, 3),
60
            array('lte', NumberType::TYPE_LESS_EQUAL, 4),
61
            array('lt', NumberType::TYPE_LESS_THAN, 5),
62
            array('eq', NumberType::TYPE_EQUAL, 6),
63
            array('eq', 'default', 7),
64
        );
65
    }
66
67
    /**
68
     * @dataProvider getFilters
69
     */
70
    public function testFilterSwitch($operatorMethod, $choiceType, $expectedValue = 'somevalue')
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...
71
    {
72
        $this->filter->filter(
73
            $this->proxyQuery,
74
            null,
75
            'somefield',
76
            array('type' => $choiceType, 'value' => $expectedValue)
77
        );
78
79
        $opDynamic = $this->qbTester->getNode('where.constraint.operand_dynamic');
80
        $opStatic = $this->qbTester->getNode('where.constraint.operand_static');
81
82
        $this->assertEquals('a', $opDynamic->getAlias());
83
        $this->assertEquals('somefield', $opDynamic->getField());
84
        $this->assertEquals($expectedValue, $opStatic->getValue());
85
86
        $this->assertTrue($this->filter->isActive());
87
    }
88
}
89