|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the Micro framework package. |
| 7 | + * |
| 8 | + * (c) Stanislau Komar <kost@micro-php.net> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Micro\Plugin\Logger\Test\Unit\Configuration; |
| 15 | + |
| 16 | +use Micro\Framework\Kernel\Configuration\ApplicationConfigurationInterface; |
| 17 | +use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfiguration; |
| 18 | +use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfigurationInterface; |
| 19 | +use Micro\Plugin\Logger\Configuration\LogLevel; |
| 20 | +use PHPUnit\Framework\TestCase; |
| 21 | + |
| 22 | +class LoggerProviderTypeConfigurationTest extends TestCase |
| 23 | +{ |
| 24 | + private ApplicationConfigurationInterface $applicationConfiguration; |
| 25 | + |
| 26 | + private LoggerProviderTypeConfigurationInterface $loggerProviderTypeConfiguration; |
| 27 | + |
| 28 | + protected function setUp(): void |
| 29 | + { |
| 30 | + $this->applicationConfiguration = $this->createMock(ApplicationConfigurationInterface::class); |
| 31 | + |
| 32 | + $this->loggerProviderTypeConfiguration = new LoggerProviderTypeConfiguration( |
| 33 | + $this->applicationConfiguration, |
| 34 | + 'default' |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @dataProvider dataProvider |
| 40 | + */ |
| 41 | + public function testGetLogLevel($loggerLevel) |
| 42 | + { |
| 43 | + $this->applicationConfiguration |
| 44 | + ->expects($this->once()) |
| 45 | + ->method('get') |
| 46 | + ->with('LOGGER_DEFAULT_LOG_LEVEL') |
| 47 | + ->willReturn($loggerLevel); |
| 48 | + |
| 49 | + if ($loggerLevel) { |
| 50 | + $this->assertEquals(LogLevel::getLevelFromString($loggerLevel), $this->loggerProviderTypeConfiguration->getLogLevel()); |
| 51 | + |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + $this->assertEquals(LogLevel::DEBUG->level(), $this->loggerProviderTypeConfiguration->getLogLevel()); |
| 56 | + } |
| 57 | + |
| 58 | + public function dataProvider() |
| 59 | + { |
| 60 | + return [ |
| 61 | + 'critical', |
| 62 | + null, |
| 63 | + ]; |
| 64 | + } |
| 65 | + |
| 66 | + public function testGetType() |
| 67 | + { |
| 68 | + $this->applicationConfiguration |
| 69 | + ->expects($this->once()) |
| 70 | + ->method('get') |
| 71 | + ->with('LOGGER_DEFAULT_PROVIDER_TYPE') |
| 72 | + ->willReturn('default_type'); |
| 73 | + |
| 74 | + $this->assertEquals('default_type', $this->loggerProviderTypeConfiguration->getType()); |
| 75 | + } |
| 76 | + |
| 77 | + public function testGetLoggerName() |
| 78 | + { |
| 79 | + $this->assertEquals('default', $this->loggerProviderTypeConfiguration->getLoggerName()); |
| 80 | + } |
| 81 | +} |
0 commit comments