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 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 StringFilterTypeTest extends Unit |
|
0 ignored issues
–
show
|
|||
13 | { |
||
14 | /** |
||
15 | * @var \UnitTester |
||
16 | */ |
||
17 | protected $tester; |
||
18 | |||
19 | /** |
||
20 | * @var StringFilterType |
||
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 StringFilterType('string', 'e'); |
||
31 | } |
||
32 | |||
33 | public function testBindRequest() |
||
34 | { |
||
35 | $request = new Request(array('filter_comparator_string' => 'equals', 'filter_value_string' => 'TheStringValue')); |
||
36 | |||
37 | $data = array(); |
||
38 | $uniqueId = 'string'; |
||
39 | $this->object->bindRequest($request, $data, $uniqueId); |
||
40 | |||
41 | $this->assertEquals(array('comparator' => 'equals', 'value' => 'TheStringValue'), $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), 'string'); |
||
59 | |||
60 | $this->assertEquals("SELECT * FROM entity e WHERE e.string $whereClause", $qb->getSQL()); |
||
61 | $this->assertEquals($testValue, $qb->getParameter('var_string')); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @return array |
||
66 | */ |
||
67 | public static function applyDataProvider() |
||
68 | { |
||
69 | return array( |
||
70 | array('equals', '= :var_string', 'AStringValue1', 'AStringValue1'), |
||
71 | array('notequals', '<> :var_string', 'AStringValue2', 'AStringValue2'), |
||
72 | array('contains', 'LIKE :var_string', 'AStringValue3', '%AStringValue3%'), |
||
73 | array('doesnotcontain', 'NOT LIKE :var_string', 'AStringValue4', '%AStringValue4%'), |
||
74 | array('startswith', 'LIKE :var_string', 'AStringValue5', 'AStringValue5%'), |
||
75 | array('endswith', 'LIKE :var_string', 'AStringValue6', '%AStringValue6'), |
||
76 | ); |
||
77 | } |
||
78 | |||
79 | public function testGetTemplate() |
||
80 | { |
||
81 | $this->assertEquals('KunstmaanAdminListBundle:FilterType:stringFilter.html.twig', $this->object->getTemplate()); |
||
82 | } |
||
83 | } |
||
84 |
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.