Verified Commit 8d8b2405 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3231950 by mondrake, daffie, joegraduate: Split Database tests in...

Issue #3231950 by mondrake, daffie, joegraduate: Split Database tests in 'core' ones and 'driver specific' ones

(cherry picked from commit d755c76e)
parent a484c5dd
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\mysql\Kernel\mysql;

use Drupal\Core\Database\Database;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\KernelTests\Core\Database\DriverSpecificDatabaseTestBase;

/**
 * MySQL-specific connection tests.
 *
 * @group Database
 */
class ConnectionTest extends DriverSpecificDatabaseTestBase {

  /**
   * Ensure that you cannot execute multiple statements on MySQL.
   */
  public function testMultipleStatementsForNewPhp(): void {
    $this->expectException(DatabaseExceptionWrapper::class);
    Database::getConnection('default', 'default')->query('SELECT * FROM {test}; SELECT * FROM {test_people}', [], ['allow_delimiter_in_query' => TRUE]);
  }

}
+25 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\mysql\Kernel\mysql;

use Drupal\KernelTests\Core\Database\DriverSpecificConnectionUnitTestBase;

/**
 * MySQL-specific connection unit tests.
 *
 * @group Database
 */
class ConnectionUnitTest extends DriverSpecificConnectionUnitTestBase {

  /**
   * Returns a set of queries specific for MySQL.
   */
  protected function getQuery(): array {
    return [
      'connection_id' => 'SELECT CONNECTION_ID()',
      'processlist' => 'SHOW PROCESSLIST',
      'show_tables' => 'SHOW TABLES',
    ];
  }

}
+43 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\mysql\Kernel\mysql;

use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Database\Database;
use Drupal\KernelTests\Core\Database\DriverSpecificKernelTestBase;

/**
 * Tests exceptions thrown by queries.
 *
 * @group Database
 */
class DatabaseExceptionWrapperTest extends DriverSpecificKernelTestBase {

  /**
   * Tests Connection::prepareStatement exceptions on preparation.
   *
   * Core database drivers use PDO emulated statements or the StatementPrefetch
   * class, which defer the statement check to the moment of the execution. In
   * order to test a failure at preparation time, we have to force the
   * connection not to emulate statement preparation. Still, this is only valid
   * for the MySql driver.
   */
  public function testPrepareStatementFailOnPreparation() {
    $connection_info = Database::getConnectionInfo('default');
    $connection_info['default']['pdo'][\PDO::ATTR_EMULATE_PREPARES] = FALSE;
    Database::addConnectionInfo('default', 'foo', $connection_info['default']);
    $foo_connection = Database::getConnection('foo', 'default');
    $this->expectException(DatabaseExceptionWrapper::class);
    $stmt = $foo_connection->prepareStatement('bananas', []);
  }

  /**
   * Tests Connection::prepareStatement exception on execution.
   */
  public function testPrepareStatementFailOnExecution() {
    $this->expectException(\PDOException::class);
    $stmt = $this->connection->prepareStatement('bananas', []);
    $stmt->execute();
  }

}
+4 −8
Original line number Diff line number Diff line
<?php

namespace Drupal\KernelTests\Core\Database;
namespace Drupal\Tests\mysql\Kernel\mysql;

use Drupal\Component\Utility\Environment;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\DatabaseException;
use Drupal\KernelTests\Core\Database\DriverSpecificDatabaseTestBase;

/**
 * Tests handling of large queries.
 *
 * @group Database
 */
class LargeQueryTest extends DatabaseTestBase {
class LargeQueryTest extends DriverSpecificDatabaseTestBase {

  /**
   * Tests truncation of messages when max_allowed_packet exception occurs.
   */
  public function testMaxAllowedPacketQueryTruncating() {
    // Only run this test for the 'mysql' driver.
    $driver = $this->connection->driver();
    if ($driver !== 'mysql') {
      $this->markTestSkipped("MySql tests can not run for driver '$driver'.");
    }
  public function testMaxAllowedPacketQueryTruncating(): void {
    // The max_allowed_packet value is configured per database instance.
    // Retrieve the max_allowed_packet value from the current instance and
    // check if PHP is configured with sufficient allowed memory to be able
+3 −12
Original line number Diff line number Diff line
<?php

namespace Drupal\KernelTests\Core\Database;
namespace Drupal\Tests\mysql\Kernel\mysql;

use Drupal\Core\Database\Driver\mysql\Connection;
use Drupal\Core\Database\Driver\mysql\ExceptionHandler;
@@ -8,6 +8,7 @@
use Drupal\Core\Database\Driver\mysql\Insert;
use Drupal\Core\Database\Driver\mysql\Schema;
use Drupal\Core\Database\Driver\mysql\Upsert;
use Drupal\KernelTests\Core\Database\DriverSpecificDatabaseTestBase;
use Drupal\Tests\Core\Database\Stub\StubPDO;

/**
@@ -16,17 +17,7 @@
 * @group legacy
 * @group Database
 */
class MysqlDriverLegacyTest extends DatabaseTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    if ($this->connection->driver() !== 'mysql') {
      $this->markTestSkipped('Only test the deprecation message for the MySQL database driver classes in Core.');
    }
  }
class MysqlDriverLegacyTest extends DriverSpecificDatabaseTestBase {

  /**
   * @covers Drupal\Core\Database\Driver\mysql\Install\Tasks
Loading