Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ public function testInit(): void
{
init(['default_integrations' => false]);

$this->assertNotNull(SentrySdk::getCurrentHub()->getClient());
$this->assertSame(SentrySdk::getCurrentHub()->getClient(), SentrySdk::getClient());
$client = SentrySdk::getClient();

$this->assertNotInstanceOf(NoOpClient::class, $client);
$this->assertSame($client, SentrySdk::getGlobalScope()->getClient());
}

public function testInitPreservesGlobalScope(): void
Expand All @@ -70,7 +72,7 @@ public function testInitPreservesGlobalScope(): void
init(['default_integrations' => false]);

$this->assertSame($globalScope, SentrySdk::getGlobalScope());
$this->assertSame(SentrySdk::getCurrentHub()->getClient(), $globalScope->getClient());
$this->assertSame(SentrySdk::getClient(), $globalScope->getClient());

$event = $globalScope->applyToEvent(Event::createEvent());

Expand Down Expand Up @@ -655,7 +657,7 @@ public function testWithContextAlwaysEndsContextWithOptionalTimeout(): void
->with(13)
->willReturn(new Result(ResultStatus::success()));

SentrySdk::init()->bindClient($client);
SentrySdk::init($client);

try {
withContext(static function (): void {
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/EnvironmentIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testInvoke(bool $isIntegrationEnabled, ?RuntimeContext $initialR
->method('getIntegration')
->willReturn($isIntegrationEnabled ? $integration : null);

SentrySdk::getCurrentHub()->bindClient($client);
SentrySdk::init($client);

withScope(function (Scope $scope) use ($expectedRuntimeContext, $expectedOsContext, $initialRuntimeContext, $initialOsContext): void {
$event = Event::createEvent();
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/FrameContextifierIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testInvoke(string $fixtureFilePath, int $lineNumber, int $contex
->method('getOptions')
->willReturn($options);

SentrySdk::getCurrentHub()->bindClient($client);
SentrySdk::init($client);

$stacktrace = new Stacktrace([
new Frame('[unknown]', $fixtureFilePath, $lineNumber, null, $fixtureFilePath),
Expand Down Expand Up @@ -133,7 +133,7 @@ public function testInvokeLogsWarningMessageIfSourceCodeExcerptCannotBeRetrieved
->method('getOptions')
->willReturn($options);

SentrySdk::getCurrentHub()->bindClient($client);
SentrySdk::init($client);

$stacktrace = new Stacktrace([
new Frame(null, '[internal]', 0),
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/ModulesIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testInvoke(bool $isIntegrationEnabled, bool $expectedEmptyModule
->method('getIntegration')
->willReturn($isIntegrationEnabled ? $integration : null);

SentrySdk::getCurrentHub()->bindClient($client);
SentrySdk::init($client);

withScope(function (Scope $scope) use ($expectedEmptyModules): void {
$event = $scope->applyToEvent(Event::createEvent());
Expand Down Expand Up @@ -86,7 +86,7 @@ public function testModuleIntegration(): void
->setTransport($transport)
->getClient();

SentrySdk::getCurrentHub()->bindClient($client);
SentrySdk::init($client);

$client->captureEvent(Event::createEvent(), null, new Scope());
}
Expand Down
5 changes: 2 additions & 3 deletions tests/Integration/OTLPIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Sentry\Integration\OTLPIntegration;
use Sentry\Options;
use Sentry\SentrySdk;
use Sentry\State\Hub;
use Sentry\State\Scope;
use Sentry\Tests\Fixtures\OpenTelemetry\StubOtelHttpClient;
use Sentry\Tests\Fixtures\OpenTelemetry\TestClientDiscoverer;
Expand Down Expand Up @@ -115,7 +114,7 @@ public function testSetupOnceRegistersExternalPropagationContext(): void
->willReturn($integration);

try {
SentrySdk::setCurrentHub(new Hub($client));
SentrySdk::init($client);

$this->assertSame([
'trace_id' => '771a43a4192642f0b136d5159a501700',
Expand Down Expand Up @@ -146,7 +145,7 @@ public function testExternalPropagationContextIsIgnoredWhenCurrentClientDoesNotH
->willReturn(null);

try {
SentrySdk::setCurrentHub(new Hub($client));
SentrySdk::init($client);

$this->assertNull(Scope::getExternalPropagationContext());
} finally {
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/RequestIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testInvoke(array $options, ServerRequestInterface $request, arra
->method('getOptions')
->willReturn(new Options($options));

SentrySdk::getCurrentHub()->bindClient($client);
SentrySdk::init($client);

withScope(function (Scope $scope) use ($event, $expectedRequestContextData, $expectedUser): void {
$event = $scope->applyToEvent($event);
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/TransactionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testSetupOnce(Event $event, bool $isIntegrationEnabled, ?EventHi
->method('getIntegration')
->willReturn($isIntegrationEnabled ? $integration : null);

SentrySdk::getCurrentHub()->bindClient($client);
SentrySdk::init($client);

withScope(function (Scope $scope) use ($event, $hint, $expectedTransaction): void {
$event = $scope->applyToEvent($event, $hint);
Expand Down
52 changes: 21 additions & 31 deletions tests/Logs/LogsAggregatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Sentry\Logs\LogsAggregator;
use Sentry\Options;
use Sentry\SentrySdk;
use Sentry\State\Hub;
use Sentry\State\Scope;
use Sentry\Tests\StubTransport;
use Sentry\Tracing\PropagationContext;
Expand All @@ -38,8 +37,7 @@ public function testAttributes(array $attributes, array $expected): void
'enable_logs' => true,
])->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
SentrySdk::init($client);

$aggregator = new LogsAggregator();

Expand Down Expand Up @@ -96,8 +94,7 @@ public function testMessageFormatting(string $message, array $values, string $ex
'enable_logs' => true,
])->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
SentrySdk::init($client);

$aggregator = new LogsAggregator();

Expand Down Expand Up @@ -173,21 +170,19 @@ public function testAttributesAreAddedToLogMessage(): void
'server_name' => 'web-server-01',
])->getClient();

SentrySdk::setCurrentHub(new Hub($client));
SentrySdk::init($client);

SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope) {
$userDataBag = new UserDataBag();
$userDataBag->setId('unique_id');
$userDataBag->setEmail('foo@example.com');
$userDataBag->setUsername('my_user');
$scope->setUser($userDataBag);
});
$userDataBag = new UserDataBag();
$userDataBag->setId('unique_id');
$userDataBag->setEmail('foo@example.com');
$userDataBag->setUsername('my_user');
SentrySdk::getIsolationScope()->setUser($userDataBag);

$spanContext = new SpanContext();
$spanContext->setTraceId(new TraceId('566e3688a61d4bc888951642d6f14a19'));
$spanContext->setSpanId(new SpanId('566e3688a61d4bc8'));
$span = new Span($spanContext);
SentrySdk::getCurrentHub()->setSpan($span);
SentrySdk::getIsolationScope()->setSpan($span);

$aggregator = new LogsAggregator();

Expand Down Expand Up @@ -219,7 +214,7 @@ public function testMergedScopeAttributesAreAddedToLogMessage(): void
'enable_logs' => true,
])->getClient();

SentrySdk::getGlobalScope()->setClient($client);
SentrySdk::init($client);
SentrySdk::getGlobalScope()->setUser(UserDataBag::createFromUserIdentifier('global-user'));

$spanContext = new SpanContext();
Expand All @@ -245,15 +240,13 @@ public function testUserAttributesCanBeSetManuallyWithDefaultPiiOff(): void
'send_default_pii' => false,
])->getClient();

SentrySdk::setCurrentHub(new Hub($client));
SentrySdk::init($client);

SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope) {
$userDataBag = new UserDataBag();
$userDataBag->setId('unique_id');
$userDataBag->setEmail('foo@example.com');
$userDataBag->setUsername('my_user');
$scope->setUser($userDataBag);
});
$userDataBag = new UserDataBag();
$userDataBag->setId('unique_id');
$userDataBag->setEmail('foo@example.com');
$userDataBag->setUsername('my_user');
SentrySdk::getIsolationScope()->setUser($userDataBag);

$aggregator = new LogsAggregator();
$aggregator->add(LogLevel::info(), 'User performed action');
Expand All @@ -278,8 +271,7 @@ public function testFlushesImmediatelyWhenThresholdIsReached(): void
'log_flush_threshold' => 2,
])->setTransport($transport)->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
SentrySdk::init($client);

$aggregator = new LogsAggregator();

Expand Down Expand Up @@ -312,7 +304,7 @@ public function testFlushCapturesLogsWithProvidedClient(): void
]));
$fallbackClient->expects($this->never())
->method('captureEvent');
SentrySdk::setCurrentHub(new Hub($fallbackClient));
SentrySdk::init($fallbackClient);

$aggregator = new LogsAggregator();
$aggregator->add(LogLevel::info(), 'Test message');
Expand Down Expand Up @@ -340,8 +332,7 @@ public function testDoesNotFlushImmediatelyWhenThresholdIsNull(): void
'log_flush_threshold' => null,
])->setTransport($transport)->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
SentrySdk::init($client);

$aggregator = new LogsAggregator();

Expand All @@ -362,7 +353,7 @@ public function testDoesNotUsePropagationContextSpanIdAsParentSpanIdWhenNoLocalS
$propagationContext->setTraceId(new TraceId('771a43a4192642f0b136d5159a501700'));
$propagationContext->setSpanId(new SpanId('1234567890abcdef'));

SentrySdk::setCurrentHub(new Hub($client));
SentrySdk::init($client);
SentrySdk::getCurrentRuntimeContext()->setIsolationScope(new Scope($propagationContext));

$aggregator = new LogsAggregator();
Expand All @@ -384,8 +375,7 @@ public function testUsesExternalPropagationContextWhenNoLocalSpanExists(): void
'enable_logs' => true,
])->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
SentrySdk::init($client);

Scope::registerExternalPropagationContext(static function (): array {
return [
Expand Down
7 changes: 2 additions & 5 deletions tests/Logs/LogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Sentry\Logs\LogLevel;
use Sentry\Options;
use Sentry\SentrySdk;
use Sentry\State\Hub;
use Sentry\Transport\Result;
use Sentry\Transport\ResultStatus;
use Sentry\Transport\TransportInterface;
Expand All @@ -36,8 +35,7 @@ public function testLogNotSentWhenDisabled(): void
$client->expects($this->never())
->method('captureEvent');

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
SentrySdk::init($client);

logger()->info('Some info message');

Expand Down Expand Up @@ -186,8 +184,7 @@ private function assertEvent(callable $assert, array $options = []): ClientInter

$client = ClientBuilder::create($clientOptions)->setTransport($transport)->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
SentrySdk::init($client);

return $client;
}
Expand Down
16 changes: 7 additions & 9 deletions tests/Metrics/TraceMetricsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use Sentry\Metrics\Types\Metric;
use Sentry\Options;
use Sentry\SentrySdk;
use Sentry\State\Hub;
use Sentry\State\HubAdapter;
use Sentry\State\Scope;
use Sentry\UserDataBag;

Expand All @@ -26,7 +24,7 @@ final class TraceMetricsTest extends TestCase
{
protected function setUp(): void
{
HubAdapter::getInstance()->bindClient(new Client(new Options(), StubTransport::getInstance()));
SentrySdk::init(new Client(new Options(), StubTransport::getInstance()));
StubTransport::$events = [];
}

Expand Down Expand Up @@ -80,7 +78,7 @@ public function testDistributionMetrics(): void

public function testFlushesImmediatelyWhenMetricFlushThresholdIsReached(): void
{
HubAdapter::getInstance()->bindClient(new Client(new Options([
SentrySdk::init(new Client(new Options([
'metric_flush_threshold' => 2,
]), StubTransport::getInstance()));

Expand All @@ -100,7 +98,7 @@ public function testFlushesImmediatelyWhenMetricFlushThresholdIsReached(): void

public function testDoesNotFlushImmediatelyWhenMetricFlushThresholdIsNull(): void
{
HubAdapter::getInstance()->bindClient(new Client(new Options([
SentrySdk::init(new Client(new Options([
'metric_flush_threshold' => null,
]), StubTransport::getInstance()));

Expand Down Expand Up @@ -143,7 +141,7 @@ public function testFlushCapturesMetricsWithProvidedClient(): void
]));
$fallbackClient->expects($this->never())
->method('captureEvent');
SentrySdk::setCurrentHub(new Hub($fallbackClient));
SentrySdk::init($fallbackClient);

$aggregator = new MetricsAggregator();
$aggregator->add(CounterMetric::TYPE, 'test-count', 2, ['foo' => 'bar'], null);
Expand All @@ -163,7 +161,7 @@ public function testFlushCapturesMetricsWithProvidedClient(): void

public function testMetricsBufferFullWhenMetricFlushThresholdIsNull(): void
{
HubAdapter::getInstance()->bindClient(new Client(new Options([
SentrySdk::init(new Client(new Options([
'metric_flush_threshold' => null,
]), StubTransport::getInstance()));

Expand All @@ -182,7 +180,7 @@ public function testMetricsBufferFullWhenMetricFlushThresholdIsNull(): void

public function testEnableMetrics(): void
{
HubAdapter::getInstance()->bindClient(new Client(new Options([
SentrySdk::init(new Client(new Options([
'enable_metrics' => false,
]), StubTransport::getInstance()));

Expand All @@ -194,7 +192,7 @@ public function testEnableMetrics(): void

public function testBeforeSendMetricAltersContent(): void
{
HubAdapter::getInstance()->bindClient(new Client(new Options([
SentrySdk::init(new Client(new Options([
'before_send_metric' => static function (Metric $metric) {
$metric->setValue(99999);

Expand Down
7 changes: 2 additions & 5 deletions tests/Monolog/LogsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Sentry\Logs\Logs;
use Sentry\Monolog\LogsHandler;
use Sentry\SentrySdk;
use Sentry\State\Hub;
use Sentry\Tests\StubTransport;

final class LogsHandlerTest extends TestCase
Expand All @@ -28,8 +27,7 @@ protected function setUp(): void
},
])->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
SentrySdk::init($client);
}

/**
Expand Down Expand Up @@ -108,8 +106,7 @@ public function testLogsHandlerDestructor(): void
])->setTransport($transport)
->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
SentrySdk::init($client);

$this->handleLogAndDrop();

Expand Down
Loading