class LoggerChannelPartTest in Purge 8.3
@coversDefaultClass \Drupal\purge\Logger\LoggerChannelPart
@group purge
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\purge\Unit\Logger\LoggerChannelPartTest
Expanded class hierarchy of LoggerChannelPartTest
File
- tests/
src/ Unit/ Logger/ LoggerChannelPartTest.php, line 14
Namespace
Drupal\Tests\purge\Unit\LoggerView source
class LoggerChannelPartTest extends UnitTestCase {
/**
* The mocked logger channel.
*
* @var \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface
*/
protected $loggerChannelPurge;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->loggerChannelPurge = $this
->createMock('\\Psr\\Log\\LoggerInterface');
}
/**
* Helper to all severity methods.
*/
private function helperForSeverityMethods($id, array $grants, $output, $severity) : void {
$occurrence = is_null($output) ? $this
->never() : $this
->once();
$this->loggerChannelPurge
->expects($occurrence)
->method('log')
->with($this
->stringContains($severity), $this
->stringContains('@purge_channel_part: @replaceme'), $this
->callback(function ($subject) use ($id, $output) {
return $subject['@purge_channel_part'] === $id && $subject['@replaceme'] === $output;
}));
$part = new LoggerChannelPart($this->loggerChannelPurge, $id, $grants);
$part
->{$severity}('@replaceme', [
'@replaceme' => $output,
]);
}
/**
* @covers ::__construct
*/
public function testInstance() : void {
$part = new LoggerChannelPart($this->loggerChannelPurge, 'id', []);
$this
->assertInstanceOf('\\Psr\\Log\\LoggerInterface', $part);
}
/**
* @covers ::getGrants
*
* @dataProvider providerTestGetGrants()
*/
public function testGetGrants(array $grants) : void {
$part = new LoggerChannelPart($this->loggerChannelPurge, 'id', $grants);
$this
->assertEquals(count($grants), count($part
->getGrants()));
$this
->assertEquals($grants, $part
->getGrants());
foreach ($part
->getGrants() as $k => $v) {
$this
->assertTrue(is_int($k));
$this
->assertTrue(is_int($v));
}
}
/**
* Provides test data for testGetGrants().
*/
public function providerTestGetGrants() : array {
return [
[
[],
],
[
[
RfcLogLevel::EMERGENCY,
],
],
[
[
RfcLogLevel::ALERT,
],
],
[
[
RfcLogLevel::CRITICAL,
],
],
[
[
RfcLogLevel::ERROR,
],
],
[
[
RfcLogLevel::WARNING,
],
],
[
[
RfcLogLevel::NOTICE,
],
],
[
[
RfcLogLevel::INFO,
],
],
[
[
RfcLogLevel::INFO,
RfcLogLevel::DEBUG,
],
],
[
[
RfcLogLevel::DEBUG,
],
],
];
}
/**
* @covers ::emergency
*
* @dataProvider providerTestEmergency()
*/
public function testEmergency($id, array $grants, $output) : void {
$this
->helperForSeverityMethods($id, $grants, $output, 'emergency');
}
/**
* Provides test data for testEmergency().
*/
public function providerTestEmergency() : array {
return [
[
'good',
[
RfcLogLevel::EMERGENCY,
],
'bazinga!',
],
[
'bad',
[
-1,
],
NULL,
],
];
}
/**
* @covers ::alert
*
* @dataProvider providerTestAlert()
*/
public function testAlert($id, array $grants, $output) : void {
$this
->helperForSeverityMethods($id, $grants, $output, 'alert');
}
/**
* Provides test data for testAlert().
*/
public function providerTestAlert() : array {
return [
[
'good',
[
RfcLogLevel::ALERT,
],
'bazinga!',
],
[
'bad',
[
-1,
],
NULL,
],
];
}
/**
* @covers ::critical
*
* @dataProvider providerTestCritical()
*/
public function testCritical($id, array $grants, $output) : void {
$this
->helperForSeverityMethods($id, $grants, $output, 'critical');
}
/**
* Provides test data for testCritical().
*/
public function providerTestCritical() : array {
return [
[
'good',
[
RfcLogLevel::CRITICAL,
],
'bazinga!',
],
[
'bad',
[
-1,
],
NULL,
],
];
}
/**
* @covers ::error
*
* @dataProvider providerTestError()
*/
public function testError($id, array $grants, $output) : void {
$this
->helperForSeverityMethods($id, $grants, $output, 'error');
}
/**
* Provides test data for testError().
*/
public function providerTestError() : array {
return [
[
'good',
[
RfcLogLevel::ERROR,
],
'bazinga!',
],
[
'bad',
[
-1,
],
NULL,
],
];
}
/**
* @covers ::warning
*
* @dataProvider providerTestWarning()
*/
public function testWarning($id, array $grants, $output) : void {
$this
->helperForSeverityMethods($id, $grants, $output, 'warning');
}
/**
* Provides test data for testWarning().
*/
public function providerTestWarning() : array {
return [
[
'good',
[
RfcLogLevel::WARNING,
],
'bazinga!',
],
[
'bad',
[
-1,
],
NULL,
],
];
}
/**
* @covers ::notice
*
* @dataProvider providerTestNotice()
*/
public function testNotice($id, array $grants, $output) : void {
$this
->helperForSeverityMethods($id, $grants, $output, 'notice');
}
/**
* Provides test data for testNotice().
*/
public function providerTestNotice() : array {
return [
[
'good',
[
RfcLogLevel::NOTICE,
],
'bazinga!',
],
[
'bad',
[
-1,
],
NULL,
],
];
}
/**
* @covers ::info
*
* @dataProvider providerTestInfo()
*/
public function testInfo($id, array $grants, $output) : void {
$this
->helperForSeverityMethods($id, $grants, $output, 'info');
}
/**
* Provides test data for testInfo().
*/
public function providerTestInfo() : array {
return [
[
'good',
[
RfcLogLevel::INFO,
],
'bazinga!',
],
[
'bad',
[
-1,
],
NULL,
],
];
}
/**
* @covers ::debug
*
* @dataProvider providerTestDebug()
*/
public function testDebug($id, array $grants, $output) : void {
$this
->helperForSeverityMethods($id, $grants, $output, 'debug');
}
/**
* Provides test data for testDebug().
*/
public function providerTestDebug() : array {
return [
[
'good',
[
RfcLogLevel::DEBUG,
],
'bazinga!',
],
[
'bad',
[
-1,
],
NULL,
],
];
}
/**
* @covers ::log
*
* @dataProvider providerTestLog()
*/
public function testLog($id, $level, $message, $output) : void {
$this->loggerChannelPurge
->expects($this
->once())
->method('log')
->with($this
->stringContains($level), $this
->stringContains('@purge_channel_part: ' . $message), $this
->callback(function ($subject) use ($id, $output) {
return $subject['@purge_channel_part'] === $id && $subject['@replaceme'] === $output;
}));
$part = new LoggerChannelPart($this->loggerChannelPurge, $id);
$part
->log($level, $message, [
'@replaceme' => $output,
]);
}
/**
* Provides test data for testLog().
*/
public function providerTestLog() : array {
return [
[
'id1',
'level1',
'message @placeholder',
[
'@placeholder' => 'foo',
],
],
[
'id2',
'level2',
'message @placeholder',
[
'@placeholder' => 'bar',
],
],
[
'id3',
'level3',
'message @placeholder',
[
'@placeholder' => 'baz',
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LoggerChannelPartTest:: |
protected | property | The mocked logger channel. | |
LoggerChannelPartTest:: |
private | function | Helper to all severity methods. | |
LoggerChannelPartTest:: |
public | function | Provides test data for testAlert(). | |
LoggerChannelPartTest:: |
public | function | Provides test data for testCritical(). | |
LoggerChannelPartTest:: |
public | function | Provides test data for testDebug(). | |
LoggerChannelPartTest:: |
public | function | Provides test data for testEmergency(). | |
LoggerChannelPartTest:: |
public | function | Provides test data for testError(). | |
LoggerChannelPartTest:: |
public | function | Provides test data for testGetGrants(). | |
LoggerChannelPartTest:: |
public | function | Provides test data for testInfo(). | |
LoggerChannelPartTest:: |
public | function | Provides test data for testLog(). | |
LoggerChannelPartTest:: |
public | function | Provides test data for testNotice(). | |
LoggerChannelPartTest:: |
public | function | Provides test data for testWarning(). | |
LoggerChannelPartTest:: |
protected | function |
Overrides UnitTestCase:: |
|
LoggerChannelPartTest:: |
public | function | @covers ::alert | |
LoggerChannelPartTest:: |
public | function | @covers ::critical | |
LoggerChannelPartTest:: |
public | function | @covers ::debug | |
LoggerChannelPartTest:: |
public | function | @covers ::emergency | |
LoggerChannelPartTest:: |
public | function | @covers ::error | |
LoggerChannelPartTest:: |
public | function | @covers ::getGrants | |
LoggerChannelPartTest:: |
public | function | @covers ::info | |
LoggerChannelPartTest:: |
public | function | @covers ::__construct | |
LoggerChannelPartTest:: |
public | function | @covers ::log | |
LoggerChannelPartTest:: |
public | function | @covers ::notice | |
LoggerChannelPartTest:: |
public | function | @covers ::warning | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |