Completed
Push — master ( c7757e...39cb21 )
by Luís
16s
created

Tests/DBAL/Driver/OCI8/OCI8StatementTest.php (3 issues)

1
<?php
2
3
namespace Doctrine\Tests\DBAL;
4
5
use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
6
use Doctrine\DBAL\Driver\OCI8\OCI8Statement;
7
use Doctrine\Tests\DbalTestCase;
8
9
class OCI8StatementTest extends DbalTestCase
10
{
11
    protected function setUp()
12
    {
13
        if (!extension_loaded('oci8')) {
14
            $this->markTestSkipped('oci8 is not installed.');
15
        }
16
17
        parent::setUp();
18
    }
19
20
    /**
21
     * This scenario shows that when the first parameter is not null
22
     * it properly sets $hasZeroIndex to 1 and calls bindValue starting at 1.
23
     *
24
     * This also verifies that the statement will check with the connection to
25
     * see what the current execution mode is.
26
     *
27
     * The expected exception is due to oci_execute failing due to no valid connection.
28
     *
29
     * @dataProvider executeDataProvider
30
     * @expectedException \Doctrine\DBAL\Driver\OCI8\OCI8Exception
31
     */
32
    public function testExecute(array $params)
33
    {
34
        $statement = $this->getMockBuilder('\Doctrine\DBAL\Driver\OCI8\OCI8Statement')
35
            ->setMethods(array('bindValue', 'errorInfo'))
36
            ->disableOriginalConstructor()
37
            ->getMock();
38
39
        $statement->expects($this->at(0))
40
            ->method('bindValue')
41
            ->with(
42
                $this->equalTo(1),
0 ignored issues
show
$this->equalTo(1) of type PHPUnit\Framework\Constraint\IsEqual is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
                /** @scrutinizer ignore-type */ $this->equalTo(1),
Loading history...
43
                $this->equalTo($params[0])
44
            );
45
        $statement->expects($this->at(1))
46
            ->method('bindValue')
47
            ->with(
48
                $this->equalTo(2),
49
                $this->equalTo($params[1])
50
            );
51
        $statement->expects($this->at(2))
52
            ->method('bindValue')
53
            ->with(
54
                $this->equalTo(3),
55
                $this->equalTo($params[2])
56
          );
57
58
        // can't pass to constructor since we don't have a real database handle,
59
        // but execute must check the connection for the executeMode
60
        $conn = $this->getMockBuilder('\Doctrine\DBAL\Driver\OCI8\OCI8Connection')
61
            ->setMethods(array('getExecuteMode'))
62
            ->disableOriginalConstructor()
63
            ->getMock();
64
        $conn->expects($this->once())
65
            ->method('getExecuteMode');
66
67
        $reflProperty = new \ReflectionProperty($statement, '_conn');
68
        $reflProperty->setAccessible(true);
69
        $reflProperty->setValue($statement, $conn);
70
71
        $statement->execute($params);
72
    }
73
74
    public static function executeDataProvider()
75
    {
76
        return array(
77
            // $hasZeroIndex = isset($params[0]); == true
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
78
            array(
79
                array(0 => 'test', 1 => null, 2 => 'value')
80
            ),
81
            // $hasZeroIndex = isset($params[0]); == false
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
82
            array(
83
                array(0 => null, 1 => 'test', 2 => 'value')
84
            )
85
        );
86
    }
87
88
    /**
89
     * @dataProvider nonTerminatedLiteralProvider
90
     */
91
    public function testConvertNonTerminatedLiteral($sql, $message)
92
    {
93
        $this->expectException(OCI8Exception::class);
94
        $this->expectExceptionMessageRegExp($message);
95
        OCI8Statement::convertPositionalToNamedPlaceholders($sql);
96
    }
97
98
    public static function nonTerminatedLiteralProvider()
99
    {
100
        return array(
101
            'no-matching-quote' => array(
102
                "SELECT 'literal FROM DUAL",
103
                '/offset 7/',
104
            ),
105
            'no-matching-double-quote' => array(
106
                'SELECT 1 "COL1 FROM DUAL',
107
                '/offset 9/',
108
            ),
109
            'incorrect-escaping-syntax' => array(
110
                "SELECT 'quoted \\'string' FROM DUAL",
111
                '/offset 23/',
112
            ),
113
        );
114
    }
115
}
116