Completed
Push — master ( 99165b...3b1bd1 )
by Mike
02:14
created

DummyClass   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 14
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 4 1
1
<?php
2
/*
3
 * This file is part of the Doctrine Bundle
4
 *
5
 * The code was originally distributed inside the Symfony framework.
6
 *
7
 * (c) Fabien Potencier <[email protected]>
8
 * (c) Doctrine Project, Benjamin Eberlei <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
*/
13
14
namespace Doctrine\Bundle\DoctrineBundle\Tests\Twig;
15
16
use Doctrine\Bundle\DoctrineBundle\Twig\DoctrineExtension;
17
18
class DoctrineExtensionTest extends \PHPUnit_Framework_TestCase
19
{
20 View Code Duplication
    public function testReplaceQueryParametersWithPostgresCasting()
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...
21
    {
22
        $extension = new DoctrineExtension();
23
        $query = 'a=? OR (1)::string OR b=?';
24
        $parameters = array(1, 2);
25
26
        $result = $extension->replaceQueryParameters($query, $parameters);
27
        $this->assertEquals('a=1 OR (1)::string OR b=2', $result);
28
    }
29
30 View Code Duplication
    public function testReplaceQueryParametersWithStartingIndexAtOne()
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...
31
    {
32
        $extension = new DoctrineExtension();
33
        $query = 'a=? OR b=?';
34
        $parameters = array(
35
            1 => 1,
36
            2 => 2
37
        );
38
39
        $result = $extension->replaceQueryParameters($query, $parameters);
40
        $this->assertEquals('a=1 OR b=2', $result);
41
    }
42
43 View Code Duplication
    public function testReplaceQueryParameters()
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...
44
    {
45
        $extension = new DoctrineExtension();
46
        $query = 'a=? OR b=?';
47
        $parameters = array(
48
            1,
49
            2
50
        );
51
52
        $result = $extension->replaceQueryParameters($query, $parameters);
53
        $this->assertEquals('a=1 OR b=2', $result);
54
    }
55
56
    public function testReplaceQueryParametersWithNamedIndex()
57
    {
58
        $extension = new DoctrineExtension();
59
        $query = 'a=:a OR b=:b';
60
        $parameters = array(
61
            'a' => 1,
62
            'b' => 2
63
        );
64
65
        $result = $extension->replaceQueryParameters($query, $parameters);
66
        $this->assertEquals('a=1 OR b=2', $result);
67
    }
68
69
    public function testEscapeBinaryParameter()
70
    {
71
        $binaryString = pack('H*', '9d40b8c1417f42d099af4782ec4b20b6');
72
        $this->assertEquals('0x9D40B8C1417F42D099AF4782EC4B20B6', DoctrineExtension::escapeFunction($binaryString));
73
    }
74
75
    public function testEscapeStringParameter()
76
    {
77
        $this->assertEquals("'test string'", DoctrineExtension::escapeFunction('test string'));
78
    }
79
80
    public function testEscapeArrayParameter()
81
    {
82
        $this->assertEquals("1, NULL, 'test', foo", DoctrineExtension::escapeFunction(array(1, null, 'test', new DummyClass('foo'))));
83
    }
84
85
    public function testEscapeObjectParameter()
86
    {
87
        $object = new DummyClass('bar');
88
        $this->assertEquals('bar', DoctrineExtension::escapeFunction($object));
89
    }
90
91
    public function testEscapeNullParameter()
92
    {
93
        $this->assertEquals('NULL', DoctrineExtension::escapeFunction(null));
94
    }
95
96
    public function testEscapeBooleanParameter()
97
    {
98
        $this->assertEquals('1', DoctrineExtension::escapeFunction(true));
99
    }
100
}
101
102
class DummyClass
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
103
{
104
    protected $str;
105
106
    public function __construct($str)
107
    {
108
        $this->str = $str;
109
    }
110
111
    public function __toString()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
112
    {
113
        return $this->str;
114
    }
115
}