Completed
Push — master ( 6d6774...64f3ed )
by Jeroen
11:23 queued 05:13
created

AdminList/FilterType/ORM/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\ORM;
4
5
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\NumberFilterType;
6
use Kunstmaan\AdminListBundle\Tests\unit\AdminList\FilterType\ORM\BaseOrmFilterTest;
7
use Symfony\Component\HttpFoundation\Request;
8
9
/**
10
 * Generated by PHPUnit_SkeletonGenerator on 2012-09-26 at 13:21:34.
11
 */
12 View Code Duplication
class NumberFilterTypeTest extends BaseOrmFilterTest
13
{
14
    /**
15
     * @var NumberFilterType
16
     */
17
    protected $object;
18
19
    protected function setUp()
20
    {
21
        $this->object = new NumberFilterType('number', 'b');
22
    }
23
24
    public function testBindRequest()
25
    {
26
        $request = new Request(array('filter_comparator_number' => 'eq', 'filter_value_number' => 10));
27
28
        $data = array();
29
        $uniqueId = 'number';
30
        $this->object->bindRequest($request, $data, $uniqueId);
31
32
        $this->assertEquals(array('comparator' => 'eq', 'value' => 10), $data);
33
    }
34
35
    /**
36
     * @param string $comparator  The comparator
37
     * @param string $whereClause The where clause
38
     * @param mixed  $value       The value
39
     * @param mixed  $testValue   The test value
40
     *
41
     * @dataProvider applyDataProvider
42
     */
43
    public function testApply($comparator, $whereClause, $value, $testValue)
44
    {
45
        $qb = $this->getQueryBuilder();
46
        $qb->select('b')
47
            ->from('Entity', 'b');
48
        $this->object->setQueryBuilder($qb);
49
        $this->object->apply(array('comparator' => $comparator, 'value' => $value), 'number');
50
51
        $this->assertEquals("SELECT b FROM Entity b WHERE b.number $whereClause", $qb->getDQL());
52
        if ($testValue) {
53
            $this->assertEquals($value, $qb->getParameter('var_number')->getValue());
54
        }
55
    }
56
57
    /**
58
     * @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...
59
     */
60
    public static function applyDataProvider()
61
    {
62
        return array(
63
            array('eq', '= :var_number', 1, true),
64
            array('neq', '<> :var_number', 2, true),
65
            array('lt', '< :var_number', 3, true),
66
            array('lte', '<= :var_number', 4, true),
67
            array('gt', '> :var_number', 5, true),
68
            array('gte', '>= :var_number', 6, true),
69
            array('isnull', 'IS NULL', 0, false),
70
            array('isnotnull', 'IS NOT NULL', 0, false),
71
        );
72
    }
73
74
    public function testGetTemplate()
75
    {
76
        $this->assertEquals('@KunstmaanAdminList/FilterType/numberFilter.html.twig', $this->object->getTemplate());
77
    }
78
}
79