* @link https://www.oxidmodule.com */ namespace D3\GuzzleFactory\tests\Apps; use D3\GuzzleFactory\GuzzleFactory; use D3\LoggerFactory\LoggerFactory; use Monolog\Logger; use ReflectionException; use RuntimeException; trait OxidLoggerTestTrait { /** * @test * @return void * @throws ReflectionException * @covers \D3\GuzzleFactory\GuzzleFactory::addOxidLogger */ public function testAddOxidLoggerWithoutOxid(): void { $sut = GuzzleFactory::create(); $this->expectException(RuntimeException::class); $this->callMethod( $sut, 'addOxidLogger', ); } /** * @test * @return void * @throws ReflectionException * @covers \D3\GuzzleFactory\GuzzleFactory::getOxidLogPath */ public function testGetOxidLogPathWithoutOxid(): void { $sut = GuzzleFactory::create(); $this->expectException(RuntimeException::class); $this->assertSame( 'foo', $this->callMethod( $sut, 'getOxidLogPath', ['fixture.log'] ) ); } /** * @test * @return void * @throws ReflectionException * @covers \D3\GuzzleFactory\GuzzleFactory::addOxidLogger */ public function testAddOxidLoggerInOxid(): void { require_once __DIR__.'/../Helpers/classAliases.php'; $sut = GuzzleFactory::create(); $this->callMethod( $sut, 'addOxidLogger', ); $loggers = $this->getValue($sut, 'loggers'); $this->assertArrayHasKey('oxid', $loggers); $this->assertInstanceOf(Logger::class, $loggers['oxid']); } /** * @test * @return void * @throws ReflectionException * @covers \D3\GuzzleFactory\GuzzleFactory::addCombinedOxidAndFileLogger */ public function testAddCombinedOxidAndFileLogger(): void { require_once __DIR__.'/../Helpers/classAliases.php'; $loggerFactory = $this->getMockBuilder(LoggerFactory::class) ->onlyMethods(['getCombinedOxidAndFileLogger']) ->getMock(); $loggerFactory->expects($this->once())->method('getCombinedOxidAndFileLogger'); $sut = $this->getMockBuilder(GuzzleFactory::class) ->onlyMethods(['getLoggerFactory']) ->getMock(); $sut->method('getLoggerFactory')->willReturn($loggerFactory); $this->setValue($sut, 'loggers', ['oxid' => 1]); $this->callMethod( $sut, 'addCombinedOxidAndFileLogger', ['nameFixture', 'file/path.log', 1, 5] ); $loggers = $this->getValue($sut, 'loggers'); $this->assertArrayHasKey('nameFixture', $loggers); $this->assertArrayNotHasKey('oxid', $loggers); $this->assertInstanceOf(Logger::class, $loggers['nameFixture']); } /** * @test * @return void * @throws ReflectionException * @covers \D3\GuzzleFactory\GuzzleFactory::getOxidLogPath */ public function testGetOxidLogPathInOxid(): void { require_once __DIR__.'/../Helpers/classAliases.php'; $sut = GuzzleFactory::create(); $this->assertStringEndsWith( 'tests/Helpers/log/fixture.log', $this->callMethod( $sut, 'getOxidLogPath', ['fixture.log'] ) ); } }