Completed
Push — 5.2 ( 7ee7b8...3c6022 )
by Jeroen
53:51 queued 38:02
created

AdminList/FilterType/DBAL/DateFilterTypeTest.php (1 issue)

Upgrade to new PHP Analysis Engine

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\DBAL;
4
5
use Doctrine\DBAL\Query\QueryBuilder;
6
use Kunstmaan\AdminListBundle\AdminList\FilterType\DBAL\DateFilterType;
7
use Codeception\Test\Unit;
8
use ReflectionClass;
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * Generated by PHPUnit_SkeletonGenerator on 2012-09-26 at 13:21:33.
13
 */
14
class DateFilterTypeTest extends Unit
15
{
16
    /**
17
     * @var \UnitTester
18
     */
19
    protected $tester;
20
21
    /**
22
     * @var DateFilterType
23
     */
24
    protected $object;
25
26
    /**
27
     * Sets up the fixture, for example, opens a network connection.
28
     * This method is called before a test is executed.
29
     */
30
    protected function _before()
31
    {
32
        $this->object = new DateFilterType('date', 'e');
33
    }
34
35
    public function testBindRequest()
36
    {
37
        $request = new Request(array('filter_comparator_date' => 'before', 'filter_value_date' => '01/01/2012'));
38
39
        $data = array();
40
        $uniqueId = 'date';
41
        $this->object->bindRequest($request, $data, $uniqueId);
42
43
        $this->assertEquals(array('comparator' => 'before', 'value' => '01/01/2012'), $data);
44
    }
45
46
    /**
47
     * @param string $comparator  The comparator
48
     * @param string $whereClause The where clause
49
     * @param mixed  $value       The value
50
     * @param mixed  $testValue   The test value
51
     *
52
     * @dataProvider applyDataProvider
53
     */
54
    public function testApply($comparator, $whereClause, $value, $testValue)
55
    {
56
        $qb = $this->tester->getDBALQueryBuilder();
57
        $qb->select('*')
58
            ->from('entity', 'e');
59
        $this->object->setQueryBuilder($qb);
60
        $this->object->apply(array('comparator' => $comparator, 'value' => $value), 'date');
61
62
        $this->assertEquals("SELECT * FROM entity e WHERE e.date $whereClause", $qb->getSQL());
63
        $this->assertEquals($testValue, $qb->getParameter('var_date'));
64
    }
65
66
    /**
67
     * @return array
68
     */
69 View Code Duplication
    public static function applyDataProvider()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        return array(
72
            array('before', '<= :var_date', '20/12/2012', '2012-12-20'),
73
            array('after', '> :var_date', '21/12/2012', '2012-12-21'),
74
        );
75
    }
76
77
    public function testGetTemplate()
78
    {
79
        $this->assertEquals('KunstmaanAdminListBundle:FilterType:dateFilter.html.twig', $this->object->getTemplate());
80
    }
81
82
    /**
83
     * @throws \ReflectionException
84
     */
85 View Code Duplication
    public function testApplyReturnsNull()
86
    {
87
        $queryBuilder = $this->createMock(QueryBuilder::class);
88
        $queryBuilder->expects($this->never())->method('setParameter');
89
        $mirror = new ReflectionClass(DateFilterType::class);
90
        $property = $mirror->getProperty('queryBuilder');
91
        $property->setAccessible(true);
92
        $property->setValue($this->object, $queryBuilder);
93
        $badData = [
94
            'value' => 'oopsNotADate',
95
            'comparator' => 'true',
96
        ];
97
        $this->object->apply($badData, uniqid());
98
    }
99
}
100