Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

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

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.

Loading history...
68
     */
69
    public static function applyDataProvider()
70
    {
71
        return array(
72
            array('eq', '= :var_number', 1, true),
73
            array('neq', '<> :var_number', 2, true),
74
            array('lt', '< :var_number', 3, true),
75
            array('lte', '<= :var_number', 4, true),
76
            array('gt', '> :var_number', 5, true),
77
            array('gte', '>= :var_number', 6, true),
78
            array('isnull', 'IS NULL', 0, false),
79
            array('isnotnull', 'IS NOT NULL', 0, false),
80
        );
81
    }
82
83
    public function testGetTemplate()
84
    {
85
        $this->assertEquals('KunstmaanAdminListBundle:FilterType:numberFilter.html.twig', $this->object->getTemplate());
86
    }
87
}
88