Completed
Push — master ( a7fff6...5ea170 )
by Jeroen
18:57 queued 10s
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 ReflectionClass;
8
use Symfony\Component\HttpFoundation\Request;
9
10
/**
11
 * Generated by PHPUnit_SkeletonGenerator on 2012-09-26 at 13:21:33.
12
 */
13
class DateFilterTypeTest extends BaseDbalFilterTest
14
{
15
    /**
16
     * @var DateFilterType
17
     */
18
    protected $object;
19
20
    protected function setUp()
21
    {
22
        $this->object = new DateFilterType('date', 'e');
23
    }
24
25
    public function testBindRequest()
26
    {
27
        $request = new Request(array('filter_comparator_date' => 'before', 'filter_value_date' => '01/01/2012'));
28
29
        $data = array();
30
        $uniqueId = 'date';
31
        $this->object->bindRequest($request, $data, $uniqueId);
32
33
        $this->assertEquals(array('comparator' => 'before', 'value' => '01/01/2012'), $data);
34
    }
35
36
    /**
37
     * @param string $comparator  The comparator
38
     * @param string $whereClause The where clause
39
     * @param mixed  $value       The value
40
     * @param mixed  $testValue   The test value
41
     *
42
     * @dataProvider applyDataProvider
43
     */
44
    public function testApply($comparator, $whereClause, $value, $testValue)
45
    {
46
        $qb = $this->getQueryBuilder();
47
        $qb->select('*')
48
            ->from('entity', 'e');
49
        $this->object->setQueryBuilder($qb);
50
        $this->object->apply(array('comparator' => $comparator, 'value' => $value), 'date');
51
52
        $this->assertEquals("SELECT * FROM entity e WHERE e.date $whereClause", $qb->getSQL());
53
        $this->assertEquals($testValue, $qb->getParameter('var_date'));
54
    }
55
56
    /**
57
     * @return array
58
     */
59 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...
60
    {
61
        return array(
62
            array('before', '<= :var_date', '20/12/2012', '2012-12-20'),
63
            array('after', '> :var_date', '21/12/2012', '2012-12-21'),
64
        );
65
    }
66
67
    public function testGetTemplate()
68
    {
69
        $this->assertEquals('KunstmaanAdminListBundle:FilterType:dateFilter.html.twig', $this->object->getTemplate());
70
    }
71
72
    /**
73
     * @throws \ReflectionException
74
     */
75 View Code Duplication
    public function testApplyReturnsNull()
76
    {
77
        $queryBuilder = $this->createMock(QueryBuilder::class);
78
        $queryBuilder->expects($this->never())->method('setParameter');
79
        $mirror = new ReflectionClass(DateFilterType::class);
80
        $property = $mirror->getProperty('queryBuilder');
81
        $property->setAccessible(true);
82
        $property->setValue($this->object, $queryBuilder);
83
        $badData = [
84
            'value' => 'oopsNotADate',
85
            'comparator' => 'true',
86
        ];
87
        $this->object->apply($badData, uniqid());
88
    }
89
}
90