LoggerIntegrationTest.php in Service Container 7
File
lib/Drupal/service_container/Tests/LoggerIntegrationTest.php
View source
<?php
namespace Drupal\service_container\Tests;
use Drupal\Core\Database\Connection;
class LoggerIntegrationTest extends ServiceContainerIntegrationTestBase {
public static function getInfo() {
return array(
'name' => 'Logger',
'description' => 'Some integration test for the logger.',
'group' => 'service_container',
);
}
protected function setUp() {
parent::setUp(array(
'dblog',
));
}
public function testLog() {
$logger_factory = $this->container
->get('logger.factory');
$connection = $this->container
->get('database');
$connection
->truncate('watchdog')
->execute();
$logger_factory
->get('system')
->info('Hello world @key', array(
'@key' => 'value',
));
$this
->doTestEntry($connection);
$connection
->truncate('watchdog')
->execute();
$logger_channel = $this->container
->get('logger.channel.default');
$logger_channel
->info('Hello world @key', array(
'@key' => 'value',
));
$this
->doTestEntry($connection);
}
protected function doTestEntry(Connection $connection) {
$result = $connection
->select('watchdog')
->fields('watchdog')
->execute()
->fetchAll();
$this
->assertEqual(1, count($result));
$this
->assertEqual(WATCHDOG_INFO, $result[0]->severity);
$this
->assertEqual('system', $result[0]->type);
$this
->assertEqual('Hello world @key', $result[0]->message);
$this
->assertEqual(array(
'@key' => 'value',
), unserialize($result[0]->variables));
}
}