LargeQueryTest.php in Zircon Profile 8
File
core/modules/system/src/Tests/Database/LargeQueryTest.php
View source
<?php
namespace Drupal\system\Tests\Database;
use Drupal\Component\Utility\Environment;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\DatabaseException;
class LargeQueryTest extends DatabaseTestBase {
function testMaxAllowedPacketQueryTruncating() {
$database = Database::getConnectionInfo('default');
if ($database['default']['driver'] == 'mysql') {
$max_allowed_packet = db_query('SELECT @@global.max_allowed_packet')
->fetchField();
if (Environment::checkMemoryLimit($max_allowed_packet + 16 * 1024 * 1024)) {
$long_name = str_repeat('a', $max_allowed_packet + 1);
try {
db_query('SELECT name FROM {test} WHERE name = :name', array(
':name' => $long_name,
));
$this
->fail("An exception should be thrown for queries larger than 'max_allowed_packet'");
} catch (DatabaseException $e) {
Database::closeConnection();
Database::getConnection();
$this
->assertEqual($e
->getPrevious()->errorInfo[1], 1153, "Got a packet bigger than 'max_allowed_packet' bytes exception thrown.");
$this
->assertTrue(strlen($e
->getMessage()) <= $max_allowed_packet, "'max_allowed_packet' exception message truncated.");
}
}
else {
$this
->verbose('The configured max_allowed_packet exceeds the php memory limit. Therefore the test is skipped.');
}
}
else {
$this
->verbose('The test requires MySQL. Therefore the test is skipped.');
}
}
}