LoggerCheckTest.php 1.4 KB

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