diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index e3d163282..6e3984c91 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -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 @@ -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()); @@ -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 { diff --git a/tests/Integration/EnvironmentIntegrationTest.php b/tests/Integration/EnvironmentIntegrationTest.php index 788b95fa8..7391acbce 100644 --- a/tests/Integration/EnvironmentIntegrationTest.php +++ b/tests/Integration/EnvironmentIntegrationTest.php @@ -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(); diff --git a/tests/Integration/FrameContextifierIntegrationTest.php b/tests/Integration/FrameContextifierIntegrationTest.php index 5667826b0..f13ba8e7d 100644 --- a/tests/Integration/FrameContextifierIntegrationTest.php +++ b/tests/Integration/FrameContextifierIntegrationTest.php @@ -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), @@ -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), diff --git a/tests/Integration/ModulesIntegrationTest.php b/tests/Integration/ModulesIntegrationTest.php index 52b96c9d3..659a50398 100644 --- a/tests/Integration/ModulesIntegrationTest.php +++ b/tests/Integration/ModulesIntegrationTest.php @@ -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()); @@ -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()); } diff --git a/tests/Integration/OTLPIntegrationTest.php b/tests/Integration/OTLPIntegrationTest.php index 27f4807b8..b8ef7ce13 100644 --- a/tests/Integration/OTLPIntegrationTest.php +++ b/tests/Integration/OTLPIntegrationTest.php @@ -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; @@ -115,7 +114,7 @@ public function testSetupOnceRegistersExternalPropagationContext(): void ->willReturn($integration); try { - SentrySdk::setCurrentHub(new Hub($client)); + SentrySdk::init($client); $this->assertSame([ 'trace_id' => '771a43a4192642f0b136d5159a501700', @@ -146,7 +145,7 @@ public function testExternalPropagationContextIsIgnoredWhenCurrentClientDoesNotH ->willReturn(null); try { - SentrySdk::setCurrentHub(new Hub($client)); + SentrySdk::init($client); $this->assertNull(Scope::getExternalPropagationContext()); } finally { diff --git a/tests/Integration/RequestIntegrationTest.php b/tests/Integration/RequestIntegrationTest.php index 66749155a..c08cc3e1c 100644 --- a/tests/Integration/RequestIntegrationTest.php +++ b/tests/Integration/RequestIntegrationTest.php @@ -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); diff --git a/tests/Integration/TransactionIntegrationTest.php b/tests/Integration/TransactionIntegrationTest.php index ab46c6a1b..1faf42176 100644 --- a/tests/Integration/TransactionIntegrationTest.php +++ b/tests/Integration/TransactionIntegrationTest.php @@ -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); diff --git a/tests/Logs/LogsAggregatorTest.php b/tests/Logs/LogsAggregatorTest.php index b604f54db..a62d0bd47 100644 --- a/tests/Logs/LogsAggregatorTest.php +++ b/tests/Logs/LogsAggregatorTest.php @@ -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; @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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'); @@ -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(); @@ -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'); @@ -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(); @@ -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(); @@ -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 [ diff --git a/tests/Logs/LogsTest.php b/tests/Logs/LogsTest.php index 4dd361b56..a0a4053b3 100644 --- a/tests/Logs/LogsTest.php +++ b/tests/Logs/LogsTest.php @@ -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; @@ -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'); @@ -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; } diff --git a/tests/Metrics/TraceMetricsTest.php b/tests/Metrics/TraceMetricsTest.php index 3d77e3706..6903c37c3 100644 --- a/tests/Metrics/TraceMetricsTest.php +++ b/tests/Metrics/TraceMetricsTest.php @@ -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; @@ -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 = []; } @@ -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())); @@ -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())); @@ -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); @@ -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())); @@ -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())); @@ -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); diff --git a/tests/Monolog/LogsHandlerTest.php b/tests/Monolog/LogsHandlerTest.php index f3f2965cc..0d94c6800 100644 --- a/tests/Monolog/LogsHandlerTest.php +++ b/tests/Monolog/LogsHandlerTest.php @@ -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 @@ -28,8 +27,7 @@ protected function setUp(): void }, ])->getClient(); - $hub = new Hub($client); - SentrySdk::setCurrentHub($hub); + SentrySdk::init($client); } /** @@ -108,8 +106,7 @@ public function testLogsHandlerDestructor(): void ])->setTransport($transport) ->getClient(); - $hub = new Hub($client); - SentrySdk::setCurrentHub($hub); + SentrySdk::init($client); $this->handleLogAndDrop(); diff --git a/tests/SentrySdkTest.php b/tests/SentrySdkTest.php index c439159ef..dcb705292 100644 --- a/tests/SentrySdkTest.php +++ b/tests/SentrySdkTest.php @@ -12,12 +12,14 @@ use Sentry\Options; use Sentry\SentrySdk; use Sentry\State\Hub; -use Sentry\State\Scope; use Sentry\Tracing\Span; use Sentry\Tracing\SpanContext; +use Sentry\Tracing\TransactionContext; use Sentry\Transport\Result; use Sentry\Transport\ResultStatus; +use function Sentry\startTransaction; + final class SentrySdkTest extends TestCase { public function testInit(): void @@ -133,23 +135,16 @@ public function testStartAndEndContextIsolateScopeData(): void { SentrySdk::init(); - SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope): void { - $scope->setTag('baseline', 'yes'); - }); + SentrySdk::getIsolationScope()->setTag('baseline', 'yes'); SentrySdk::startContext(); - SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope): void { - $scope->setTag('request', 'yes'); - }); + SentrySdk::getIsolationScope()->setTag('request', 'yes'); SentrySdk::endContext(); $event = Event::createEvent(); - - SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope) use (&$event): void { - $event = $scope->applyToEvent($event); - }); + $event = SentrySdk::getIsolationScope()->applyToEvent($event); $this->assertArrayHasKey('baseline', $event->getTags()); $this->assertArrayNotHasKey('request', $event->getTags()); @@ -160,16 +155,15 @@ public function testStartContextDoesNotInheritBaselineSpan(): void SentrySdk::init(); $baselineSpan = new Span(new SpanContext()); - SentrySdk::getCurrentHub()->setSpan($baselineSpan); + SentrySdk::getIsolationScope()->setSpan($baselineSpan); SentrySdk::startContext(); - $contextHub = SentrySdk::getCurrentHub(); - $this->assertNull($contextHub->getSpan()); + $this->assertNull(SentrySdk::getIsolationScope()->getSpan()); SentrySdk::endContext(); - $this->assertSame($baselineSpan, SentrySdk::getCurrentHub()->getSpan()); + $this->assertSame($baselineSpan, SentrySdk::getIsolationScope()->getSpan()); } public function testStartContextCreatesFreshPropagationContext(): void @@ -195,16 +189,16 @@ public function testWithContextResetsSpanAndTransactionAcrossInvocations(): void SentrySdk::init(); SentrySdk::withContext(function (): void { - $transaction = SentrySdk::getCurrentHub()->startTransaction(new \Sentry\Tracing\TransactionContext('request-1')); - SentrySdk::getCurrentHub()->setSpan($transaction); + $transaction = startTransaction(new TransactionContext('request-1')); + SentrySdk::getIsolationScope()->setSpan($transaction); - $this->assertSame($transaction, SentrySdk::getCurrentHub()->getSpan()); - $this->assertSame($transaction, SentrySdk::getCurrentHub()->getTransaction()); + $this->assertSame($transaction, SentrySdk::getIsolationScope()->getSpan()); + $this->assertSame($transaction, SentrySdk::getIsolationScope()->getTransaction()); }); SentrySdk::withContext(function (): void { - $this->assertNull(SentrySdk::getCurrentHub()->getSpan()); - $this->assertNull(SentrySdk::getCurrentHub()->getTransaction()); + $this->assertNull(SentrySdk::getIsolationScope()->getSpan()); + $this->assertNull(SentrySdk::getIsolationScope()->getTransaction()); }); } @@ -242,7 +236,7 @@ public function testEndContextFlushesClientTransportWithOptionalTimeout(): void ->with(12) ->willReturn(new Result(ResultStatus::success())); - SentrySdk::init()->bindClient($client); + SentrySdk::init($client); SentrySdk::startContext(); SentrySdk::endContext(12); @@ -257,7 +251,7 @@ public function testFlushFlushesClientTransport(): void ->with(null) ->willReturn(new Result(ResultStatus::success())); - SentrySdk::init()->bindClient($client); + SentrySdk::init($client); SentrySdk::flush(); } @@ -295,9 +289,7 @@ public function testNestedWithContextReusesOuterContext(): void $outerScope = SentrySdk::getIsolationScope(); $outerContextId = SentrySdk::getCurrentRuntimeContext()->getId(); - SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope): void { - $scope->setTag('outer', 'yes'); - }); + SentrySdk::getIsolationScope()->setTag('outer', 'yes'); SentrySdk::withContext(static function () use (&$innerScope, &$innerContextId): void { $innerScope = SentrySdk::getIsolationScope(); @@ -306,9 +298,7 @@ public function testNestedWithContextReusesOuterContext(): void $event = Event::createEvent(); - SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope) use (&$event): void { - $event = $scope->applyToEvent($event); - }); + $event = SentrySdk::getIsolationScope()->applyToEvent($event); $this->assertNotSame($globalScope, SentrySdk::getIsolationScope()); $this->assertSame('yes', $event->getTags()['outer'] ?? null); @@ -352,9 +342,7 @@ private function getCurrentScopeTraceparent(): string { $traceparent = ''; - SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope) use (&$traceparent): void { - $traceparent = $scope->getPropagationContext()->toTraceparent(); - }); + $traceparent = SentrySdk::getIsolationScope()->getPropagationContext()->toTraceparent(); return $traceparent; } diff --git a/tests/Tracing/StrictTraceContinuationTest.php b/tests/Tracing/StrictTraceContinuationTest.php index 6de0a3a96..88440b5da 100644 --- a/tests/Tracing/StrictTraceContinuationTest.php +++ b/tests/Tracing/StrictTraceContinuationTest.php @@ -8,7 +8,6 @@ use Sentry\ClientInterface; use Sentry\Options; use Sentry\SentrySdk; -use Sentry\State\Hub; use Sentry\Tracing\PropagationContext; use Sentry\Tracing\TransactionContext; @@ -26,7 +25,7 @@ public function testPropagationContext(Options $options, string $baggage, bool $ ->method('getOptions') ->willReturn($options); - SentrySdk::setCurrentHub(new Hub($client)); + SentrySdk::init($client); $contexts = [ PropagationContext::fromHeaders(self::SENTRY_TRACE_HEADER, $baggage), @@ -56,7 +55,7 @@ public function testTransactionContext(Options $options, string $baggage, bool $ ->method('getOptions') ->willReturn($options); - SentrySdk::setCurrentHub(new Hub($client)); + SentrySdk::init($client); $contexts = [ TransactionContext::fromHeaders(self::SENTRY_TRACE_HEADER, $baggage), diff --git a/tests/Tracing/TransactionContextTest.php b/tests/Tracing/TransactionContextTest.php index 678d8d897..9d2b3dd61 100644 --- a/tests/Tracing/TransactionContextTest.php +++ b/tests/Tracing/TransactionContextTest.php @@ -10,7 +10,6 @@ use Sentry\NoOpClient; use Sentry\Options; use Sentry\SentrySdk; -use Sentry\State\Hub; use Sentry\Tracing\DynamicSamplingContext; use Sentry\Tracing\SpanId; use Sentry\Tracing\TraceId; @@ -182,7 +181,7 @@ public function testInvalidSampleRandIsLogged(): void $client->method('getOptions') ->willReturn(new Options(['logger' => $logger])); - SentrySdk::setCurrentHub(new Hub($client)); + SentrySdk::init($client); try { TransactionContext::fromHeaders( @@ -190,7 +189,7 @@ public function testInvalidSampleRandIsLogged(): void 'sentry-sample_rand=-1.0' ); } finally { - SentrySdk::setCurrentHub(new Hub(new NoOpClient())); + SentrySdk::init(new NoOpClient()); } } diff --git a/tests/Tracing/TransactionTest.php b/tests/Tracing/TransactionTest.php index 82a767bd3..bf77563f2 100644 --- a/tests/Tracing/TransactionTest.php +++ b/tests/Tracing/TransactionTest.php @@ -11,13 +11,14 @@ use Sentry\EventType; use Sentry\Options; use Sentry\SentrySdk; -use Sentry\State\Hub; use Sentry\State\Scope; use Sentry\Tests\TestUtil\ClockMock; use Sentry\Tracing\SpanContext; use Sentry\Tracing\Transaction; use Sentry\Tracing\TransactionContext; +use function Sentry\startTransaction; + /** * @group time-sensitive */ @@ -112,7 +113,9 @@ public function testTransactionIsSampledCorrectlyWhenTracingIsSetToZeroInOptions ]) ); - $transaction = (new Hub($client))->startTransaction($context); + SentrySdk::init($client); + + $transaction = startTransaction($context); $this->assertSame($expectedSampled, $transaction->getSampled()); } @@ -155,7 +158,9 @@ public function testTransactionIsNotSampledWhenTracingIsDisabledInOptions(Transa ]) ); - $transaction = (new Hub($client))->startTransaction($context); + SentrySdk::init($client); + + $transaction = startTransaction($context); $this->assertSame($expectedSampled, $transaction->getSampled()); } diff --git a/tests/phpt-oom/php84/out_of_memory_fatal_error_increases_memory_limit.phpt b/tests/phpt-oom/php84/out_of_memory_fatal_error_increases_memory_limit.phpt index 35a32c838..47364f873 100644 --- a/tests/phpt-oom/php84/out_of_memory_fatal_error_increases_memory_limit.phpt +++ b/tests/phpt-oom/php84/out_of_memory_fatal_error_increases_memory_limit.phpt @@ -65,7 +65,7 @@ $options->setTransport($transport); $client = (new ClientBuilder($options))->getClient(); -SentrySdk::init()->bindClient($client); +SentrySdk::init($client); echo 'Before OOM memory limit: ' . \ini_get('memory_limit'); diff --git a/tests/phpt-oom/php85/out_of_memory_fatal_error_increases_memory_limit.phpt b/tests/phpt-oom/php85/out_of_memory_fatal_error_increases_memory_limit.phpt index a547854da..544929924 100644 --- a/tests/phpt-oom/php85/out_of_memory_fatal_error_increases_memory_limit.phpt +++ b/tests/phpt-oom/php85/out_of_memory_fatal_error_increases_memory_limit.phpt @@ -65,7 +65,7 @@ $options->setTransport($transport); $client = (new ClientBuilder($options))->getClient(); -SentrySdk::init()->bindClient($client); +SentrySdk::init($client); echo 'Before OOM memory limit: ' . \ini_get('memory_limit'); diff --git a/tests/phpt/test_callable_serialization.phpt b/tests/phpt/test_callable_serialization.phpt index ff5a2d79e..4806cf053 100644 --- a/tests/phpt/test_callable_serialization.phpt +++ b/tests/phpt/test_callable_serialization.phpt @@ -19,6 +19,8 @@ use Sentry\Transport\Result; use Sentry\Transport\ResultStatus; use Sentry\Transport\TransportInterface; +use function Sentry\captureException; + $vendor = __DIR__; while (!file_exists($vendor . '/vendor')) { @@ -51,11 +53,11 @@ $client = ClientBuilder::create($options) ->setTransport($transport) ->getClient(); -SentrySdk::getCurrentHub()->bindClient($client); +SentrySdk::init($client); class Foo { function __construct(string $bar) { - SentrySdk::getCurrentHub()->captureException(new Exception('doh!')); + captureException(new Exception('doh!')); } }