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

Detect driver in tests based on configured driver name #4951

Merged
merged 3 commits into from
Nov 6, 2021
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
11 changes: 5 additions & 6 deletions tests/Functional/BlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace Doctrine\DBAL\Tests\Functional;

use Doctrine\DBAL\Driver\OCI8\Driver as OCI8Driver;
use Doctrine\DBAL\Driver\PDO;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use Doctrine\DBAL\Types\Type;

use function fopen;
Expand All @@ -17,7 +16,7 @@ class BlobTest extends FunctionalTestCase
{
protected function setUp(): void
{
if ($this->connection->getDriver() instanceof PDO\OCI\Driver) {
if (TestUtil::isDriverOneOf('pdo_oci')) {
// 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
self::markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI');
Expand Down Expand Up @@ -50,7 +49,7 @@ public function testInsert(): void
public function testInsertProcessesStream(): void
{
// https://github.com/doctrine/dbal/issues/3290
if ($this->connection->getDriver() instanceof OCI8Driver) {
if (TestUtil::isDriverOneOf('oci8')) {
self::markTestIncomplete('The oci8 driver does not support stream resources as parameters');
}

Expand Down Expand Up @@ -106,7 +105,7 @@ public function testUpdate(): void
public function testUpdateProcessesStream(): void
{
// https://github.com/doctrine/dbal/issues/3290
if ($this->connection->getDriver() instanceof OCI8Driver) {
if (TestUtil::isDriverOneOf('oci8')) {
self::markTestIncomplete('The oci8 driver does not support stream resources as parameters');
}

Expand All @@ -133,7 +132,7 @@ public function testUpdateProcessesStream(): void

public function testBindParamProcessesStream(): void
{
if ($this->connection->getDriver() instanceof OCI8Driver) {
if (TestUtil::isDriverOneOf('oci8')) {
self::markTestIncomplete('The oci8 driver does not support stream resources as parameters');
}

Expand Down
51 changes: 29 additions & 22 deletions tests/Functional/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ConnectionException;
use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver\PDO\Connection as PDOConnection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
Expand Down Expand Up @@ -69,7 +68,7 @@ public function testTransactionNestingBehavior(): void
$this->connection->insert(self::TABLE, ['id' => 1]);
self::fail('Expected exception to be thrown because of the unique constraint.');
} catch (Throwable $e) {
$this->assertIsUniqueConstraintException($e);
self::assertInstanceOf(UniqueConstraintViolationException::class, $e);
$this->connection->rollBack();
self::assertSame(1, $this->connection->getTransactionNestingLevel());
}
Expand Down Expand Up @@ -144,7 +143,7 @@ public function testTransactionNestingBehaviorWithSavepoints(): void
$this->connection->insert(self::TABLE, ['id' => 1]);
self::fail('Expected exception to be thrown because of the unique constraint.');
} catch (Throwable $e) {
$this->assertIsUniqueConstraintException($e);
self::assertInstanceOf(UniqueConstraintViolationException::class, $e);
$this->connection->rollBack();
self::assertSame(1, $this->connection->getTransactionNestingLevel());
}
Expand Down Expand Up @@ -241,7 +240,7 @@ public function testTransactionBehaviorWithRollback(): void
$this->connection->insert(self::TABLE, ['id' => 1]);
self::fail('Expected exception to be thrown because of the unique constraint.');
} catch (Throwable $e) {
$this->assertIsUniqueConstraintException($e);
self::assertInstanceOf(UniqueConstraintViolationException::class, $e);
self::assertSame(1, $this->connection->getTransactionNestingLevel());
$this->connection->rollBack();
self::assertSame(0, $this->connection->getTransactionNestingLevel());
Expand Down Expand Up @@ -269,7 +268,7 @@ public function testTransactionalWithException(): void
});
self::fail('Expected exception to be thrown because of the unique constraint.');
} catch (Throwable $e) {
$this->assertIsUniqueConstraintException($e);
self::assertInstanceOf(UniqueConstraintViolationException::class, $e);
self::assertSame(0, $this->connection->getTransactionNestingLevel());
}
}
Expand Down Expand Up @@ -393,31 +392,39 @@ public function testPersistentConnection(): void
self::assertTrue($pdo->getAttribute(PDO::ATTR_PERSISTENT));
}

private function createTestTable(): void
public function testExceptionOnExecuteStatement(): void
{
$table = new Table(self::TABLE);
$table->addColumn('id', 'integer');
$table->setPrimaryKey(['id']);
$this->expectException(DriverException::class);

$this->dropAndCreateTable($table);
$this->connection->executeStatement('foo');
}

$this->connection->insert(self::TABLE, ['id' => 1]);
public function testExceptionOnExecuteQuery(): void
{
$this->expectException(DriverException::class);

$this->connection->executeQuery('foo');
}

private function assertIsUniqueConstraintException(Throwable $exception): void
/**
* Some drivers do not check the query server-side even though emulated prepared statements are disabled,
* so an exception is thrown only eventually.
*/
public function testExceptionOnPrepareAndExecute(): void
{
if ($this->connection->getDriver() instanceof IBMDB2\Driver) {
// The IBM DB2 driver currently doesn't instantiate specialized exceptions
$this->expectException(DriverException::class);

return;
}
$this->connection->prepare('foo')->executeStatement();
}

if ($this->connection->getDriver() instanceof AbstractSQLServerDriver) {
// The SQL Server drivers currently don't instantiate specialized exceptions
private function createTestTable(): void
{
$table = new Table(self::TABLE);
$table->addColumn('id', 'integer');
$table->setPrimaryKey(['id']);

return;
}
$this->dropAndCreateTable($table);

self::assertInstanceOf(UniqueConstraintViolationException::class, $exception);
$this->connection->insert(self::TABLE, ['id' => 1]);
}
}
6 changes: 3 additions & 3 deletions tests/Functional/Driver/IBMDB2/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Doctrine\DBAL\Tests\Functional\Driver\IBMDB2;

use Doctrine\DBAL\Driver\IBMDB2\Connection;
use Doctrine\DBAL\Driver\IBMDB2\Driver;
use Doctrine\DBAL\Driver\IBMDB2\Exception\ConnectionFailed;
use Doctrine\DBAL\Driver\IBMDB2\Exception\PrepareFailed;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use ReflectionProperty;

use function db2_close;
Expand All @@ -18,11 +18,11 @@ class ConnectionTest extends FunctionalTestCase
{
protected function setUp(): void
{
if ($this->connection->getDriver() instanceof Driver) {
if (TestUtil::isDriverOneOf('ibm_db2')) {
return;
}

$this->markTestSkipped('ibm_db2 only test.');
self::markTestSkipped('This test requires the ibm_db2 driver.');
}

protected function tearDown(): void
Expand Down
5 changes: 3 additions & 2 deletions tests/Functional/Driver/IBMDB2/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\IBMDB2\Driver;
use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest;
use Doctrine\DBAL\Tests\TestUtil;

/**
* @requires extension ibm_db2
Expand All @@ -15,11 +16,11 @@ protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof Driver) {
if (TestUtil::isDriverOneOf('ibm_db2')) {
return;
}

self::markTestSkipped('ibm_db2 only test.');
self::markTestSkipped('This test requires the ibm_db2 driver.');
}

public function testConnectsWithoutDatabaseNameParameter(): void
Expand Down
6 changes: 3 additions & 3 deletions tests/Functional/Driver/IBMDB2/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Doctrine\DBAL\Tests\Functional\Driver\IBMDB2;

use Doctrine\DBAL\Driver\IBMDB2\Driver;
use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;

use const E_ALL;
use const E_NOTICE;
Expand All @@ -19,11 +19,11 @@ class StatementTest extends FunctionalTestCase
{
protected function setUp(): void
{
if ($this->connection->getDriver() instanceof Driver) {
if (TestUtil::isDriverOneOf('ibm_db2')) {
return;
}

self::markTestSkipped('ibm_db2 only test.');
self::markTestSkipped('This test requires the ibm_db2 driver.');
}

public function testExecutionErrorsAreNotSuppressed(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Driver/Mysqli/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class ConnectionTest extends FunctionalTestCase
{
protected function setUp(): void
{
if ($this->connection->getDriver() instanceof Driver) {
if (TestUtil::isDriverOneOf('mysqli')) {
return;
}

self::markTestSkipped('MySQLi only test.');
self::markTestSkipped('This test requires the mysqli driver.');
}

public function testSupportedDriverOptions(): void
Expand Down
5 changes: 3 additions & 2 deletions tests/Functional/Driver/Mysqli/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\Mysqli\Driver;
use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest;
use Doctrine\DBAL\Tests\TestUtil;

/**
* @requires extension mysqli
Expand All @@ -15,11 +16,11 @@ protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof Driver) {
if (TestUtil::isDriverOneOf('mysqli')) {
return;
}

self::markTestSkipped('MySQLi only test.');
self::markTestSkipped('This test requires the mysqli driver.');
}

protected function createDriver(): DriverInterface
Expand Down
6 changes: 3 additions & 3 deletions tests/Functional/Driver/OCI8/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Doctrine\DBAL\Tests\Functional\Driver\OCI8;

use Doctrine\DBAL\Driver\OCI8\Driver;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;

/**
* @requires extension oci8
Expand All @@ -13,11 +13,11 @@ class ConnectionTest extends FunctionalTestCase
{
protected function setUp(): void
{
if ($this->connection->getDriver() instanceof Driver) {
if (TestUtil::isDriverOneOf('oci8')) {
return;
}

self::markTestSkipped('oci8 only test.');
self::markTestSkipped('This test requires the oci8 driver.');
}

public function testLastInsertIdAcceptsFqn(): void
Expand Down
5 changes: 3 additions & 2 deletions tests/Functional/Driver/OCI8/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\OCI8\Driver;
use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest;
use Doctrine\DBAL\Tests\TestUtil;

/**
* @requires extension oci8
Expand All @@ -15,11 +16,11 @@ protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof Driver) {
if (TestUtil::isDriverOneOf('oci8')) {
return;
}

self::markTestSkipped('oci8 only test.');
self::markTestSkipped('This test requires the oci8 driver.');
}

public function testConnectsWithoutDatabaseNameParameter(): void
Expand Down
5 changes: 2 additions & 3 deletions tests/Functional/Driver/OCI8/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\DBAL\Tests\Functional\Driver\OCI8;

use Doctrine\DBAL\Driver\OCI8\Driver;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
Expand Down Expand Up @@ -32,11 +31,11 @@ protected function setUp(): void
{
$this->connectionParams = TestUtil::getConnectionParams();

if ($this->connection->getDriver() instanceof Driver) {
if (TestUtil::isDriverOneOf('oci8')) {
return;
}

self::markTestSkipped('oci8 only test.');
self::markTestSkipped('This test requires the oci8 driver.');
}

protected function tearDown(): void
Expand Down
6 changes: 3 additions & 3 deletions tests/Functional/Driver/OCI8/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Doctrine\DBAL\Tests\Functional\Driver\OCI8;

use Doctrine\DBAL\Driver\OCI8\Driver;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;

/**
* @requires extension oci8
Expand All @@ -12,11 +12,11 @@ class StatementTest extends FunctionalTestCase
{
protected function setUp(): void
{
if ($this->connection->getDriver() instanceof Driver) {
if (TestUtil::isDriverOneOf('oci8')) {
return;
}

self::markTestSkipped('oci8 only test.');
self::markTestSkipped('This test requires the oci8 driver.');
}

/**
Expand Down
Loading