Skip to content

Commit

Permalink
Merge pull request #4868 from morozov/functional-connect-disconnect
Browse files Browse the repository at this point in the history
 Rework connect/disconnect routines in functional tests
  • Loading branch information
derrabus committed Oct 13, 2021
2 parents 6322f1e + e635885 commit ade125f
Show file tree
Hide file tree
Showing 46 changed files with 37 additions and 177 deletions.
2 changes: 0 additions & 2 deletions tests/Driver/API/ExceptionConverterTest.php
Expand Up @@ -19,8 +19,6 @@ abstract class ExceptionConverterTest extends TestCase

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

$this->converter = $this->createConverter();
}

Expand Down
2 changes: 0 additions & 2 deletions tests/Driver/AbstractDriverTest.php
Expand Up @@ -27,8 +27,6 @@ abstract class AbstractDriverTest extends TestCase

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

$this->driver = $this->createDriver();
}

Expand Down
2 changes: 0 additions & 2 deletions tests/Driver/PDO/ExceptionTest.php
Expand Up @@ -33,8 +33,6 @@ class ExceptionTest extends TestCase

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

$this->wrappedException = new PDOException(self::MESSAGE);

$this->wrappedException->errorInfo = [self::SQLSTATE, self::ERROR_CODE];
Expand Down
8 changes: 3 additions & 5 deletions tests/Functional/AutoIncrementColumnTest.php
Expand Up @@ -13,8 +13,6 @@ class AutoIncrementColumnTest extends FunctionalTestCase

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

$table = new Table('auto_increment_table');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->setPrimaryKey(['id']);
Expand All @@ -25,11 +23,11 @@ protected function setUp(): void

protected function tearDown(): void
{
if ($this->shouldDisableIdentityInsert) {
$this->connection->executeStatement('SET IDENTITY_INSERT auto_increment_table OFF');
if (! $this->shouldDisableIdentityInsert) {
return;
}

parent::tearDown();
$this->connection->executeStatement('SET IDENTITY_INSERT auto_increment_table OFF');
}

public function testInsertIdentityValue(): void
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/BlobTest.php
Expand Up @@ -17,8 +17,6 @@ class BlobTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof PDO\OCI\Driver) {
// 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
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/Connection/ConnectionLostTest.php
Expand Up @@ -12,8 +12,6 @@ class ConnectionLostTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
return;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/Connection/FetchTest.php
Expand Up @@ -16,8 +16,6 @@ class FetchTest extends FunctionalTestCase

public function setUp(): void
{
parent::setUp();

$this->query = TestUtil::generateResultSetQuery([
[
'a' => 'foo',
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/ConnectionTest.php
Expand Up @@ -33,8 +33,6 @@ protected function tearDown(): void
}

$this->markConnectionNotReusable();

parent::tearDown();
}

public function testGetWrappedConnection(): void
Expand Down
13 changes: 1 addition & 12 deletions tests/Functional/DataAccessTest.php
Expand Up @@ -22,33 +22,22 @@

class DataAccessTest extends FunctionalTestCase
{
/** @var bool */
private static $generated = false;

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

if (self::$generated !== false) {
return;
}

$table = new Table('fetch_table');
$table->addColumn('test_int', 'integer');
$table->addColumn('test_string', 'string');
$table->addColumn('test_datetime', 'datetime', ['notnull' => false]);
$table->setPrimaryKey(['test_int']);

$sm = $this->connection->getSchemaManager();
$sm->createTable($table);
$sm->dropAndCreateTable($table);

$this->connection->insert('fetch_table', [
'test_int' => 1,
'test_string' => 'foo',
'test_datetime' => '2010-01-01 10:10:10',
]);

self::$generated = true;
}

public function testPrepareWithBindValue(): void
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/Driver/AbstractDriverTest.php
Expand Up @@ -18,8 +18,6 @@ abstract class AbstractDriverTest extends FunctionalTestCase

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

$this->driver = $this->createDriver();
}

Expand Down
4 changes: 0 additions & 4 deletions tests/Functional/Driver/IBMDB2/ConnectionTest.php
Expand Up @@ -18,8 +18,6 @@ class ConnectionTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof Driver) {
return;
}
Expand All @@ -30,8 +28,6 @@ protected function setUp(): void
protected function tearDown(): void
{
$this->markConnectionNotReusable();

parent::tearDown();
}

public function testConnectionFailure(): void
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/Driver/IBMDB2/StatementTest.php
Expand Up @@ -19,8 +19,6 @@ class StatementTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof Driver) {
return;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/Driver/Mysqli/ConnectionTest.php
Expand Up @@ -19,8 +19,6 @@ class ConnectionTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof Driver) {
return;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/Driver/OCI8/ConnectionTest.php
Expand Up @@ -13,8 +13,6 @@ class ConnectionTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof Driver) {
return;
}
Expand Down
3 changes: 0 additions & 3 deletions tests/Functional/Driver/OCI8/ResultTest.php
Expand Up @@ -30,7 +30,6 @@ class ResultTest extends FunctionalTestCase

protected function setUp(): void
{
parent::setUp();
$this->connectionParams = TestUtil::getConnectionParams();

if ($this->connection->getDriver() instanceof Driver) {
Expand All @@ -50,8 +49,6 @@ protected function tearDown(): void
'DROP TYPE return_numbers',
$this->connectionParams['user']
));

parent::tearDown();
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/Driver/OCI8/StatementTest.php
Expand Up @@ -12,8 +12,6 @@ class StatementTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof Driver) {
return;
}
Expand Down
4 changes: 0 additions & 4 deletions tests/Functional/Driver/PDO/ConnectionTest.php
Expand Up @@ -24,8 +24,6 @@ class ConnectionTest extends FunctionalTestCase

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

$driverConnection = $this->connection->getWrappedConnection();

if (! $driverConnection instanceof Connection) {
Expand All @@ -38,8 +36,6 @@ protected function setUp(): void
protected function tearDown(): void
{
$this->markConnectionNotReusable();

parent::tearDown();
}

public function testThrowsWrappedExceptionOnConstruct(): void
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/Driver/PDO/PgSQL/ConnectionTest.php
Expand Up @@ -13,8 +13,6 @@ class ConnectionTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof Driver) {
return;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/Driver/SQLSrv/StatementTest.php
Expand Up @@ -13,8 +13,6 @@ class StatementTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof Driver) {
return;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/ExceptionTest.php
Expand Up @@ -36,8 +36,6 @@ class ExceptionTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$driver = $this->connection->getDriver();

if ($driver instanceof IBMDB2\Driver) {
Expand Down
4 changes: 1 addition & 3 deletions tests/Functional/LegacyAPITest.php
Expand Up @@ -16,8 +16,6 @@ class LegacyAPITest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$table = new Table('legacy_table');
$table->addColumn('test_int', 'integer');
$table->addColumn('test_string', 'string');
Expand All @@ -32,7 +30,7 @@ protected function setUp(): void
]);
}

public function tearDown(): void
protected function tearDown(): void
{
$this->connection->executeStatement('DELETE FROM legacy_table WHERE test_int > 1');
}
Expand Down
16 changes: 5 additions & 11 deletions tests/Functional/LockMode/NoneTest.php
Expand Up @@ -22,8 +22,6 @@ class NoneTest extends FunctionalTestCase

public function setUp(): void
{
parent::setUp();

if ($this->connection->getDriver() instanceof OCI8\Driver) {
// https://github.com/doctrine/dbal/issues/4417
self::markTestSkipped('This test fails on OCI8 for a currently unknown reason');
Expand Down Expand Up @@ -59,22 +57,18 @@ public function setUp(): void
self::fail('Separate connections do not seem to talk to the same database');
}

public function tearDown(): void
protected function tearDown(): void
{
parent::tearDown();

if ($this->connection2->isTransactionActive()) {
$this->connection2->rollBack();
}

$this->connection2->close();

$this->connection->getSchemaManager()->dropTable('users');

if (! $this->connection->getDatabasePlatform() instanceof SQLServer2012Platform) {
return;
}

if ($this->connection->isTransactionActive()) {
$this->connection->rollBack();
}

$db = $this->connection->getDatabase();
$this->connection->executeStatement('ALTER DATABASE ' . $db . ' SET READ_COMMITTED_SNAPSHOT OFF');
}
Expand Down
42 changes: 12 additions & 30 deletions tests/Functional/ModifyLimitQueryTest.php
Expand Up @@ -15,38 +15,20 @@

class ModifyLimitQueryTest extends FunctionalTestCase
{
/** @var bool */
private static $tableCreated = false;

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

if (! self::$tableCreated) {
$table = new Table('modify_limit_table');
$table->addColumn('test_int', 'integer');
$table->setPrimaryKey(['test_int']);

$table2 = new Table('modify_limit_table2');
$table2->addColumn('id', 'integer', ['autoincrement' => true]);
$table2->addColumn('test_int', 'integer');
$table2->setPrimaryKey(['id']);

$sm = $this->connection->getSchemaManager();
$sm->createTable($table);
$sm->createTable($table2);
self::$tableCreated = true;
}

$platform = $this->connection->getDatabasePlatform();

$this->connection->executeStatement(
$platform->getTruncateTableSQL('modify_limit_table')
);

$this->connection->executeStatement(
$platform->getTruncateTableSQL('modify_limit_table2')
);
$table = new Table('modify_limit_table');
$table->addColumn('test_int', 'integer');
$table->setPrimaryKey(['test_int']);

$table2 = new Table('modify_limit_table2');
$table2->addColumn('id', 'integer', ['autoincrement' => true]);
$table2->addColumn('test_int', 'integer');
$table2->setPrimaryKey(['id']);

$sm = $this->connection->getSchemaManager();
$sm->dropAndCreateTable($table);
$sm->dropAndCreateTable($table2);
}

public function testModifyLimitQuerySimpleQuery(): void
Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/NamedParametersTest.php
Expand Up @@ -150,8 +150,6 @@ public static function ticketProvider(): iterable

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

if ($this->connection->getSchemaManager()->tablesExist('ddc1372_foobar')) {
return;
}
Expand Down
Expand Up @@ -13,8 +13,6 @@ final class NewPrimaryKeyWithNewAutoIncrementColumnTest extends FunctionalTestCa
{
protected function setUp(): void
{
parent::setUp();

if ($this->getPlatform() instanceof MySQLPlatform) {
return;
}
Expand Down
6 changes: 1 addition & 5 deletions tests/Functional/PortabilityTest.php
Expand Up @@ -16,8 +16,6 @@ class PortabilityTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->connection = DriverManager::getConnection(
$this->connection->getParams(),
$this->connection->getConfiguration()
Expand Down Expand Up @@ -49,11 +47,9 @@ protected function setUp(): void
}
}

public function tearDown(): void
protected function tearDown(): void
{
$this->markConnectionNotReusable();

parent::tearDown();
}

public function testFullFetchMode(): void
Expand Down

0 comments on commit ade125f

Please sign in to comment.