class LoggerIntegrationTest in Service Container 7
Same name and namespace in other branches
- 7.2 lib/Drupal/service_container/Tests/LoggerIntegrationTest.php \Drupal\service_container\Tests\LoggerIntegrationTest
Hierarchy
- class \Drupal\service_container\Tests\ServiceContainerIntegrationTestBase extends \Drupal\service_container\Tests\DrupalWebTestCase
- class \Drupal\service_container\Tests\LoggerIntegrationTest
Expanded class hierarchy of LoggerIntegrationTest
File
- lib/
Drupal/ service_container/ Tests/ LoggerIntegrationTest.php, line 12 - Contains \Drupal\service_container\Tests\LoggerIntegrationTest.
Namespace
Drupal\service_container\TestsView source
class LoggerIntegrationTest extends ServiceContainerIntegrationTestBase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Logger',
'description' => 'Some integration test for the logger.',
'group' => 'service_container',
);
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp(array(
'dblog',
));
}
public function testLog() {
/** @var \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory */
$logger_factory = $this->container
->get('logger.factory');
/** @var \Drupal\Core\Database\Connection $connection */
$connection = $this->container
->get('database');
// Use both the factory and the logger channel directly.
$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);
}
/**
* Checks whether the expected logging entry got written.
*
* @param \Drupal\Core\Database\Connection $connection
* The database collection.
*/
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));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LoggerIntegrationTest:: |
protected | function | Checks whether the expected logging entry got written. | |
LoggerIntegrationTest:: |
public static | function | ||
LoggerIntegrationTest:: |
protected | function |
Overrides ServiceContainerIntegrationTestBase:: |
|
LoggerIntegrationTest:: |
public | function | ||
ServiceContainerIntegrationTestBase:: |
protected | property | The dependency injection container usable in the test. | |
ServiceContainerIntegrationTestBase:: |
protected | property | The profile to install as a basis for testing. | 1 |