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\DoctrineMongoDBAdminBundle\Tests\Filter; |
15
|
|
|
|
16
|
|
|
use Sonata\AdminBundle\Form\Type\Filter\NumberType; |
17
|
|
|
use Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery; |
18
|
|
|
use Sonata\DoctrineMongoDBAdminBundle\Filter\NumberFilter; |
19
|
|
|
|
20
|
|
|
class NumberFilterTest extends FilterWithQueryBuilderTest |
21
|
|
|
{ |
22
|
|
|
public function testFilterEmpty(): void |
23
|
|
|
{ |
24
|
|
|
$filter = new NumberFilter(); |
25
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
26
|
|
|
|
27
|
|
|
$builder = new ProxyQuery($this->getQueryBuilder()); |
|
|
|
|
28
|
|
|
|
29
|
|
|
$filter->filter($builder, 'alias', 'field', null); |
30
|
|
|
$filter->filter($builder, 'alias', 'field', 'asds'); |
31
|
|
|
|
32
|
|
|
$this->assertFalse($filter->isActive()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testFilterInvalidOperator(): void |
36
|
|
|
{ |
37
|
|
|
$filter = new NumberFilter(); |
38
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
39
|
|
|
|
40
|
|
|
$builder = new ProxyQuery($this->getQueryBuilder()); |
|
|
|
|
41
|
|
|
|
42
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => 'foo']); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$this->assertFalse($filter->isActive()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testFilter(): void |
48
|
|
|
{ |
49
|
|
|
$filter = new NumberFilter(); |
50
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
51
|
|
|
|
52
|
|
|
$builder = new ProxyQuery($this->getQueryBuilder()); |
|
|
|
|
53
|
|
|
|
54
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => NumberType::TYPE_EQUAL, 'value' => 42]); |
|
|
|
|
55
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => NumberType::TYPE_GREATER_EQUAL, 'value' => 42]); |
|
|
|
|
56
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => NumberType::TYPE_GREATER_THAN, 'value' => 42]); |
|
|
|
|
57
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => NumberType::TYPE_LESS_EQUAL, 'value' => 42]); |
|
|
|
|
58
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => NumberType::TYPE_LESS_THAN, 'value' => 42]); |
|
|
|
|
59
|
|
|
$filter->filter($builder, 'alias', 'field', ['value' => 42]); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$this->assertTrue($filter->isActive()); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
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: