Completed
Push — master ( ba8ed9...770316 )
by Jeroen
06:11
created

AdminList/FilterType/DBAL/StringFilterTypeTest.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\StringFilterType;
6
use Symfony\Component\HttpFoundation\Request;
7
8
/**
9
 * Generated by PHPUnit_SkeletonGenerator on 2012-09-26 at 13:21:33.
10
 */
11 View Code Duplication
class StringFilterTypeTest extends BaseDbalFilterTest
0 ignored issues
show
This class 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...
12
{
13
    /**
14
     * @var \UnitTester
15
     */
16
    protected $tester;
17
18
    /**
19
     * @var StringFilterType
20
     */
21
    protected $object;
22
23
    protected function setUp()
24
    {
25
        $this->object = new StringFilterType('string', 'e');
26
    }
27
28
    public function testBindRequest()
29
    {
30
        $request = new Request(array('filter_comparator_string' => 'equals', 'filter_value_string' => 'TheStringValue'));
31
32
        $data = array();
33
        $uniqueId = 'string';
34
        $this->object->bindRequest($request, $data, $uniqueId);
35
36
        $this->assertEquals(array('comparator' => 'equals', 'value' => 'TheStringValue'), $data);
37
    }
38
39
    /**
40
     * @param string $comparator  The comparator
41
     * @param string $whereClause The where clause
42
     * @param mixed  $value       The value
43
     * @param mixed  $testValue   The test value
44
     *
45
     * @dataProvider applyDataProvider
46
     */
47
    public function testApply($comparator, $whereClause, $value, $testValue)
48
    {
49
        $qb = $this->getQueryBuilder();
50
        $qb->select('*')
51
            ->from('entity', 'e');
52
        $this->object->setQueryBuilder($qb);
53
        $this->object->apply(array('comparator' => $comparator, 'value' => $value), 'string');
54
55
        $this->assertEquals("SELECT * FROM entity e WHERE e.string $whereClause", $qb->getSQL());
56
        $this->assertEquals($testValue, $qb->getParameter('var_string'));
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public static function applyDataProvider()
63
    {
64
        return array(
65
            array('equals', '= :var_string', 'AStringValue1', 'AStringValue1'),
66
            array('notequals', '<> :var_string', 'AStringValue2', 'AStringValue2'),
67
            array('contains', 'LIKE :var_string', 'AStringValue3', '%AStringValue3%'),
68
            array('doesnotcontain', 'NOT LIKE :var_string', 'AStringValue4', '%AStringValue4%'),
69
            array('startswith', 'LIKE :var_string', 'AStringValue5', 'AStringValue5%'),
70
            array('endswith', 'LIKE :var_string', 'AStringValue6', '%AStringValue6'),
71
        );
72
    }
73
74
    public function testGetTemplate()
75
    {
76
        $this->assertEquals('KunstmaanAdminListBundle:FilterType:stringFilter.html.twig', $this->object->getTemplate());
77
    }
78
}
79