class LogsHttpLoggerTest in Logs HTTP 8
Tests the Logs Http logger service.
@group logs_http @coversDefaultClass \Drupal\logs_http\Logger\LogsHttpLogger
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\logs_http\Unit\LogsHttpLoggerTest
Expanded class hierarchy of LogsHttpLoggerTest
File
- tests/
src/ Unit/ LogsHttpLoggerTest.php, line 17
Namespace
Drupal\Tests\logs_http\UnitView source
class LogsHttpLoggerTest extends UnitTestCase {
/**
* The config object.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $config;
/**
* The log message parser service.
*
* @var \Drupal\Core\Logger\LogMessageParserInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $logMessageParser;
/**
* The severity levels array.
*
* @var array
*/
protected $severityLevels;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->config = $this
->prophesize(ConfigFactoryInterface::class);
$this->logMessageParser = $this
->prophesize(LogMessageParserInterface::class);
$this->severityLevels = RfcLogLevel::getLevels();
$this->config
->get('logs_http.settings')
->willReturn($this->config
->reveal());
}
/**
* Tests isEnabled method.
*
* @covers ::isEnabled
* @dataProvider isEnabledProvider
*/
public function testIsEnabled($enabled, $url, $expected) {
$this->config
->get('enabled')
->willReturn($enabled);
$this->config
->get('url')
->willReturn($url);
$logger = new LogsHttpLogger($this->config
->reveal(), $this->logMessageParser
->reveal());
$result = $logger
->isEnabled();
$this
->assertEquals($expected, $result);
}
/**
* Provides test data to test isEnabled.
*
* In order to isEnabled method to return TRUE, the 'enabled' configuration
* must be TRUE and the url must not be empty.
*
* @return array
* Array with:
* - "enabled" boolean value.
* - "url" string value.
* - The expected result.
*/
public function isEnabledProvider() {
return [
[
FALSE,
'',
FALSE,
],
[
FALSE,
'https://example.com',
FALSE,
],
[
TRUE,
'',
FALSE,
],
[
TRUE,
'https://example.com',
TRUE,
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LogsHttpLoggerTest:: |
protected | property | The config object. | |
LogsHttpLoggerTest:: |
protected | property | The log message parser service. | |
LogsHttpLoggerTest:: |
protected | property | The severity levels array. | |
LogsHttpLoggerTest:: |
public | function | Provides test data to test isEnabled. | |
LogsHttpLoggerTest:: |
public | function |
Overrides UnitTestCase:: |
|
LogsHttpLoggerTest:: |
public | function | Tests isEnabled method. | |
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. |