OCI8StatementTest.php 2.52 KB
Newer Older
1 2 3 4 5
<?php

namespace Doctrine\Tests\DBAL;

require_once __DIR__ . '/../../../TestInit.php';
6

7 8
class OCI8StatementTest extends \Doctrine\Tests\DbalTestCase
{
9 10 11 12 13
    public function setUp()
    {
        if (!extension_loaded('oci8')) {
            $this->markTestSkipped('oci8 is not installed.');
        }
14

15 16
        parent::setUp();
    }
17 18 19 20

    /**
     * This scenario shows that when the first parameter is not null
     * it properly sets $hasZeroIndex to 1 and calls bindValue starting at 1.
21
     *
22 23 24
     * This also verifies that the statement will check with the connection to
     * see what the current execution mode is.
     *
25 26 27 28 29 30 31
     * The expected exception is due to oci_execute failing due to no valid connection.
     *
     * @dataProvider executeDataProvider
     * @expectedException \Doctrine\DBAL\Driver\OCI8\OCI8Exception
     */
    public function testExecute(array $params)
    {
32 33 34
        $statement = $this->getMock('\Doctrine\DBAL\Driver\OCI8\OCI8Statement',
            array('bindValue', 'errorInfo'),
            array(), '', false);
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

        $statement->expects($this->at(0))
            ->method('bindValue')
            ->with(
                $this->equalTo(1),
                $this->equalTo($params[0])
            );
        $statement->expects($this->at(1))
            ->method('bindValue')
            ->with(
                $this->equalTo(2),
                $this->equalTo($params[1])
            );
        $statement->expects($this->at(2))
            ->method('bindValue')
            ->with(
                $this->equalTo(3),
                $this->equalTo($params[2])
          );

55 56 57 58 59 60 61 62 63 64
        // can't pass to constructor since we don't have a real database handle,
        // but execute must check the connection for the executeMode
        $conn = $this->getMock('\Doctrine\DBAL\Driver\OCI8\OCI8Connection', array('getExecuteMode'), array(), '', false);
        $conn->expects($this->once())
            ->method('getExecuteMode');

        $reflProperty = new \ReflectionProperty($statement, '_conn');
        $reflProperty->setAccessible(true);
        $reflProperty->setValue($statement, $conn);

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
        $statement->execute($params);
    }

    public static function executeDataProvider()
    {
        return array(
            // $hasZeroIndex = isset($params[0]); == true
            array(
                array(0 => 'test', 1 => null, 2 => 'value')
            ),
            // $hasZeroIndex = isset($params[0]); == false
            array(
                array(0 => null, 1 => 'test', 2 => 'value')
            )
        );
    }

}