Completed
Push — master ( a76a39...6e9755 )
by
unknown
14:19
created

BooleanFilterTest::testFilterNullData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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\CoreBundle\Form\Type\BooleanType;
15
use Sonata\DoctrinePHPCRAdminBundle\Filter\BooleanFilter;
16
17
class BooleanFilterTest extends BaseTestCase
18
{
19
    /**
20
     * @var BooleanFilter
21
     */
22
    private $filter;
23
24
    public function setUp()
25
    {
26
        parent::setUp();
27
        $this->filter = new BooleanFilter();
28
    }
29
30
    public function testFilterNullData()
31
    {
32
        $this->filter->filter($this->proxyQuery, null, 'somefield', null);
33
        $this->assertFalse($this->filter->isActive());
34
    }
35
36
    public function testFilterEmptyArrayData()
37
    {
38
        $this->filter->filter($this->proxyQuery, null, 'somefield', array());
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
        $this->assertFalse($this->filter->isActive());
40
    }
41
42
    public function testFilterEmptyArrayDataSpecifiedType()
43
    {
44
        $this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => BooleanType::TYPE_YES));
0 ignored issues
show
Documentation introduced by
array('type' => \Sonata\...\BooleanType::TYPE_YES) is of type array<string,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
        $this->assertFalse($this->filter->isActive());
46
    }
47
48
    public function testFilterEmptyArrayDataWithMeaninglessValue()
49
    {
50
        $this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => BooleanType::TYPE_YES, 'value' => 'someValue'));
0 ignored issues
show
Documentation introduced by
array('type' => \Sonata\...'value' => 'someValue') is of type array<string,string,{"value":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
51
        $this->assertFalse($this->filter->isActive());
52
    }
53
54
    public function getFilters()
55
    {
56
        return array(
57
            array('eq', BooleanType::TYPE_YES, 1),
58
            array('eq', BooleanType::TYPE_NO, 0),
59
        );
60
    }
61
62
    /**
63
     * @dataProvider getFilters
64
     */
65
    public function testFilterSwitch($operatorMethod, $value, $expectedValue)
0 ignored issues
show
Unused Code introduced by
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...
66
    {
67
        $this->filter->filter(
68
            $this->proxyQuery,
69
            null,
70
            'somefield',
71
            array('type' => '', 'value' => $value)
0 ignored issues
show
Documentation introduced by
array('type' => '', 'value' => $value) is of type array<string,?,{"type":"string","value":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
72
        );
73
74
        $opDynamic = $this->qbTester->getNode('where.constraint.operand_dynamic');
75
        $opStatic = $this->qbTester->getNode('where.constraint.operand_static');
76
77
        $this->assertEquals('a', $opDynamic->getAlias());
78
        $this->assertEquals('somefield', $opDynamic->getField());
79
        $this->assertEquals($expectedValue, $opStatic->getValue());
80
81
        $this->assertTrue($this->filter->isActive());
82
    }
83
}
84