Skip to content

Commit

Permalink
Disabled and reworked some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Nov 20, 2018
1 parent 20bd597 commit 60b4a7c
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 14 deletions.
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) {
throw new PDOException($exception);
}
}

/**
Expand Down
12 changes: 11 additions & 1 deletion 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\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
Expand All @@ -23,10 +24,19 @@ protected function setUp()
{
parent::setUp();

if ($this->connection->getDriver() instanceof PDOSQLSrvDriver) {
$driver = $this->connection->getDriver();

if ($driver instanceof PDOSQLSrvDriver) {
$this->markTestSkipped('This test does not work on pdo_sqlsrv driver due to a bug. See: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/5a755bdd-41e9-45cb-9166-c9da4475bb94/how-to-set-null-for-varbinarymax-using-bindvalue-using-pdosqlsrv?forum=sqldriverforphp');
}

if ($driver instanceof PDOOracleDriver) {
// inserting BLOBs with the PDO Oracle driver requires a different SQL syntax
// which is currently not supported
// see http://php.net/manual/en/pdo.lobs.php#example-1035
$this->markTestSkipped('This test does not work on pdo_oci');
}

/** @var AbstractSchemaManager $sm */
$table = new Table('blob_table');
$table->addColumn('id', 'integer');
Expand Down
20 changes: 14 additions & 6 deletions tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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\PDOOracle\Driver as PDOOracleDriver;
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSRVDriver;
use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver;
Expand Down Expand Up @@ -754,7 +755,7 @@ public function testFetchAllStyleObject()
*/
public function testFetchAllSupportFetchClass()
{
$this->skipOci8AndMysqli();
$this->skipUnsupportedDrivers();
$this->setupFixture();

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

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

$sql = 'SELECT * FROM fetch_table';
Expand Down Expand Up @@ -935,12 +936,19 @@ private function setupFixture()
]);
}

private function skipOci8AndMysqli()
private function skipUnsupportedDrivers()
{
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 PDOOracleDriver) {
$this->markTestSkipped('Not supported by PDO Oracle');
}

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

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
8 changes: 8 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 Down Expand Up @@ -79,6 +80,13 @@ public function testReuseStatementWithLongerResults()

public function testFetchLongBlob()
{
if ($this->connection->getDriver() instanceof PDOOracleDriver) {
// inserting BLOBs with the PDO Oracle driver requires a different SQL syntax
// which is currently not supported
// see http://php.net/manual/en/pdo.lobs.php#example-1035
$this->markTestSkipped('This test does not work on 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
8 changes: 8 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\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
Expand Down Expand Up @@ -81,6 +82,13 @@ public static function dataIdempotentDataConversion()
*/
public function testIdempotentDataConversion($type, $originalValue, $expectedPhpType)
{
if ($type === 'text' && $this->connection->getDriver() instanceof PDOOracleDriver) {
// inserting LOBs with the PDO Oracle driver requires a different SQL syntax
// which is currently not supported
// see http://php.net/manual/en/pdo.lobs.php#example-1035
$this->markTestSkipped('This test does not work on 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('Binary fields are not supported on PDO Oracle');
}

$table = new Table('binary_table');
$table->addColumn('id', 'binary', [
'length' => 16,
Expand Down
39 changes: 34 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\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Sequence;
Expand Down Expand Up @@ -151,7 +152,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 @@ -177,7 +178,15 @@ 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');
try {
$lastInsertId = $this->lastInsertId('write_table_id_seq');
} catch (DriverException $e) {
if ($e->getCode() === 'IM001') {
$this->markTestSkipped($e->getMessage());
}

throw $e;
}

self::assertGreaterThan(0, $lastInsertId);
self::assertEquals($nextSequenceVal, $lastInsertId);
Expand All @@ -189,7 +198,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(null));
}

/**
Expand Down Expand Up @@ -287,11 +296,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 @@ -336,4 +345,24 @@ 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
*
* @return string
*
* @throws DriverException
*/
private function lastInsertId(?string $name = null)
{
try {
return $this->connection->lastInsertId($name);
} catch (DriverException $e) {
if ($e->getCode() === 'IM001') {
$this->markTestSkipped($e->getMessage());
}

throw $e;
}
}
}

0 comments on commit 60b4a7c

Please sign in to comment.