Completed
Push — master ( 5b1ac4...a1db3b )
by David
17:06
created

tests/Unit/Filter/NodeNameFilterTest.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
/*
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\Unit\Filter;
13
14
use Sonata\DoctrinePHPCRAdminBundle\Filter\NodeNameFilter;
15
use Sonata\DoctrinePHPCRAdminBundle\Form\Type\Filter\ChoiceType;
16
17
class NodeNameFilterTest extends BaseTestCase
18
{
19
    public function setUp()
20
    {
21
        parent::setUp();
22
        $this->filter = new NodeNameFilter();
23
    }
24
25
    public function getChoiceTypeForEmptyTests()
26
    {
27
        return ChoiceType::TYPE_EQUAL;
28
    }
29
30
    public function testFilterNullData()
31
    {
32
        $res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', null);
33
        $this->assertNull($res);
34
        $this->assertFalse($this->filter->isActive());
35
    }
36
37
    public function testFilterEmptyArrayData()
38
    {
39
        $res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', []);
40
        $this->assertNull($res);
41
        $this->assertFalse($this->filter->isActive());
42
    }
43
44
    public function testFilterEmptyArrayDataSpecifiedType()
45
    {
46
        $res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', ['type' => ChoiceType::TYPE_EQUAL]);
47
        $this->assertNull($res);
48
        $this->assertFalse($this->filter->isActive());
49
    }
50
51
    public function testFilterEmptyArrayDataWithMeaninglessValue()
52
    {
53
        $this->filter->filter($this->proxyQuery, 'a', 'somefield', ['type' => ChoiceType::TYPE_EQUAL, 'value' => ' ']);
54
        $this->assertFalse($this->filter->isActive());
55
    }
56
57
    public function getFilters()
58
    {
59
        return [
60
            ['eqNodeName', ChoiceType::TYPE_EQUAL],
61
            ['likeNodeName', ChoiceType::TYPE_NOT_CONTAINS, '%somevalue%'],
62
            ['likeNodeName', ChoiceType::TYPE_CONTAINS, '%somevalue%'],
63
            ['likeNodeName', ChoiceType::TYPE_CONTAINS_WORDS, '%somevalue%'],
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->proxyQuery->expects($this->exactly(1))
73
            ->method('getQueryBuilder')
74
            ->will($this->returnValue($this->qb));
75
76
        $this->filter->filter(
77
            $this->proxyQuery,
78
            'a',
79
            'somefield',
80
            ['type' => $choiceType, 'value' => 'somevalue']
81
        );
82
83
        $localName = $this->qbTester->getNode('where.constraint.operand_dynamic');
84
        $literal = $this->qbTester->getNode('where.constraint.operand_static');
85
86
        $this->assertEquals('a', $localName->getAlias());
87
        $this->assertEquals($expectedValue, $literal->getValue());
88
89
        $this->assertTrue($this->filter->isActive());
90
    }
91
}
92