Completed
Push — webtests ( edc590 )
by Maximilian
01:56
created

NodeNameFilterTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 75
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A getChoiceTypeForEmptyTests() 0 4 1
A testFilterNullData() 0 6 1
A testFilterEmptyArrayData() 0 6 1
A testFilterEmptyArrayDataSpecifiedType() 0 6 1
A testFilterEmptyArrayDataWithMeaninglessValue() 0 5 1
A getFilters() 0 9 1
A testFilterSwitch() 0 21 1
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', array());
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', array('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', array('type' => ChoiceType::TYPE_EQUAL, 'value' => ' '));
54
        $this->assertFalse($this->filter->isActive());
55
    }
56
57
    public function getFilters()
58
    {
59
        return array(
60
            array('eqNodeName', ChoiceType::TYPE_EQUAL),
61
            array('likeNodeName', ChoiceType::TYPE_NOT_CONTAINS, '%somevalue%'),
62
            array('likeNodeName', ChoiceType::TYPE_CONTAINS, '%somevalue%'),
63
            array('likeNodeName', ChoiceType::TYPE_CONTAINS_WORDS, '%somevalue%'),
64
        );
65
    }
66
67
    /**
68
     * @dataProvider getFilters
69
     */
70
    public function testFilterSwitch($operatorMethod, $choiceType, $expectedValue = 'somevalue')
71
    {
72
        $this->proxyQuery->expects($this->exactly(1))
0 ignored issues
show
Documentation Bug introduced by
The method expects does not exist on object<Sonata\DoctrinePH...le\Datagrid\ProxyQuery>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
73
            ->method('getQueryBuilder')
74
            ->will($this->returnValue($this->qb));
75
76
        $this->filter->filter(
77
            $this->proxyQuery,
78
            'a',
79
            'somefield',
80
            array('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