StringFilterTypeTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 68
loc 68
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 4 4 1
A testBindRequest() 10 10 1
A testApply() 11 11 1
A applyDataProvider() 11 11 1
A testGetTemplate() 4 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\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
Duplication introduced by
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(): void
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
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string[][].

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...
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('@KunstmaanAdminList/FilterType/stringFilter.html.twig', $this->object->getTemplate());
77
    }
78
}
79