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\Operator\DateOperatorType; |
17
|
|
|
use Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery; |
18
|
|
|
use Sonata\DoctrineMongoDBAdminBundle\Filter\DateTimeFilter; |
19
|
|
|
use Symfony\Component\Form\Extension\Core\Type\DateTimeType; |
20
|
|
|
|
21
|
|
|
final class DateTimeFilterTest extends FilterWithQueryBuilderTest |
22
|
|
|
{ |
23
|
|
|
public function testEmpty(): void |
24
|
|
|
{ |
25
|
|
|
$filter = new DateTimeFilter(); |
26
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
27
|
|
|
|
28
|
|
|
$builder = new ProxyQuery($this->getQueryBuilder()); |
29
|
|
|
|
30
|
|
|
$builder->getQueryBuilder() |
|
|
|
|
31
|
|
|
->expects($this->never()) |
32
|
|
|
->method('field') |
33
|
|
|
; |
34
|
|
|
|
35
|
|
|
$filter->filter($builder, 'alias', 'field', null); |
|
|
|
|
36
|
|
|
$filter->filter($builder, 'alias', 'field', ''); |
|
|
|
|
37
|
|
|
$filter->filter($builder, 'alias', 'field', []); |
38
|
|
|
|
39
|
|
|
$this->assertFalse($filter->isActive()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testGetType(): void |
43
|
|
|
{ |
44
|
|
|
$this->assertSame(DateTimeType::class, (new DateTimeFilter())->getFieldType()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @dataProvider getExamples |
49
|
|
|
*/ |
50
|
|
|
public function testFilter(array $data, string $method): void |
51
|
|
|
{ |
52
|
|
|
$filter = new DateTimeFilter(); |
53
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
54
|
|
|
|
55
|
|
|
$builder = new ProxyQuery($this->getQueryBuilder()); |
56
|
|
|
|
57
|
|
|
$builder->getQueryBuilder() |
|
|
|
|
58
|
|
|
->expects($this->once()) |
59
|
|
|
->method($method) |
60
|
|
|
->with($data['value'] ?? null) |
61
|
|
|
; |
62
|
|
|
|
63
|
|
|
$filter->filter($builder, 'alias', 'field', $data); |
64
|
|
|
|
65
|
|
|
$this->assertTrue($filter->isActive()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getExamples(): array |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
[['type' => DateOperatorType::TYPE_EQUAL, 'value' => new \DateTime('now')], 'range'], |
72
|
|
|
[['type' => DateOperatorType::TYPE_GREATER_EQUAL, 'value' => new \DateTime('now')], 'gte'], |
73
|
|
|
[['type' => DateOperatorType::TYPE_GREATER_THAN, 'value' => new \DateTime('now')], 'gt'], |
74
|
|
|
[['type' => DateOperatorType::TYPE_LESS_EQUAL, 'value' => new \DateTime('now')], 'lte'], |
75
|
|
|
[['type' => DateOperatorType::TYPE_LESS_THAN, 'value' => new \DateTime('now')], 'lt'], |
76
|
|
|
[['type' => DateOperatorType::TYPE_NULL], 'equals'], |
77
|
|
|
[['type' => DateOperatorType::TYPE_NOT_NULL], 'notEqual'], |
78
|
|
|
[['value' => new \DateTime('now')], 'range'], |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.