Loading core/modules/mysql/tests/src/Kernel/mysql/ConnectionTest.php 0 → 100644 +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]); } } core/modules/mysql/tests/src/Kernel/mysql/ConnectionUnitTest.php 0 → 100644 +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', ]; } } core/modules/mysql/tests/src/Kernel/mysql/DatabaseExceptionWrapperTest.php 0 → 100644 +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(); } } core/tests/Drupal/KernelTests/Core/Database/LargeQueryTest.php→core/modules/mysql/tests/src/Kernel/mysql/LargeQueryTest.php +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 Loading core/tests/Drupal/KernelTests/Core/Database/MysqlDriverLegacyTest.php→core/modules/mysql/tests/src/Kernel/mysql/MysqlDriverLegacyTest.php +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; Loading @@ -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; /** Loading @@ -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 Loading
core/modules/mysql/tests/src/Kernel/mysql/ConnectionTest.php 0 → 100644 +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]); } }
core/modules/mysql/tests/src/Kernel/mysql/ConnectionUnitTest.php 0 → 100644 +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', ]; } }
core/modules/mysql/tests/src/Kernel/mysql/DatabaseExceptionWrapperTest.php 0 → 100644 +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(); } }
core/tests/Drupal/KernelTests/Core/Database/LargeQueryTest.php→core/modules/mysql/tests/src/Kernel/mysql/LargeQueryTest.php +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 Loading
core/tests/Drupal/KernelTests/Core/Database/MysqlDriverLegacyTest.php→core/modules/mysql/tests/src/Kernel/mysql/MysqlDriverLegacyTest.php +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; Loading @@ -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; /** Loading @@ -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