Failed Conditions
Push — master ( 656579...2742cd )
by Marco
11:55
created

Tests/DBAL/Driver/OCI8/OCI8StatementTest.php (1 issue)

Labels
Severity
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),
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);
1 ignored issue
show
The method execute() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

71
        $statement->/** @scrutinizer ignore-call */ 
72
                    execute($params);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
    }
73
74
    public static function executeDataProvider()
75
    {
76
        return array(
77
            // $hasZeroIndex = isset($params[0]); == true
78
            array(
79
                array(0 => 'test', 1 => null, 2 => 'value')
80
            ),
81
            // $hasZeroIndex = isset($params[0]); == false
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