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\CoreBundle\Form\Type\BooleanType; |
17
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Filter\BooleanFilter; |
18
|
|
|
|
19
|
|
|
class BooleanFilterTest extends BaseTestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var BooleanFilter |
23
|
|
|
*/ |
24
|
|
|
private $filter; |
25
|
|
|
|
26
|
|
|
public function setUp(): void |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
$this->filter = new BooleanFilter(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testFilterNullData(): void |
33
|
|
|
{ |
34
|
|
|
$this->filter->filter($this->proxyQuery, null, 'somefield', null); |
|
|
|
|
35
|
|
|
$this->assertFalse($this->filter->isActive()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testFilterEmptyArrayData(): void |
39
|
|
|
{ |
40
|
|
|
$this->filter->filter($this->proxyQuery, null, 'somefield', []); |
41
|
|
|
$this->assertFalse($this->filter->isActive()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testFilterEmptyArrayDataSpecifiedType(): void |
45
|
|
|
{ |
46
|
|
|
$this->filter->filter($this->proxyQuery, null, 'somefield', ['type' => BooleanType::TYPE_YES]); |
47
|
|
|
$this->assertFalse($this->filter->isActive()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testFilterEmptyArrayDataWithMeaninglessValue(): void |
51
|
|
|
{ |
52
|
|
|
$this->filter->filter($this->proxyQuery, null, 'somefield', ['type' => BooleanType::TYPE_YES, 'value' => 'someValue']); |
53
|
|
|
$this->assertFalse($this->filter->isActive()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getFilters() |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
['eq', BooleanType::TYPE_YES, true], |
60
|
|
|
['eq', BooleanType::TYPE_NO, false], |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @dataProvider getFilters |
66
|
|
|
*/ |
67
|
|
|
public function testFilterSwitch($operatorMethod, $value, $expectedValue): void |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$this->filter->filter( |
70
|
|
|
$this->proxyQuery, |
71
|
|
|
null, |
72
|
|
|
'somefield', |
73
|
|
|
['type' => '', 'value' => $value] |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$opDynamic = $this->qbTester->getNode('where.constraint.operand_dynamic'); |
77
|
|
|
$opStatic = $this->qbTester->getNode('where.constraint.operand_static'); |
78
|
|
|
|
79
|
|
|
$this->assertSame('a', $opDynamic->getAlias()); |
80
|
|
|
$this->assertSame('somefield', $opDynamic->getField()); |
81
|
|
|
$this->assertSame($expectedValue, $opStatic->getValue()); |
82
|
|
|
|
83
|
|
|
$this->assertTrue($this->filter->isActive()); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
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: