Skip to content

Commit a479ce6

Browse files
Merge pull request #154 from edsrzf/psr-log-update
2 parents 1a0d5c4 + 5d6a5d0 commit a479ce6

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"php": "^7.2|^8.0",
2222
"ext-json": "*",
2323
"guzzlehttp/guzzle": "~7.0",
24-
"psr/log": "^1.1"
24+
"psr/log": "^1.1 || ^2.0 || ^3.0"
2525
},
2626
"require-dev": {
2727
"phpunit/phpunit": "^9.0",

tests/Transports/GuzzleAsyncTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use GuzzleHttp\Psr7\Request;
1010
use GuzzleHttp\Psr7\Response;
1111
use PHPUnit\Framework\TestCase;
12-
use Psr\Log\Test\TestLogger;
12+
use Psr\Log\LoggerInterface;
1313
use Raygun4php\RaygunMessage;
1414
use Raygun4php\Transports\GuzzleAsync;
1515

@@ -28,13 +28,12 @@ public function testTransmitLogsErrorIfResponseCodeIs400()
2828
$transport = new GuzzleAsync($client);
2929
$message = new RaygunMessage();
3030

31-
$logger = new TestLogger();
31+
$logger = $this->createMock(LoggerInterface::class);
32+
$logger->expects($this->atLeastOnce())->method('error');
3233
$transport->setLogger($logger);
3334

3435
$transport->transmit($message);
3536
$transport->wait();
36-
37-
$this->assertTrue($logger->hasErrorRecords());
3837
}
3938

4039
public function testTransmitLogsWarningIfResponseCodeIs200()
@@ -49,13 +48,12 @@ public function testTransmitLogsWarningIfResponseCodeIs200()
4948
$transport = new GuzzleAsync($client);
5049
$message = new RaygunMessage();
5150

52-
$logger = new TestLogger();
51+
$logger = $this->createMock(LoggerInterface::class);
52+
$logger->expects($this->atLeastOnce())->method('warning');
5353
$transport->setLogger($logger);
5454

5555
$transport->transmit($message);
5656
$transport->wait();
57-
58-
$this->assertTrue($logger->hasWarningRecords());
5957
}
6058

6159
public function testTransmitLogsErrorIfHttpClientThrowsException()
@@ -71,12 +69,11 @@ public function testTransmitLogsErrorIfHttpClientThrowsException()
7169

7270
$message = new RaygunMessage();
7371

74-
$logger = new TestLogger();
72+
$logger = $this->createMock(LoggerInterface::class);
73+
$logger->expects($this->atLeastOnce())->method('error');
7574
$transport->setLogger($logger);
7675

7776
$transport->transmit($message);
7877
$transport->wait();
79-
80-
$this->assertTrue($logger->hasErrorRecords());
8178
}
8279
}

tests/Transports/GuzzleSyncTest.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
use GuzzleHttp\Client;
66
use GuzzleHttp\Exception\ConnectException;
77
use PHPUnit\Framework\TestCase;
8+
use Psr\Log\LoggerInterface;
89
use GuzzleHttp\Handler\MockHandler;
910
use GuzzleHttp\HandlerStack;
1011
use GuzzleHttp\Psr7\Request;
1112
use GuzzleHttp\Psr7\Response;
12-
use Psr\Log\Test\TestLogger;
1313
use Raygun4php\RaygunMessage;
1414
use Raygun4php\Transports\GuzzleSync;
1515

@@ -72,12 +72,11 @@ public function testTransmitLogsErrorIfHttpClientThrowsException()
7272
$transport = new GuzzleSync($client);
7373
$message = new RaygunMessage();
7474

75-
$logger = new TestLogger();
75+
$logger = $this->createMock(LoggerInterface::class);
76+
$logger->expects($this->atLeastOnce())->method('error');
7677
$transport->setLogger($logger);
7778

7879
$transport->transmit($message);
79-
80-
$this->assertTrue($logger->hasErrorRecords());
8180
}
8281

8382
public function testTransmitLogsRelevant400Message()
@@ -92,12 +91,13 @@ public function testTransmitLogsRelevant400Message()
9291
$transport = new GuzzleSync($client);
9392
$message = new RaygunMessage();
9493

95-
$logger = new TestLogger();
94+
$logger = $this->createMock(LoggerInterface::class);
95+
$logger->expects($this->atLeastOnce())
96+
->method('error')
97+
->with($this->stringContains('400'));
9698
$transport->setLogger($logger);
9799

98100
$transport->transmit($message);
99-
100-
$this->assertTrue($logger->hasErrorThatContains('400'));
101101
}
102102

103103
public function testTransmitLogsRelevant400MessageNoException()
@@ -115,12 +115,13 @@ public function testTransmitLogsRelevant400MessageNoException()
115115
$transport = new GuzzleSync($client);
116116
$message = new RaygunMessage();
117117

118-
$logger = new TestLogger();
118+
$logger = $this->createMock(LoggerInterface::class);
119+
$logger->expects($this->atLeastOnce())
120+
->method('error')
121+
->with($this->stringContains('400'));
119122
$transport->setLogger($logger);
120123

121124
$transport->transmit($message);
122-
123-
$this->assertTrue($logger->hasErrorThatContains('400'));
124125
}
125126

126127
public function testTransmitLogsRelevant403Message()
@@ -135,12 +136,13 @@ public function testTransmitLogsRelevant403Message()
135136
$transport = new GuzzleSync($client);
136137
$message = new RaygunMessage();
137138

138-
$logger = new TestLogger();
139+
$logger = $this->createMock(LoggerInterface::class);
140+
$logger->expects($this->atLeastOnce())
141+
->method('error')
142+
->with($this->stringContains('403'));
139143
$transport->setLogger($logger);
140144

141145
$transport->transmit($message);
142-
143-
$this->assertTrue($logger->hasErrorThatContains('403'));
144146
}
145147

146148
public function testTransmitReturnsFalseOnHttpStatus400NoException()

0 commit comments

Comments
 (0)