Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContinuousPHP configuration for PDO Oracle driver #3339

Merged
merged 3 commits into from
Dec 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ reports/
dist/
download/
vendor/
*.phpunit.xml
/*.phpunit.xml
/phpunit.xml
/.phpcs-cache
/phpstan.neon
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ before_commands:
tools:
external_code_coverage:
timeout: 3600
runs: 27 # 23x Travis (jobs with COVERAGE=yes) + 3x AppVeyor (jobs with coverage=yes) + 1x ContinuousPHP
runs: 28 # 23x Travis (jobs with COVERAGE=yes) + 3x AppVeyor (jobs with coverage=yes) + 2x ContinuousPHP

filter:
excluded_paths:
Expand Down
6 changes: 5 additions & 1 deletion lib/Doctrine/DBAL/Driver/PDOConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ public function quote($input, $type = ParameterType::STRING)
*/
public function lastInsertId($name = null)
{
return parent::lastInsertId($name);
try {
return parent::lastInsertId($name);
} catch (\PDOException $exception) {
Majkl578 marked this conversation as resolved.
Show resolved Hide resolved
throw new PDOException($exception);
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/BlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Functional;

use Doctrine\DBAL\Driver\OCI8\Driver as OCI8Driver;
use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Schema\Table;
Expand All @@ -21,6 +22,12 @@ protected function setUp()
{
parent::setUp();

if ($this->connection->getDriver() instanceof PDOOracleDriver) {
// inserting BLOBs as streams on Oracle requires Oracle-specific SQL syntax which is currently not supported
// see http://php.net/manual/en/pdo.lobs.php#example-1035
$this->markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI');
}

$table = new Table('blob_table');
$table->addColumn('id', 'integer');
$table->addColumn('clobfield', 'text');
Expand Down
27 changes: 20 additions & 7 deletions tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use DateTime;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Mysqli\Driver as MySQLiDriver;
use Doctrine\DBAL\Driver\OCI8\Driver as Oci8Driver;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver;
use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
Expand All @@ -14,6 +17,7 @@
use Doctrine\DBAL\Statement;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalFunctionalTestCase;
use PDO;
use const CASE_LOWER;
use const PHP_EOL;
use function array_change_key_case;
Expand Down Expand Up @@ -749,7 +753,7 @@ public function testFetchAllStyleObject()
*/
public function testFetchAllSupportFetchClass()
{
$this->skipOci8AndMysqli();
$this->beforeFetchClassTest();
$this->setupFixture();

$sql = 'SELECT test_int, test_string, test_datetime FROM fetch_table';
Expand Down Expand Up @@ -791,7 +795,7 @@ public function testFetchAllStyleColumn()
*/
public function testSetFetchModeClassFetchAll()
{
$this->skipOci8AndMysqli();
$this->beforeFetchClassTest();
$this->setupFixture();

$sql = 'SELECT * FROM fetch_table';
Expand All @@ -813,7 +817,7 @@ public function testSetFetchModeClassFetchAll()
*/
public function testSetFetchModeClassFetch()
{
$this->skipOci8AndMysqli();
$this->beforeFetchClassTest();
$this->setupFixture();

$sql = 'SELECT * FROM fetch_table';
Expand Down Expand Up @@ -908,16 +912,25 @@ private function setupFixture()
]);
}

private function skipOci8AndMysqli()
private function beforeFetchClassTest()
{
if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'oci8') {
$driver = $this->connection->getDriver();

if ($driver instanceof Oci8Driver) {
$this->markTestSkipped('Not supported by OCI8');
}
if ($this->connection->getDriver()->getName() !== 'mysqli') {

if ($driver instanceof MySQLiDriver) {
$this->markTestSkipped('Mysqli driver dont support this feature.');
}

if (! $driver instanceof PDOOracleDriver) {
return;
}

$this->markTestSkipped('Mysqli driver dont support this feature.');
/** @var PDOConnection $connection */
$connection = $this->connection->getWrappedConnection();
$connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function setUp()

$table = new Table('stmt_test');
$table->addColumn('id', 'integer');
$table->addColumn('name', 'text');
$table->addColumn('name', 'string');
$this->connection->getSchemaManager()->dropAndCreateTable($table);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@

class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
/** @var bool */
private static $privilegesGranted = false;

protected function setUp()
{
parent::setUp();

if (! isset($GLOBALS['db_username'])) {
$this->markTestSkipped('Foo');
if (self::$privilegesGranted) {
return;
}

$username = $GLOBALS['db_username'];
if (! isset($GLOBALS['db_username'])) {
self::markTestSkipped('Username must be explicitly specified in connection parameters for this test');
}

$query = 'GRANT ALL PRIVILEGES TO ' . $username;
TestUtil::getTempConnection()
->exec('GRANT ALL PRIVILEGES TO ' . $GLOBALS['db_username']);

$conn = TestUtil::getTempConnection();
$conn->executeUpdate($query);
self::$privilegesGranted = true;
}

public function testRenameTable()
Expand Down
19 changes: 19 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\Tests\DBAL\Functional;

use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
Expand All @@ -25,6 +26,10 @@ protected function setUp()

public function testStatementIsReusableAfterClosingCursor()
{
if ($this->connection->getDriver() instanceof PDOOracleDriver) {
$this->markTestIncomplete('See https://bugs.php.net/bug.php?id=77181');
}

$this->connection->insert('stmt_test', ['id' => 1]);
$this->connection->insert('stmt_test', ['id' => 2]);

Expand All @@ -46,6 +51,10 @@ public function testStatementIsReusableAfterClosingCursor()

public function testReuseStatementWithLongerResults()
{
if ($this->connection->getDriver() instanceof PDOOracleDriver) {
$this->markTestIncomplete('PDO_OCI doesn\'t support fetching blobs via PDOStatement::fetchAll()');
}

$sm = $this->connection->getSchemaManager();
$table = new Table('stmt_longer_results');
$table->addColumn('param', 'string');
Expand Down Expand Up @@ -79,6 +88,12 @@ public function testReuseStatementWithLongerResults()

public function testFetchLongBlob()
{
if ($this->connection->getDriver() instanceof PDOOracleDriver) {
// inserting BLOBs as streams on Oracle requires Oracle-specific SQL syntax which is currently not supported
// see http://php.net/manual/en/pdo.lobs.php#example-1035
$this->markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI');
}

// make sure memory limit is large enough to not cause false positives,
// but is still not enough to store a LONGBLOB of the max possible size
$this->iniSet('memory_limit', '4G');
Expand Down Expand Up @@ -138,6 +153,10 @@ public function testIncompletelyFetchedStatementDoesNotBlockConnection()

public function testReuseStatementAfterClosingCursor()
{
if ($this->connection->getDriver() instanceof PDOOracleDriver) {
$this->markTestIncomplete('See https://bugs.php.net/bug.php?id=77181');
}

$this->connection->insert('stmt_test', ['id' => 1]);
$this->connection->insert('stmt_test', ['id' => 2]);

Expand Down
7 changes: 7 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Functional;

use DateTime;
use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalFunctionalTestCase;
Expand Down Expand Up @@ -77,6 +78,12 @@ public static function dataIdempotentDataConversion()
*/
public function testIdempotentDataConversion($type, $originalValue, $expectedPhpType)
{
if ($type === 'text' && $this->connection->getDriver() instanceof PDOOracleDriver) {
// inserting BLOBs as streams on Oracle requires Oracle-specific SQL syntax which is currently not supported
// see http://php.net/manual/en/pdo.lobs.php#example-1035
$this->markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI');
}

$columnName = 'test_' . $type;
$typeInstance = Type::getType($type);
$insertionValue = $typeInstance->convertToDatabaseValue($originalValue, $this->connection->getDatabasePlatform());
Expand Down
5 changes: 5 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Tests\DBAL\Functional\Types;

use Doctrine\DBAL\Driver\IBMDB2\DB2Driver;
use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalFunctionalTestCase;
Expand All @@ -19,6 +20,10 @@ protected function setUp()
{
parent::setUp();

if ($this->connection->getDriver() instanceof PDOOracleDriver) {
$this->markTestSkipped('PDO_OCI doesn\'t support binding binary values');
}

$table = new Table('binary_table');
$table->addColumn('id', 'binary', [
'length' => 16,
Expand Down
32 changes: 27 additions & 5 deletions tests/Doctrine/Tests/DBAL/Functional/WriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Functional;

use DateTime;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
Expand Down Expand Up @@ -149,7 +150,7 @@ public function testLastInsertId()
}

self::assertEquals(1, $this->connection->insert('write_table', ['test_int' => 2, 'test_string' => 'bar']));
$num = $this->connection->lastInsertId();
$num = $this->lastInsertId();

self::assertNotNull($num, 'LastInsertId() should not be null.');
self::assertGreaterThan(0, $num, 'LastInsertId() should be non-negative number.');
Expand All @@ -175,7 +176,7 @@ public function testLastInsertIdSequence()
$stmt = $this->connection->query($this->connection->getDatabasePlatform()->getSequenceNextValSQL('write_table_id_seq'));
$nextSequenceVal = $stmt->fetchColumn();

$lastInsertId = $this->connection->lastInsertId('write_table_id_seq');
$lastInsertId = $this->lastInsertId('write_table_id_seq');

self::assertGreaterThan(0, $lastInsertId);
self::assertEquals($nextSequenceVal, $lastInsertId);
Expand All @@ -187,7 +188,7 @@ public function testLastInsertIdNoSequenceGiven()
$this->markTestSkipped("Test only works consistently on platforms that support sequences and don't support identity columns.");
}

self::assertFalse($this->connection->lastInsertId(null));
self::assertFalse($this->lastInsertId());
}

/**
Expand Down Expand Up @@ -285,11 +286,11 @@ public function testEmptyIdentityInsert()

$this->connection->exec($sql);

$firstId = $this->connection->lastInsertId($seqName);
$firstId = $this->lastInsertId($seqName);

$this->connection->exec($sql);

$secondId = $this->connection->lastInsertId($seqName);
$secondId = $this->lastInsertId($seqName);

self::assertGreaterThan($firstId, $secondId);
}
Expand Down Expand Up @@ -334,4 +335,25 @@ public function testDeleteWhereIsNull()

self::assertCount(0, $data);
}

/**
* Returns the ID of the last inserted row or skips the test if the currently used driver
* doesn't support this feature
*
* @return string
*
* @throws DriverException
*/
private function lastInsertId(?string $name = null)
{
try {
return $this->connection->lastInsertId($name);
} catch (DriverException $e) {
if ($e->getCode() === 'IM001') {
Majkl578 marked this conversation as resolved.
Show resolved Hide resolved
$this->markTestSkipped($e->getMessage());
}

throw $e;
}
}
}
11 changes: 11 additions & 0 deletions tests/continuousphp/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

declare(strict_types=1);

use Doctrine\DBAL\DriverManager;

(static function () : void {
// workaround for https://bugs.php.net/bug.php?id=77120
DriverManager::getConnection([
'driver' => 'oci8',
'host' => 'oracle-xe-11',
'user' => 'ORACLE',
'password' => 'ORACLE',
'dbname' => 'XE',
])->query('ALTER USER ORACLE IDENTIFIED BY ORACLE');

$pos = array_search('--coverage-clover', $_SERVER['argv'], true);

if ($pos === false) {
Expand Down
5 changes: 5 additions & 0 deletions tests/continuousphp/install-pdo-oci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -euo pipefail

phpbrew ext install pdo_oci -- --with-pdo-oci=instantclient,/usr/local/instantclient
Loading