Completed
Push — master ( 4c1af7...741b75 )
by Ruud
21:53
created

EnumerationFilterTypeTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 25.76 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 17
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testBindRequest() 10 10 1
A testApply() 0 13 2
A applyDataProvider() 7 7 1
A testGetTemplate() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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()
0 ignored issues
show
Duplication introduced by
This method 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...
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
0 ignored issues
show
Documentation introduced by
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...
64
     */
65 View Code Duplication
    public static function applyDataProvider()
0 ignored issues
show
Duplication introduced by
This method 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...
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