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