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\DoctrineORMAdminBundle\Tests\Filter; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; |
18
|
|
|
use Sonata\DoctrineORMAdminBundle\Filter\EmptyFilter; |
19
|
|
|
use Sonata\Form\Type\BooleanType; |
20
|
|
|
|
21
|
|
|
final class EmptyFilterTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
public function testEmpty(): void |
24
|
|
|
{ |
25
|
|
|
$filter = new EmptyFilter(); |
26
|
|
|
$filter->initialize('field_name', [ |
27
|
|
|
'field_options' => ['class' => 'FooBar'], |
28
|
|
|
]); |
29
|
|
|
|
30
|
|
|
$builder = new ProxyQuery(new QueryBuilder()); |
|
|
|
|
31
|
|
|
|
32
|
|
|
$filter->filter($builder, 'alias', 'field', null); |
33
|
|
|
|
34
|
|
|
$this->assertSame([], $builder->query); |
|
|
|
|
35
|
|
|
$this->assertFalse($filter->isActive()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @dataProvider valueDataProvider |
40
|
|
|
*/ |
41
|
|
|
public function testValue(int $value, string $expectedQuery): void |
42
|
|
|
{ |
43
|
|
|
$filter = new EmptyFilter(); |
44
|
|
|
$filter->initialize('field_name', [ |
45
|
|
|
'field_options' => ['class' => 'FooBar'], |
46
|
|
|
]); |
47
|
|
|
|
48
|
|
|
$builder = new ProxyQuery(new QueryBuilder()); |
|
|
|
|
49
|
|
|
$this->assertSame([], $builder->query); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$filter->filter($builder, 'alias', 'field', ['value' => $value]); |
52
|
|
|
|
53
|
|
|
$this->assertSame([$expectedQuery], $builder->query); |
|
|
|
|
54
|
|
|
$this->assertTrue($filter->isActive()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testRenderSettings(): void |
58
|
|
|
{ |
59
|
|
|
$filter = new EmptyFilter(); |
60
|
|
|
$filter->initialize('field_name', [ |
61
|
|
|
'field_options' => ['class' => 'FooBar'], |
62
|
|
|
]); |
63
|
|
|
$options = $filter->getRenderSettings()[1]; |
64
|
|
|
|
65
|
|
|
$this->assertSame(BooleanType::class, $options['field_type']); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function valueDataProvider(): array |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
[BooleanType::TYPE_YES, 'alias.field IS NULL'], |
72
|
|
|
[BooleanType::TYPE_NO, 'alias.field IS NOT NULL'], |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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: