diff --git a/composer.json b/composer.json index 670760d..620c62b 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "php": "^7.2|^8.0", "ext-json": "*", "guzzlehttp/guzzle": "~7.0", - "psr/log": "^1.1" + "psr/log": "^1.1 || ^2.0 || ^3.0" }, "require-dev": { "phpunit/phpunit": "^9.0", diff --git a/tests/Transports/GuzzleAsyncTest.php b/tests/Transports/GuzzleAsyncTest.php index c1f014d..c33eddc 100644 --- a/tests/Transports/GuzzleAsyncTest.php +++ b/tests/Transports/GuzzleAsyncTest.php @@ -9,7 +9,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use PHPUnit\Framework\TestCase; -use Psr\Log\Test\TestLogger; +use Psr\Log\LoggerInterface; use Raygun4php\RaygunMessage; use Raygun4php\Transports\GuzzleAsync; @@ -28,13 +28,12 @@ public function testTransmitLogsErrorIfResponseCodeIs400() $transport = new GuzzleAsync($client); $message = new RaygunMessage(); - $logger = new TestLogger(); + $logger = $this->createMock(LoggerInterface::class); + $logger->expects($this->atLeastOnce())->method('error'); $transport->setLogger($logger); $transport->transmit($message); $transport->wait(); - - $this->assertTrue($logger->hasErrorRecords()); } public function testTransmitLogsWarningIfResponseCodeIs200() @@ -49,13 +48,12 @@ public function testTransmitLogsWarningIfResponseCodeIs200() $transport = new GuzzleAsync($client); $message = new RaygunMessage(); - $logger = new TestLogger(); + $logger = $this->createMock(LoggerInterface::class); + $logger->expects($this->atLeastOnce())->method('warning'); $transport->setLogger($logger); $transport->transmit($message); $transport->wait(); - - $this->assertTrue($logger->hasWarningRecords()); } public function testTransmitLogsErrorIfHttpClientThrowsException() @@ -71,12 +69,11 @@ public function testTransmitLogsErrorIfHttpClientThrowsException() $message = new RaygunMessage(); - $logger = new TestLogger(); + $logger = $this->createMock(LoggerInterface::class); + $logger->expects($this->atLeastOnce())->method('error'); $transport->setLogger($logger); $transport->transmit($message); $transport->wait(); - - $this->assertTrue($logger->hasErrorRecords()); } } diff --git a/tests/Transports/GuzzleSyncTest.php b/tests/Transports/GuzzleSyncTest.php index c49312b..4414882 100644 --- a/tests/Transports/GuzzleSyncTest.php +++ b/tests/Transports/GuzzleSyncTest.php @@ -5,11 +5,11 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\ConnectException; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use Psr\Log\Test\TestLogger; use Raygun4php\RaygunMessage; use Raygun4php\Transports\GuzzleSync; @@ -72,12 +72,11 @@ public function testTransmitLogsErrorIfHttpClientThrowsException() $transport = new GuzzleSync($client); $message = new RaygunMessage(); - $logger = new TestLogger(); + $logger = $this->createMock(LoggerInterface::class); + $logger->expects($this->atLeastOnce())->method('error'); $transport->setLogger($logger); $transport->transmit($message); - - $this->assertTrue($logger->hasErrorRecords()); } public function testTransmitLogsRelevant400Message() @@ -92,12 +91,13 @@ public function testTransmitLogsRelevant400Message() $transport = new GuzzleSync($client); $message = new RaygunMessage(); - $logger = new TestLogger(); + $logger = $this->createMock(LoggerInterface::class); + $logger->expects($this->atLeastOnce()) + ->method('error') + ->with($this->stringContains('400')); $transport->setLogger($logger); $transport->transmit($message); - - $this->assertTrue($logger->hasErrorThatContains('400')); } public function testTransmitLogsRelevant400MessageNoException() @@ -115,12 +115,13 @@ public function testTransmitLogsRelevant400MessageNoException() $transport = new GuzzleSync($client); $message = new RaygunMessage(); - $logger = new TestLogger(); + $logger = $this->createMock(LoggerInterface::class); + $logger->expects($this->atLeastOnce()) + ->method('error') + ->with($this->stringContains('400')); $transport->setLogger($logger); $transport->transmit($message); - - $this->assertTrue($logger->hasErrorThatContains('400')); } public function testTransmitLogsRelevant403Message() @@ -135,12 +136,13 @@ public function testTransmitLogsRelevant403Message() $transport = new GuzzleSync($client); $message = new RaygunMessage(); - $logger = new TestLogger(); + $logger = $this->createMock(LoggerInterface::class); + $logger->expects($this->atLeastOnce()) + ->method('error') + ->with($this->stringContains('403')); $transport->setLogger($logger); $transport->transmit($message); - - $this->assertTrue($logger->hasErrorThatContains('403')); } public function testTransmitReturnsFalseOnHttpStatus400NoException()