Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / dblog / tests / src / Functional / ConnectionFailureTest.php
1 <?php
2
3 namespace Drupal\Tests\dblog\Functional;
4
5 use Drupal\Core\Database\Database;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests logging of connection failures.
10  *
11  * @group dblog
12  */
13 class ConnectionFailureTest extends BrowserTestBase {
14
15   public static $modules = ['dblog'];
16
17   /**
18    * Tests logging of connection failures.
19    */
20   public function testConnectionFailureLogging() {
21     $logger = \Drupal::service('logger.factory');
22
23     // MySQL errors like "1153 - Got a packet bigger than 'max_allowed_packet'
24     // bytes" or "1100 - Table 'xyz' was not locked with LOCK TABLES" lead to a
25     // database connection unusable for further requests. All further request
26     // will result in an "2006 - MySQL server had gone away" error. As a
27     // consequence it's impossible to use this connection to log the causing
28     // initial error itself. Using Database::closeConnection() we simulate such
29     // a corrupted connection. In this case dblog has to establish a different
30     // connection by itself to be able to write the log entry.
31     Database::closeConnection();
32
33     // Create a log entry.
34     $logger->get('php')->error('testConnectionFailureLogging');
35
36     // Re-establish the default database connection.
37     Database::getConnection();
38
39     $wid = db_query("SELECT MAX(wid) FROM {watchdog} WHERE message = 'testConnectionFailureLogging'")->fetchField();
40     $this->assertTrue($wid, 'Watchdog entry has been stored in database.');
41   }
42
43 }