|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace YdbPlatform\Ydb\Test; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use YdbPlatform\Ydb\Auth\Implement\AnonymousAuthentication; |
| 7 | +use YdbPlatform\Ydb\Logger\NullLogger; |
| 8 | +use YdbPlatform\Ydb\Logger\SimpleStdLogger; |
| 9 | +use YdbPlatform\Ydb\Ydb; |
| 10 | + |
| 11 | +class LoggerCheckTest extends TestCase{ |
| 12 | + |
| 13 | + public function testExceptExceptionInConfigs(){ |
| 14 | + $config = [ |
| 15 | + 'logger' => new SimpleStdLogger(7) |
| 16 | + ]; |
| 17 | + $this->expectException('Exception'); |
| 18 | + new Ydb($config, new NullLogger()); |
| 19 | + } |
| 20 | + public function testCheckUseLoggerFromConfig(){ |
| 21 | + $logger = new SimpleStdLogger(7); |
| 22 | + $config = [ |
| 23 | + 'logger' => $logger |
| 24 | + ]; |
| 25 | + $ydb = new Ydb($config); |
| 26 | + $this->assertEquals($logger, $ydb->getLogger()); |
| 27 | + } |
| 28 | + public function testCheckUseLoggerFromParam(){ |
| 29 | + $logger = new SimpleStdLogger(7); |
| 30 | + $config = []; |
| 31 | + $ydb = new Ydb($config, $logger); |
| 32 | + $this->assertEquals($logger, $ydb->getLogger()); |
| 33 | + } |
| 34 | + public function testCheckUseNullLogger(){ |
| 35 | + $config = []; |
| 36 | + $ydb = new Ydb($config); |
| 37 | + $this->assertInstanceOf(NullLogger::class, $ydb->getLogger()); |
| 38 | + } |
| 39 | + |
| 40 | + public function testThrowExceptionOnNonLoggerObject(){ |
| 41 | + $config = [ |
| 42 | + 'logger' => new AnonymousAuthentication() |
| 43 | + ]; |
| 44 | + $this->expectException('TypeError'); |
| 45 | + $ydb = new Ydb($config); |
| 46 | + $this->assertInstanceOf(NullLogger::class, $ydb->getLogger()); |
| 47 | + } |
| 48 | +} |
0 commit comments