Skip to content

Commit 6d80ada

Browse files
committed
Fix tests
1 parent 8d90388 commit 6d80ada

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

test/EventListener/ConsoleListenerTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Prophecy\Argument;
7+
use Sentry\Event;
78
use Sentry\SentryBundle\EventListener\ConsoleListener;
89
use Sentry\State\Hub;
910
use Sentry\State\HubInterface;
@@ -47,7 +48,7 @@ public function testOnConsoleCommandAddsCommandName(): void
4748

4849
$listener->onConsoleCommand($event->reveal());
4950

50-
$this->assertSame(['command' => 'sf:command:name'], $this->currentScope->getTags());
51+
$this->assertSame(['command' => 'sf:command:name'], $this->getTagsContext($this->currentScope));
5152
}
5253

5354
public function testOnConsoleCommandAddsPlaceholderCommandName(): void
@@ -60,6 +61,14 @@ public function testOnConsoleCommandAddsPlaceholderCommandName(): void
6061

6162
$listener->onConsoleCommand($event->reveal());
6263

63-
$this->assertSame(['command' => 'N/A'], $this->currentScope->getTags());
64+
$this->assertSame(['command' => 'N/A'], $this->getTagsContext($this->currentScope));
65+
}
66+
67+
private function getTagsContext(Scope $scope): array
68+
{
69+
$event = new Event();
70+
$scope->applyToEvent($event, []);
71+
72+
return $event->getTagsContext()->toArray();
6473
}
6574
}

test/EventListener/RequestListenerTest.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPUnit\Framework\TestCase;
66
use Prophecy\Argument;
77
use Sentry\ClientInterface;
8+
use Sentry\Event;
89
use Sentry\Options;
910
use Sentry\SentryBundle\EventListener\RequestListener;
1011
use Sentry\State\Hub;
@@ -94,7 +95,7 @@ public function testOnKernelRequestUserDataIsSetToScope($user): void
9495
'ip_address' => '1.2.3.4',
9596
'username' => 'john-doe',
9697
];
97-
$this->assertEquals($expectedUserData, $this->currentScope->getUser());
98+
$this->assertEquals($expectedUserData, $this->getUserContext($this->currentScope));
9899
}
99100

100101
public function userDataProvider(): \Generator
@@ -131,7 +132,7 @@ public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void
131132

132133
$listener->onKernelRequest($event->reveal());
133134

134-
$this->assertEquals([], $this->currentScope->getUser());
135+
$this->assertEquals([], $this->getUserContext($this->currentScope));
135136
}
136137

137138
public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void
@@ -156,7 +157,7 @@ public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void
156157

157158
$listener->onKernelRequest($event->reveal());
158159

159-
$this->assertEquals([], $this->currentScope->getUser());
160+
$this->assertEquals([], $this->getUserContext($this->currentScope));
160161
}
161162

162163
public function testOnKernelRequestUsernameIsNotSetIfTokenStorageIsAbsent(): void
@@ -187,7 +188,7 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenStorageIsAbsent(): voi
187188
$expectedUserData = [
188189
'ip_address' => '1.2.3.4',
189190
];
190-
$this->assertEquals($expectedUserData, $this->currentScope->getUser());
191+
$this->assertEquals($expectedUserData, $this->getUserContext($this->currentScope));
191192
}
192193

193194
public function testOnKernelRequestUsernameIsNotSetIfAuthorizationCheckerIsAbsent(): void
@@ -218,7 +219,7 @@ public function testOnKernelRequestUsernameIsNotSetIfAuthorizationCheckerIsAbsen
218219
$expectedUserData = [
219220
'ip_address' => '1.2.3.4',
220221
];
221-
$this->assertEquals($expectedUserData, $this->currentScope->getUser());
222+
$this->assertEquals($expectedUserData, $this->getUserContext($this->currentScope));
222223
}
223224

224225
public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
@@ -253,7 +254,7 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
253254
$expectedUserData = [
254255
'ip_address' => '1.2.3.4',
255256
];
256-
$this->assertEquals($expectedUserData, $this->currentScope->getUser());
257+
$this->assertEquals($expectedUserData, $this->getUserContext($this->currentScope));
257258
}
258259

259260
/**
@@ -295,7 +296,7 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated():
295296
$expectedUserData = [
296297
'ip_address' => '1.2.3.4',
297298
];
298-
$this->assertEquals($expectedUserData, $this->currentScope->getUser());
299+
$this->assertEquals($expectedUserData, $this->getUserContext($this->currentScope));
299300
}
300301

301302
public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered(): void
@@ -330,7 +331,7 @@ public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered(): void
330331
$expectedUserData = [
331332
'ip_address' => '1.2.3.4',
332333
];
333-
$this->assertEquals($expectedUserData, $this->currentScope->getUser());
334+
$this->assertEquals($expectedUserData, $this->getUserContext($this->currentScope));
334335
}
335336

336337
public function testOnKernelControllerAddsRouteTag(): void
@@ -403,9 +404,17 @@ public function testOnKernelRequestUserDataAndTagsAreNotSetInSubRequest(): void
403404

404405
$listener->onKernelRequest($event->reveal());
405406

406-
$this->assertEmpty($this->currentScope->getUser());
407+
$this->assertEmpty($this->getUserContext($this->currentScope));
407408
$this->assertEmpty($this->currentScope->getTags());
408409
}
410+
411+
private function getUserContext(Scope $scope): array
412+
{
413+
$event = new Event();
414+
$scope->applyToEvent($event, []);
415+
416+
return $event->getUserContext()->toArray();
417+
}
409418
}
410419

411420
class ToStringUser

0 commit comments

Comments
 (0)