class LoggerChannelTest in Service Container 7.2
Same name and namespace in other branches
- 7 tests/src/Logger/LoggerChannelTest.php \Drupal\Tests\service_container\Logger\LoggerChannelTest
@coversDefaultClass \Drupal\service_container\Logger\LoggerChannel
Hierarchy
- class \Drupal\Tests\service_container\Logger\LoggerChannelTest extends \Drupal\Tests\service_container\Logger\PHPUnit_Framework_TestCase
Expanded class hierarchy of LoggerChannelTest
File
- tests/
src/ Logger/ LoggerChannelTest.php, line 16 - Contains \Drupal\Tests\service_container\Logger\LoggerChannelTest.
Namespace
Drupal\Tests\service_container\LoggerView source
class LoggerChannelTest extends \PHPUnit_Framework_TestCase {
/**
* The tested logger channel.
*
* @var \Drupal\service_container\Logger\LoggerChannel
*/
protected $loggerChannel;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->loggerChannel = new LoggerChannel('test');
}
/**
* @covers ::__construct()
*/
public function test_construct() {
$this
->assertInstanceOf('\\Drupal\\service_container\\Logger\\LoggerChannel', $this->loggerChannel);
$this
->assertAttributeEquals('test', 'channel', $this->loggerChannel);
}
/**
* @covers ::log()
* @covers ::addLogger()
*
* @dataProvider providerLogLevels
*/
public function test_log_singleLogger($log_method = NULL, $log_level = LogLevel::INFO) {
$logger = \Mockery::mock('Psr\\Log\\LoggerInterface');
$logger
->shouldReceive('log')
->with($log_level, 'test-message', array(
'key' => 'value',
'channel' => 'test',
));
$this->loggerChannel
->addLogger($logger);
if (is_null($log_method)) {
$this->loggerChannel
->log($log_level, 'test-message', array(
'key' => 'value',
));
}
else {
$this->loggerChannel
->{$log_method}('test-message', array(
'key' => 'value',
));
}
}
/**
* @covers ::log()
* @covers ::setLoggers()
*/
public function test_setLoggers() {
$logger1 = \Mockery::mock('Psr\\Log\\LoggerInterface');
$logger2 = \Mockery::mock('Psr\\Log\\LoggerInterface');
// Note: We use globally()/ordered() in order to ensure that $logger2 is
// called first.
$logger2
->shouldReceive('log')
->globally()
->ordered()
->with(LogLevel::INFO, 'test-message', array(
'key' => 'value',
'channel' => 'test',
));
$logger1
->shouldReceive('log')
->globally()
->ordered()
->with(LogLevel::INFO, 'test-message', array(
'key' => 'value',
'channel' => 'test',
));
$this->loggerChannel
->setLoggers(array(
0 => array(
$logger1,
),
10 => array(
$logger2,
),
));
$this->loggerChannel
->log(LogLevel::INFO, 'test-message', array(
'key' => 'value',
));
}
/**
* @covers ::log()
* @covers ::sortLoggers()
* @covers ::addLogger()
*
* @covers ::emergency()
* @covers ::alert()
* @covers ::critical()
* @covers ::error()
* @covers ::warning()
* @covers ::notice()
* @covers ::info()
* @covers ::debug()
*
* @dataProvider providerLogLevels
*/
public function test_sortLogger($log_method = NULL, $log_level = LogLevel::INFO) {
$logger1 = \Mockery::mock('Psr\\Log\\LoggerInterface');
$logger2 = \Mockery::mock('Psr\\Log\\LoggerInterface');
// Note: We use globally()/ordered() in order to ensure that $logger2 is
// called first.
$logger2
->shouldReceive('log')
->globally()
->ordered()
->with($log_level, 'test-message', array(
'key' => 'value',
'channel' => 'test',
));
$logger1
->shouldReceive('log')
->globally()
->ordered()
->with($log_level, 'test-message', array(
'key' => 'value',
'channel' => 'test',
));
$this->loggerChannel
->addLogger($logger1, 0);
$this->loggerChannel
->addLogger($logger2, 10);
if (is_null($log_method)) {
$this->loggerChannel
->log($log_level, 'test-message', array(
'key' => 'value',
));
}
else {
$this->loggerChannel
->{$log_method}('test-message', array(
'key' => 'value',
));
}
}
public function providerLogLevels() {
$data = array();
$data[] = array(
'emergency',
LogLevel::EMERGENCY,
);
$data[] = array(
'alert',
LogLevel::ALERT,
);
$data[] = array(
'critical',
LogLevel::CRITICAL,
);
$data[] = array(
'error',
LogLevel::ERROR,
);
$data[] = array(
'warning',
LogLevel::WARNING,
);
$data[] = array(
'notice',
LogLevel::NOTICE,
);
$data[] = array(
'info',
LogLevel::INFO,
);
$data[] = array(
'debug',
LogLevel::DEBUG,
);
return $data;
}
/**
* @covers ::setRequestStack()
*/
public function test_setRequestStack() {
$request_stack = \Mockery::mock('alias:Symfony\\Component\\HttpFoundation\\RequestStack');
$this->loggerChannel
->setRequestStack($request_stack);
$this
->assertAttributeEquals($request_stack, 'requestStack', $this->loggerChannel);
}
/**
* @covers ::setCurrentUser()
*/
public function test_setCurrentUser() {
$current_user = \Mockery::mock('alias:Drupal\\Core\\Session\\AccountInterface');
$this->loggerChannel
->setCurrentUser($current_user);
$this
->assertAttributeEquals($current_user, 'currentUser', $this->loggerChannel);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LoggerChannelTest:: |
protected | property | The tested logger channel. | |
LoggerChannelTest:: |
public | function | ||
LoggerChannelTest:: |
protected | function | ||
LoggerChannelTest:: |
public | function | @covers ::__construct() | |
LoggerChannelTest:: |
public | function | @covers ::log() @covers ::addLogger() | |
LoggerChannelTest:: |
public | function | @covers ::setCurrentUser() | |
LoggerChannelTest:: |
public | function | @covers ::log() @covers ::setLoggers() | |
LoggerChannelTest:: |
public | function | @covers ::setRequestStack() | |
LoggerChannelTest:: |
public | function | @covers ::log() @covers ::sortLoggers() @covers ::addLogger() |