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\DateFilter; |
19
|
|
|
use Symfony\Component\Form\Extension\Core\Type\DateType; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Ennio Wolsink <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class DateFilterTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
public function testEmpty(): void |
27
|
|
|
{ |
28
|
|
|
$filter = new DateFilter(); |
29
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
30
|
|
|
|
31
|
|
|
$builder = new ProxyQuery(new QueryBuilder()); |
|
|
|
|
32
|
|
|
|
33
|
|
|
$filter->filter($builder, 'alias', 'field', null); |
|
|
|
|
34
|
|
|
$filter->filter($builder, 'alias', 'field', ''); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$this->assertSame([], $builder->query); |
|
|
|
|
37
|
|
|
$this->assertFalse($filter->isActive()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testGetType(): void |
41
|
|
|
{ |
42
|
|
|
$this->assertSame(DateType::class, (new DateFilter())->getFieldType()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testFilterRecordsWholeDay(): void |
46
|
|
|
{ |
47
|
|
|
$filter = new DateFilter(); |
48
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
49
|
|
|
|
50
|
|
|
$builder = new ProxyQuery(new QueryBuilder()); |
|
|
|
|
51
|
|
|
$filter->filter($builder, 'alias', 'field', ['value' => new \DateTime()]); |
52
|
|
|
|
53
|
|
|
$this->assertCount(2, $builder->parameters); |
|
|
|
|
54
|
|
|
$this->assertCount(2, $builder->query); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
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: