class LargeQueryTest
Same name and namespace in other branches
- 8.9.x core/tests/Drupal/KernelTests/Core/Database/LargeQueryTest.php \Drupal\KernelTests\Core\Database\LargeQueryTest
Tests handling of large queries.
Attributes
#[Group('Database')]
Hierarchy
- class \Drupal\Tests\mysqli\Kernel\mysqli\LargeQueryTest
Expanded class hierarchy of LargeQueryTest
File
-
core/
modules/ mysqli/ tests/ src/ Kernel/ mysqli/ LargeQueryTest.php, line 16
Namespace
Drupal\Tests\mysqli\Kernel\mysqliView source
class LargeQueryTest extends BaseMySqlTest {
/**
* Tests truncation of messages when max_allowed_packet exception occurs.
*/
public function testMaxAllowedPacketQueryTruncating() : void {
$connectionInfo = Database::getConnectionInfo();
Database::addConnectionInfo('default', 'testMaxAllowedPacketQueryTruncating', $connectionInfo['default']);
$testConnection = Database::getConnection('testMaxAllowedPacketQueryTruncating');
// 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
// to generate a query larger than max_allowed_packet.
$max_allowed_packet = $testConnection->query('SELECT @@global.max_allowed_packet')
->fetchField();
if (!Environment::checkMemoryLimit($max_allowed_packet + 16 * 1024 * 1024)) {
$this->markTestSkipped('The configured max_allowed_packet exceeds the php memory limit. Therefore the test is skipped.');
}
$long_name = str_repeat('a', $max_allowed_packet + 1);
try {
$testConnection->query('SELECT [name] FROM {test} WHERE [name] = :name', [
':name' => $long_name,
]);
$this->fail("An exception should be thrown for queries larger than 'max_allowed_packet'");
} catch (\Throwable $e) {
Database::closeConnection('testMaxAllowedPacketQueryTruncating');
// Got a packet bigger than 'max_allowed_packet' bytes exception thrown.
$this->assertInstanceOf(DatabaseExceptionWrapper::class, $e);
$this->assertEquals(1153, $e->getPrevious()
->getCode());
// 'max_allowed_packet' exception message truncated.
// Use strlen() to count the bytes exactly, not the Unicode chars.
$this->assertLessThanOrEqual($max_allowed_packet, strlen($e->getMessage()));
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ConfigTestTrait::configImporter | protected | function | Returns a ConfigImporter object to import test configuration. |
ConfigTestTrait::copyConfig | protected | function | Copies configuration objects from source storage to target storage. |
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. |
ExtensionListTestTrait::getModulePath | protected | function | Gets the path for the specified module. |
ExtensionListTestTrait::getThemePath | protected | function | Gets the path for the specified theme. |
LargeQueryTest::testMaxAllowedPacketQueryTruncating | public | function | Tests truncation of messages when max_allowed_packet exception occurs. |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. |
StorageCopyTrait::replaceStorageContents | protected static | function | Copy the configuration from one storage to another and remove stale items. |
TestRequirementsTrait::getDrupalRoot | protected static | function | Returns the Drupal root directory. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.