Skip to content

Commit 70ed51f

Browse files
committed
Fix usage of newer feature in test suite
1 parent b0a5ade commit 70ed51f

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

test/BaseTestCase.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Sentry\Options;
7+
use Sentry\SentrySdk;
8+
use Sentry\State\Hub;
9+
use Sentry\State\HubInterface;
710

811
abstract class BaseTestCase extends TestCase
912
{
@@ -31,4 +34,13 @@ protected function getSupportedOptionsCount(): int
3134

3235
return $count;
3336
}
37+
38+
protected function setCurrentHub(HubInterface $hub): void
39+
{
40+
if (class_exists(SentrySdk::class)) {
41+
SentrySdk::setCurrentHub($hub);
42+
} else {
43+
Hub::setCurrent($hub);
44+
}
45+
}
3446
}

test/Command/SentryTestCommandTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
namespace Sentry\SentryBundle\Test\Command;
44

5-
use PHPUnit\Framework\TestCase;
65
use Prophecy\Argument;
76
use Sentry\ClientInterface;
87
use Sentry\Options;
98
use Sentry\SentryBundle\Command\SentryTestCommand;
10-
use Sentry\SentrySdk;
9+
use Sentry\SentryBundle\Test\BaseTestCase;
1110
use Sentry\State\HubInterface;
1211
use Symfony\Component\Console\Application;
1312
use Symfony\Component\Console\Tester\CommandTester;
1413

15-
class SentryTestCommandTest extends TestCase
14+
class SentryTestCommandTest extends BaseTestCase
1615
{
1716
public function testExecuteSuccessfully(): void
1817
{
@@ -29,7 +28,7 @@ public function testExecuteSuccessfully(): void
2928
->shouldBeCalled()
3029
->willReturn($lastEventId);
3130

32-
SentrySdk::setCurrentHub($hub->reveal());
31+
$this->setCurrentHub($hub->reveal());
3332

3433
$commandTester = $this->executeCommand();
3534

@@ -51,7 +50,7 @@ public function testExecuteFailsDueToMissingDSN(): void
5150
$hub->getClient()
5251
->willReturn($client->reveal());
5352

54-
SentrySdk::setCurrentHub($hub->reveal());
53+
$this->setCurrentHub($hub->reveal());
5554

5655
$commandTester = $this->executeCommand();
5756

@@ -75,7 +74,7 @@ public function testExecuteFailsDueToMessageNotSent(): void
7574
->shouldBeCalled()
7675
->willReturn(null);
7776

78-
SentrySdk::setCurrentHub($hub->reveal());
77+
$this->setCurrentHub($hub->reveal());
7978

8079
$commandTester = $this->executeCommand();
8180

@@ -92,7 +91,7 @@ public function testExecuteFailsDueToMissingClient(): void
9291
$hub->getClient()
9392
->willReturn(null);
9493

95-
SentrySdk::setCurrentHub($hub->reveal());
94+
$this->setCurrentHub($hub->reveal());
9695

9796
$commandTester = $this->executeCommand();
9897

test/EventListener/ConsoleListenerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
namespace Sentry\SentryBundle\Test\EventListener;
44

5-
use PHPUnit\Framework\TestCase;
65
use Prophecy\Argument;
76
use Sentry\Event;
87
use Sentry\SentryBundle\EventListener\ConsoleListener;
9-
use Sentry\SentrySdk;
8+
use Sentry\SentryBundle\Test\BaseTestCase;
109
use Sentry\State\HubInterface;
1110
use Sentry\State\Scope;
1211
use Symfony\Component\Console\Command\Command;
1312
use Symfony\Component\Console\Event\ConsoleCommandEvent;
1413

15-
class ConsoleListenerTest extends TestCase
14+
class ConsoleListenerTest extends BaseTestCase
1615
{
1716
private $currentHub;
1817
private $currentScope;
@@ -31,7 +30,7 @@ protected function setUp()
3130
$callable($scope);
3231
});
3332

34-
SentrySdk::setCurrentHub($this->currentHub->reveal());
33+
$this->setCurrentHub($this->currentHub->reveal());
3534
}
3635

3736
public function testOnConsoleCommandAddsCommandName(): void

test/EventListener/RequestListenerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace Sentry\SentryBundle\Test\EventListener;
44

5-
use PHPUnit\Framework\TestCase;
65
use Prophecy\Argument;
76
use Sentry\ClientInterface;
87
use Sentry\Event;
98
use Sentry\Options;
109
use Sentry\SentryBundle\EventListener\RequestListener;
11-
use Sentry\SentrySdk;
10+
use Sentry\SentryBundle\Test\BaseTestCase;
1211
use Sentry\State\HubInterface;
1312
use Sentry\State\Scope;
1413
use Symfony\Component\HttpFoundation\Request;
@@ -18,7 +17,7 @@
1817
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1918
use Symfony\Component\Security\Core\User\UserInterface;
2019

21-
class RequestListenerTest extends TestCase
20+
class RequestListenerTest extends BaseTestCase
2221
{
2322
private $currentScope;
2423
private $currentHub;
@@ -48,7 +47,7 @@ protected function setUp()
4847
$callable($scope);
4948
});
5049

51-
SentrySdk::setCurrentHub($this->currentHub->reveal());
50+
$this->setCurrentHub($this->currentHub->reveal());
5251
}
5352

5453
/**

test/EventListener/SubRequestListenerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
namespace Sentry\SentryBundle\Test\EventListener;
44

5-
use PHPUnit\Framework\TestCase;
65
use Sentry\SentryBundle\EventListener\SubRequestListener;
7-
use Sentry\SentrySdk;
6+
use Sentry\SentryBundle\Test\BaseTestCase;
87
use Sentry\State\HubInterface;
98
use Sentry\State\Scope;
109
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
1110
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1211

13-
class SubRequestListenerTest extends TestCase
12+
class SubRequestListenerTest extends BaseTestCase
1413
{
1514
private $currentHub;
1615

@@ -20,7 +19,7 @@ protected function setUp()
2019

2120
$this->currentHub = $this->prophesize(HubInterface::class);
2221

23-
SentrySdk::setCurrentHub($this->currentHub->reveal());
22+
$this->setCurrentHub($this->currentHub->reveal());
2423
}
2524

2625
public function testOnKernelRequestWithMasterRequest(): void

0 commit comments

Comments
 (0)