diff --git a/CHANGELOG.md b/CHANGELOG.md index d43bb46e1..8dd862880 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # CHANGELOG ## Unreleased - -- ... +- Updated .gitattributes to reduce package footprint (#770) +- Use multibyte functions to handle unicode paths (#774) +- Remove `Hub::getScope()` to deny direct access to `Scope` instances (#776) ## 2.0.0-beta2 (2019-02-11) - Rename `SentryAuth` class to `SentryAuthentication` (#742) diff --git a/src/State/Hub.php b/src/State/Hub.php index 6811b8062..a37cb5f3a 100644 --- a/src/State/Hub.php +++ b/src/State/Hub.php @@ -52,14 +52,6 @@ public function getClient(): ?ClientInterface return $this->getStackTop()->getClient(); } - /** - * {@inheritdoc} - */ - public function getScope(): Scope - { - return $this->getStackTop()->getScope(); - } - /** * {@inheritdoc} */ @@ -242,6 +234,16 @@ public function getIntegration(string $className): ?IntegrationInterface return null; } + /** + * Gets the scope bound to the top of the stack. + * + * @return Scope + */ + private function getScope(): Scope + { + return $this->getStackTop()->getScope(); + } + /** * Gets the topmost client/layer pair in the stack. * diff --git a/src/State/HubInterface.php b/src/State/HubInterface.php index d2569b0b9..af13d62e6 100644 --- a/src/State/HubInterface.php +++ b/src/State/HubInterface.php @@ -23,13 +23,6 @@ interface HubInterface */ public function getClient(): ?ClientInterface; - /** - * Gets the scope bound to the top of the stack. - * - * @return Scope - */ - public function getScope(): Scope; - /** * Gets the ID of the last captured event. * diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 87b4672f5..07290a129 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -274,8 +274,13 @@ public function testHandlingExceptionThrowingAnException(): void $client = new Client(new Options(), $transport, $this->createEventFactory()); - Hub::getCurrent()->bindClient($client); - $client->captureException($this->createCarelessExceptionWithStacktrace(), Hub::getCurrent()->getScope()); + $hub = Hub::getCurrent(); + $hub->bindClient($client); + + $method = new \ReflectionMethod($hub, 'getScope'); + $method->setAccessible(true); + + $client->captureException($this->createCarelessExceptionWithStacktrace(), $method->invoke($hub)); } /** diff --git a/tests/SdkTest.php b/tests/SdkTest.php index 9f9b0b013..6d0f55e37 100644 --- a/tests/SdkTest.php +++ b/tests/SdkTest.php @@ -94,7 +94,12 @@ public function testAddBreadcrumb(): void addBreadcrumb($breadcrumb); - $this->assertSame([$breadcrumb], Hub::getCurrent()->getScope()->getBreadcrumbs()); + $hub = Hub::getCurrent(); + + $method = new \ReflectionMethod($hub, 'getScope'); + $method->setAccessible(true); + + $this->assertSame([$breadcrumb], $method->invoke($hub)->getBreadcrumbs()); } public function testWithScope(): void diff --git a/tests/State/HubTest.php b/tests/State/HubTest.php index 027f694c0..a95e73caf 100644 --- a/tests/State/HubTest.php +++ b/tests/State/HubTest.php @@ -11,6 +11,7 @@ use Sentry\ClientInterface; use Sentry\Severity; use Sentry\State\Hub; +use Sentry\State\HubInterface; use Sentry\State\Scope; final class HubTest extends TestCase @@ -19,7 +20,7 @@ public function testConstructorCreatesScopeAutomatically(): void { $hub = new Hub(null, null); - $this->assertNotNull($hub->getScope()); + $this->assertNotNull($this->getScope($hub)); } public function testGetClient(): void @@ -36,7 +37,7 @@ public function testGetScope(): void $scope = new Scope(); $hub = new Hub($this->createMock(ClientInterface::class), $scope); - $this->assertSame($scope, $hub->getScope()); + $this->assertSame($scope, $this->getScope($hub)); } public function testGetLastEventId(): void @@ -57,14 +58,14 @@ public function testPushScope(): void { $hub = new Hub($this->createMock(ClientInterface::class)); - $scope1 = $hub->getScope(); + $scope1 = $this->getScope($hub); $client1 = $hub->getClient(); $scope2 = $hub->pushScope(); $client2 = $hub->getClient(); $this->assertNotSame($scope1, $scope2); - $this->assertSame($scope2, $hub->getScope()); + $this->assertSame($scope2, $this->getScope($hub)); $this->assertSame($client1, $client2); $this->assertSame($client1, $hub->getClient()); } @@ -73,22 +74,22 @@ public function testPopScope(): void { $hub = new Hub($this->createMock(ClientInterface::class)); - $scope1 = $hub->getScope(); + $scope1 = $this->getScope($hub); $client = $hub->getClient(); $scope2 = $hub->pushScope(); - $this->assertSame($scope2, $hub->getScope()); + $this->assertSame($scope2, $this->getScope($hub)); $this->assertSame($client, $hub->getClient()); $this->assertTrue($hub->popScope()); - $this->assertSame($scope1, $hub->getScope()); + $this->assertSame($scope1, $this->getScope($hub)); $this->assertSame($client, $hub->getClient()); $this->assertFalse($hub->popScope()); - $this->assertSame($scope1, $hub->getScope()); + $this->assertSame($scope1, $this->getScope($hub)); $this->assertSame($client, $hub->getClient()); } @@ -97,7 +98,7 @@ public function testWithScope(): void $scope = new Scope(); $hub = new Hub($this->createMock(ClientInterface::class), $scope); - $this->assertSame($scope, $hub->getScope()); + $this->assertSame($scope, $this->getScope($hub)); $callbackInvoked = false; @@ -116,7 +117,7 @@ public function testWithScope(): void } $this->assertTrue($callbackInvoked); - $this->assertSame($scope, $hub->getScope()); + $this->assertSame($scope, $this->getScope($hub)); } public function testConfigureScope(): void @@ -134,7 +135,7 @@ public function testConfigureScope(): void }); $this->assertTrue($callbackInvoked); - $this->assertSame($scope, $hub->getScope()); + $this->assertSame($scope, $this->getScope($hub)); } public function testBindClient(): void @@ -217,7 +218,7 @@ public function testAddBreadcrumb(): void $hub->addBreadcrumb($breadcrumb); - $this->assertSame([$breadcrumb], $hub->getScope()->getBreadcrumbs()); + $this->assertSame([$breadcrumb], $this->getScope($hub)->getBreadcrumbs()); } public function testAddBreadcrumbDoesNothingIfMaxBreadcrumbsLimitIsZero(): void @@ -227,14 +228,14 @@ public function testAddBreadcrumbDoesNothingIfMaxBreadcrumbsLimitIsZero(): void $hub->addBreadcrumb(new Breadcrumb(Breadcrumb::LEVEL_ERROR, Breadcrumb::TYPE_ERROR, 'error_reporting')); - $this->assertEmpty($hub->getScope()->getBreadcrumbs()); + $this->assertEmpty($this->getScope($hub)->getBreadcrumbs()); } public function testAddBreadcrumbRespectsMaxBreadcrumbsLimit(): void { $client = ClientBuilder::create(['max_breadcrumbs' => 2])->getClient(); $hub = new Hub($client); - $scope = $hub->getScope(); + $scope = $this->getScope($hub); $breadcrumb1 = new Breadcrumb(Breadcrumb::LEVEL_WARNING, Breadcrumb::TYPE_ERROR, 'error_reporting', 'foo'); $breadcrumb2 = new Breadcrumb(Breadcrumb::LEVEL_WARNING, Breadcrumb::TYPE_ERROR, 'error_reporting', 'bar'); @@ -260,7 +261,7 @@ public function testAddBreadcrumbDoesNothingWhenBeforeBreadcrumbCallbackReturnsN $hub->addBreadcrumb(new Breadcrumb(Breadcrumb::LEVEL_ERROR, Breadcrumb::TYPE_ERROR, 'error_reporting')); - $this->assertEmpty($hub->getScope()->getBreadcrumbs()); + $this->assertEmpty($this->getScope($hub)->getBreadcrumbs()); } public function testAddBreadcrumbStoresBreadcrumbReturnedByBeforeBreadcrumbCallback(): void @@ -276,7 +277,7 @@ public function testAddBreadcrumbStoresBreadcrumbReturnedByBeforeBreadcrumbCallb $hub->addBreadcrumb($breadcrumb1); - $this->assertSame([$breadcrumb2], $hub->getScope()->getBreadcrumbs()); + $this->assertSame([$breadcrumb2], $this->getScope($hub)->getBreadcrumbs()); } public function testCaptureEvent(): void @@ -292,4 +293,12 @@ public function testCaptureEvent(): void $this->assertEquals('2b867534eead412cbdb882fd5d441690', $hub->captureEvent(['message' => 'test'])); } + + private function getScope(HubInterface $hub): Scope + { + $method = new \ReflectionMethod($hub, 'getScope'); + $method->setAccessible(true); + + return $method->invoke($hub); + } }