These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminListBundle\Tests\AdminList\FilterType\ORM; |
||
4 | |||
5 | use Doctrine\ORM\QueryBuilder; |
||
6 | use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\DateTimeFilterType; |
||
7 | use ReflectionClass; |
||
8 | use Symfony\Component\HttpFoundation\Request; |
||
9 | |||
10 | View Code Duplication | class DateTimeFilterTypeTest extends BaseOrmFilterTest |
|
11 | { |
||
12 | /** |
||
13 | * @var DateTimeFilterType |
||
14 | */ |
||
15 | protected $object; |
||
16 | |||
17 | protected function setUp() |
||
18 | { |
||
19 | $this->object = new DateTimeFilterType('datetime', 'b'); |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @return array |
||
0 ignored issues
–
show
|
|||
24 | */ |
||
25 | public static function applyDataProvider() |
||
26 | { |
||
27 | return [ |
||
28 | ['before', '<= :var_datetime', ['date' => '14/04/2014', 'time' => '09:00'], '2014-04-14 09:00'], |
||
29 | ['after', '> :var_datetime', ['date' => '14/04/2014', 'time' => '10:00'], '2014-04-14 10:00'], |
||
30 | ]; |
||
31 | } |
||
32 | |||
33 | public function testBindRequest() |
||
34 | { |
||
35 | $request = new Request([ |
||
36 | 'filter_comparator_datetime' => 'before', |
||
37 | 'filter_value_datetime' => ['date' => '14/04/2014', 'time' => '09:00'], |
||
38 | ]); |
||
39 | |||
40 | $data = []; |
||
41 | $uniqueId = 'datetime'; |
||
42 | $this->object->bindRequest($request, $data, $uniqueId); |
||
43 | |||
44 | $this->assertEquals( |
||
45 | ['comparator' => 'before', 'value' => ['date' => '14/04/2014', 'time' => '09:00']], |
||
46 | $data |
||
47 | ); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param string $comparator The comparator |
||
52 | * @param string $whereClause The where clause |
||
53 | * @param mixed $value The value |
||
54 | * @param mixed $testValue The test value |
||
55 | * |
||
56 | * @dataProvider applyDataProvider |
||
57 | */ |
||
58 | public function testApply($comparator, $whereClause, $value, $testValue) |
||
59 | { |
||
60 | $qb = $this->getQueryBuilder(); |
||
61 | $qb->select('b') |
||
62 | ->from('Entity', 'b'); |
||
63 | $this->object->setQueryBuilder($qb); |
||
64 | $this->object->apply(['comparator' => $comparator, 'value' => $value], 'datetime'); |
||
65 | |||
66 | $this->assertEquals("SELECT b FROM Entity b WHERE b.datetime $whereClause", $qb->getDQL()); |
||
67 | $this->assertEquals($testValue, $qb->getParameter('var_datetime')->getValue()); |
||
68 | } |
||
69 | |||
70 | public function testGetTemplate() |
||
71 | { |
||
72 | $this->assertEquals( |
||
73 | '@KunstmaanAdminList/FilterType/dateTimeFilter.html.twig', |
||
74 | $this->object->getTemplate() |
||
75 | ); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @throws \ReflectionException |
||
80 | */ |
||
81 | public function testApplyReturnsNull() |
||
82 | { |
||
83 | $queryBuilder = $this->createMock(QueryBuilder::class); |
||
84 | $queryBuilder->expects($this->never())->method('setParameter'); |
||
85 | $mirror = new ReflectionClass(DateTimeFilterType::class); |
||
86 | $property = $mirror->getProperty('queryBuilder'); |
||
87 | $property->setAccessible(true); |
||
88 | $property->setValue($this->object, $queryBuilder); |
||
89 | |||
90 | $badData = [ |
||
91 | 'value' => [ |
||
92 | 'date' => 'oopsNotADate', |
||
93 | 'time' => 'oopsNotATime', |
||
94 | ], |
||
95 | 'comparator' => 'true', |
||
96 | ]; |
||
97 | $this->object->apply($badData, uniqid()); |
||
98 | } |
||
99 | } |
||
100 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.