These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\DateType; |
||
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' => DateType::TYPE_EQUAL, 'value' => new \DateTime('now')], 'range'], |
||
0 ignored issues
–
show
|
|||
72 | [['type' => DateType::TYPE_GREATER_EQUAL, 'value' => new \DateTime('now')], 'gte'], |
||
0 ignored issues
–
show
The constant
Sonata\AdminBundle\Form\...ype::TYPE_GREATER_EQUAL has been deprecated with message: since sonata-project/admin-bundle 3.57, to be removed with 4.0: Use DateOperatorType::TYPE_GREATER_EQUAL instead
This class constant has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.
Loading history...
|
|||
73 | [['type' => DateType::TYPE_GREATER_THAN, 'value' => new \DateTime('now')], 'gt'], |
||
0 ignored issues
–
show
The constant
Sonata\AdminBundle\Form\...Type::TYPE_GREATER_THAN has been deprecated with message: since sonata-project/admin-bundle 3.57, to be removed with 4.0: Use DateOperatorType::TYPE_GREATER_THAN instead
This class constant has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.
Loading history...
|
|||
74 | [['type' => DateType::TYPE_LESS_EQUAL, 'value' => new \DateTime('now')], 'lte'], |
||
0 ignored issues
–
show
The constant
Sonata\AdminBundle\Form\...teType::TYPE_LESS_EQUAL has been deprecated with message: since sonata-project/admin-bundle 3.57, to be removed with 4.0: Use DateOperatorType::TYPE_LESS_EQUAL instead
This class constant has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.
Loading history...
|
|||
75 | [['type' => DateType::TYPE_LESS_THAN, 'value' => new \DateTime('now')], 'lt'], |
||
0 ignored issues
–
show
The constant
Sonata\AdminBundle\Form\...ateType::TYPE_LESS_THAN has been deprecated with message: since sonata-project/admin-bundle 3.57, to be removed with 4.0: Use DateOperatorType::TYPE_LESS_THAN instead
This class constant has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.
Loading history...
|
|||
76 | [['type' => DateType::TYPE_NULL], 'equals'], |
||
0 ignored issues
–
show
The constant
Sonata\AdminBundle\Form\...ter\DateType::TYPE_NULL has been deprecated with message: since sonata-project/admin-bundle 3.57, to be removed with 4.0: Use DateOperatorType::TYPE_NULL instead
This class constant has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.
Loading history...
|
|||
77 | [['type' => DateType::TYPE_NOT_NULL], 'notEqual'], |
||
0 ignored issues
–
show
The constant
Sonata\AdminBundle\Form\...DateType::TYPE_NOT_NULL has been deprecated with message: since sonata-project/admin-bundle 3.57, to be removed with 4.0: Use DateOperatorType::TYPE_NOT_NULL instead
This class constant has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.
Loading history...
|
|||
78 | [['value' => new \DateTime('now')], 'range'], |
||
79 | ]; |
||
80 | } |
||
81 | } |
||
82 |
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.