Skip to content

Commit 7404176

Browse files
committed
wip handle older SDK versions
Will either squash this into the first commit if acceptable, the alternative is to just bump the required version of `sentry/sentry`.
1 parent 45a7c8c commit 7404176

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
## Unreleased
44

5-
- Report exceptions to Sentry as unhandled by default.
6-
- Exceptions from messages which will be retried are sent to Sentry as handled.
5+
- Report exceptions to Sentry as unhandled by default (when `sentry/sentry` ≥ 3.11).
6+
- Exceptions from messages which will be retried are sent to Sentry as handled (when `sentry/sentry` ≥ 3.11).
77

88
## 4.4.0 (2022-10-20)
99

tests/EventListener/AbstractConsoleListenerTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public function testHandleConsoleTerminateEvent(): void
102102
*/
103103
public function testHandleConsoleErrorEvent(bool $captureErrors): void
104104
{
105+
// For BC with sentry/sentry < 3.11
106+
$checkMechanism = \property_exists(EventHint::class, 'mechanism');
107+
105108
$scope = new Scope();
106109
$consoleEvent = new ConsoleErrorEvent(new ArrayInput([]), new NullOutput(), new \Exception());
107110
$listenerClass = static::getListenerClass();
@@ -119,10 +122,13 @@ public function testHandleConsoleErrorEvent(bool $captureErrors): void
119122
$this->anything(),
120123
$this->logicalAnd(
121124
$this->isInstanceOf(EventHint::class),
122-
$this->callback(function (EventHint $subject) use ($consoleEvent) {
125+
$this->callback(function (EventHint $subject) use ($consoleEvent, $checkMechanism) {
123126
self::assertSame($consoleEvent->getError(), $subject->exception);
124-
self::assertNotNull($subject->mechanism);
125-
self::assertFalse($subject->mechanism->isHandled());
127+
128+
if ($checkMechanism) {
129+
self::assertNotNull($subject->mechanism);
130+
self::assertFalse($subject->mechanism->isHandled());
131+
}
126132

127133
return true;
128134
})

tests/EventListener/ErrorListenerTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ protected function setUp(): void
4141
*/
4242
public function testHandleExceptionEvent($event): void
4343
{
44+
// For BC with sentry/sentry < 3.11
45+
$checkMechanism = \property_exists(EventHint::class, 'mechanism');
46+
4447
$expectedException = $event instanceof ExceptionEvent ? $event->getThrowable() : $event->getException();
4548

4649
$this->hub->expects($this->once())
@@ -49,10 +52,13 @@ public function testHandleExceptionEvent($event): void
4952
$this->anything(),
5053
$this->logicalAnd(
5154
$this->isInstanceOf(EventHint::class),
52-
$this->callback(function (EventHint $subject) use ($expectedException) {
55+
$this->callback(function (EventHint $subject) use ($expectedException, $checkMechanism) {
5356
self::assertSame($expectedException, $subject->exception);
54-
self::assertNotNull($subject->mechanism);
55-
self::assertFalse($subject->mechanism->isHandled());
57+
58+
if ($checkMechanism) {
59+
self::assertNotNull($subject->mechanism);
60+
self::assertFalse($subject->mechanism->isHandled());
61+
}
5662

5763
return true;
5864
})

tests/EventListener/MessengerListenerTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public function testHandleWorkerMessageFailedEvent(array $exceptions, WorkerMess
5050
$this->markTestSkipped('Messenger not supported in this environment.');
5151
}
5252

53+
// For BC with sentry/sentry < 3.11
54+
$checkMechanism = \property_exists(EventHint::class, 'mechanism');
55+
5356
$scope = new Scope();
5457

5558
$this->hub->expects($this->once())
@@ -60,15 +63,18 @@ public function testHandleWorkerMessageFailedEvent(array $exceptions, WorkerMess
6063

6164
$this->hub->expects($this->exactly(\count($exceptions)))
6265
->method('captureEvent')
63-
->withConsecutive(...array_map(function (\Throwable $expectedException) use ($expectedIsHandled): array {
66+
->withConsecutive(...array_map(function (\Throwable $expectedException) use ($expectedIsHandled, $checkMechanism): array {
6467
return [
6568
$this->anything(),
6669
$this->logicalAnd(
6770
$this->isInstanceOf(EventHint::class),
68-
$this->callback(function (EventHint $subject) use ($expectedException, $expectedIsHandled) {
71+
$this->callback(function (EventHint $subject) use ($expectedException, $expectedIsHandled, $checkMechanism) {
6972
self::assertSame($expectedException, $subject->exception);
70-
self::assertNotNull($subject->mechanism);
71-
self::assertSame($expectedIsHandled, $subject->mechanism->isHandled());
73+
74+
if ($checkMechanism) {
75+
self::assertNotNull($subject->mechanism);
76+
self::assertSame($expectedIsHandled, $subject->mechanism->isHandled());
77+
}
7278

7379
return true;
7480
})

0 commit comments

Comments
 (0)