diff --git a/Tests/Unit/Integration/NetlogixIntegrationTest.php b/Tests/Unit/Integration/NetlogixIntegrationTest.php index 2fffafd..67fc8df 100644 --- a/Tests/Unit/Integration/NetlogixIntegrationTest.php +++ b/Tests/Unit/Integration/NetlogixIntegrationTest.php @@ -12,6 +12,7 @@ use Netlogix\Sentry\Integration\NetlogixIntegration; use Netlogix\Sentry\LoggingRule\ExceptionHandlerRenderingGroupsRule; use Netlogix\Sentry\Scope\ScopeProvider; +use PHPUnit\Framework\MockObject\MockBuilder; use Sentry\Event; use Sentry\EventHint; use Sentry\UserDataBag; @@ -135,7 +136,7 @@ public function Event_is_logged_when_no_rules_are_defined(): void self::assertSame($event, NetlogixIntegration::handleEvent($event, $hint)); } - public function provideExceptionLoggingExpectations(): iterable + public static function provideExceptionLoggingExpectations(): iterable { yield 'If ruleResult is false, null is returned' => [ 'ruleResult' => false, @@ -157,7 +158,7 @@ public function Event_is_enriched_with_ScopeProvider_data(): void ->getMock(); $scopeProvider = $this->getMockBuilder(ScopeProvider::class) - ->setMethods( + ->{method_exists(MockBuilder::class, 'onlyMethods') ? 'onlyMethods' : 'setMethods'}( [ 'collectEnvironment', 'collectExtra', diff --git a/Tests/Unit/Scope/ClosureLike.php b/Tests/Unit/Scope/ClosureLike.php new file mode 100644 index 0000000..1fabfb5 --- /dev/null +++ b/Tests/Unit/Scope/ClosureLike.php @@ -0,0 +1,12 @@ +getEnvironment()); } - public function provideEmptyEnvironments(): iterable + public static function provideEmptyEnvironments(): iterable { yield 'Empty String' => ['environment' => '']; yield 'NULL' => ['environment' => null]; diff --git a/Tests/Unit/Scope/Release/FlowSettingsTest.php b/Tests/Unit/Scope/Release/FlowSettingsTest.php index e0dcd12..83dc0e6 100644 --- a/Tests/Unit/Scope/Release/FlowSettingsTest.php +++ b/Tests/Unit/Scope/Release/FlowSettingsTest.php @@ -51,7 +51,7 @@ public function empty_releases_are_converted_to_null($release): void self::assertNull($flowSettings->getRelease()); } - public function provideEmptyReleases(): iterable + public static function provideEmptyReleases(): iterable { yield 'Empty String' => ['release' => '']; yield 'NULL' => ['release' => null]; diff --git a/Tests/Unit/Scope/ScopeProviderTest.php b/Tests/Unit/Scope/ScopeProviderTest.php index 75c74de..422f097 100644 --- a/Tests/Unit/Scope/ScopeProviderTest.php +++ b/Tests/Unit/Scope/ScopeProviderTest.php @@ -13,6 +13,7 @@ use Netlogix\Sentry\Scope\ScopeProvider; use Netlogix\Sentry\Scope\Tags\TagProvider; use Netlogix\Sentry\Scope\User\UserProvider; +use PHPUnit\Framework\MockObject\MockBuilder; use stdClass; class ScopeProviderTest extends UnitTestCase @@ -54,7 +55,6 @@ public function providers_are_sorted_according_to_settings(): void $this->objectManagerMock ->expects(self::exactly(2)) ->method('get') - ->withConsecutive(['ExtraMock1'], ['ExtraMock2']) ->willReturnOnConsecutiveCalls($extra1, $extra2); $this->provider->injectSettings([ @@ -138,79 +138,110 @@ public function providers_must_be_of_the_correct_type(string $scope, object $pro $this->provider->initializeObject(); } - public function provideInvalidProviderTypes(): iterable + public static function provideInvalidProviderTypes(): iterable { + $extraProvider = new class implements ExtraProvider { + public function getExtra(): array + { + return []; + } + }; + $releaseProvider = new class implements ReleaseProvider { + public function getRelease(): ?string + { + return ''; + } + }; + $tagProvider = new class implements TagProvider { + public function getTags(): array + { + return []; + } + }; + $userProvider = new class implements UserProvider { + public function getUser(): array + { + return []; + } + }; + $environmentProvider = new class implements EnvironmentProvider { + public function getEnvironment(): ?string + { + return ''; + } + }; + yield 'environment stdClass' => ['scope' => 'environment', 'provider' => new stdClass()]; yield 'environment Extra' => [ 'scope' => 'environment', - 'provider' => $this->getMockBuilder(ExtraProvider::class)->getMock() + 'provider' => $extraProvider ]; yield 'environment Release' => [ 'scope' => 'environment', - 'provider' => $this->getMockBuilder(ReleaseProvider::class)->getMock() + 'provider' => $releaseProvider ]; yield 'environment Tag' => [ 'scope' => 'environment', - 'provider' => $this->getMockBuilder(TagProvider::class)->getMock() + 'provider' => $tagProvider ]; yield 'environment User' => [ 'scope' => 'environment', - 'provider' => $this->getMockBuilder(UserProvider::class)->getMock() + 'provider' => $userProvider ]; yield 'extra stdClass' => ['scope' => 'extra', 'provider' => new stdClass()]; yield 'extra Environment' => [ 'scope' => 'extra', - 'provider' => $this->getMockBuilder(EnvironmentProvider::class)->getMock() + 'provider' => $environmentProvider ]; yield 'extra Release' => [ 'scope' => 'extra', - 'provider' => $this->getMockBuilder(ReleaseProvider::class)->getMock() + 'provider' => $releaseProvider ]; - yield 'extra Tag' => ['scope' => 'extra', 'provider' => $this->getMockBuilder(TagProvider::class)->getMock()]; - yield 'extra User' => ['scope' => 'extra', 'provider' => $this->getMockBuilder(UserProvider::class)->getMock()]; + yield 'extra Tag' => ['scope' => 'extra', 'provider' => $tagProvider]; + yield 'extra User' => ['scope' => 'extra', 'provider' => $userProvider]; yield 'release stdClass' => ['scope' => 'release', 'provider' => new stdClass()]; yield 'release Environment' => [ 'scope' => 'release', - 'provider' => $this->getMockBuilder(EnvironmentProvider::class)->getMock() + 'provider' => $environmentProvider ]; yield 'release Extra' => [ 'scope' => 'release', - 'provider' => $this->getMockBuilder(ExtraProvider::class)->getMock() + 'provider' => $extraProvider ]; yield 'release Tag' => [ 'scope' => 'release', - 'provider' => $this->getMockBuilder(TagProvider::class)->getMock() + 'provider' => $tagProvider ]; yield 'release User' => [ 'scope' => 'release', - 'provider' => $this->getMockBuilder(UserProvider::class)->getMock() + 'provider' => $userProvider ]; yield 'tags stdClass' => ['scope' => 'tags', 'provider' => new stdClass()]; yield 'tags Environment' => [ 'scope' => 'tags', - 'provider' => $this->getMockBuilder(EnvironmentProvider::class)->getMock() + 'provider' => $environmentProvider ]; - yield 'tags Extra' => ['scope' => 'tags', 'provider' => $this->getMockBuilder(ExtraProvider::class)->getMock()]; + yield 'tags Extra' => ['scope' => 'tags', 'provider' => $extraProvider]; yield 'tags Release' => [ 'scope' => 'tags', - 'provider' => $this->getMockBuilder(ReleaseProvider::class)->getMock() + 'provider' => $releaseProvider ]; - yield 'tags User' => ['scope' => 'tags', 'provider' => $this->getMockBuilder(UserProvider::class)->getMock()]; + yield 'tags User' => ['scope' => 'tags', 'provider' => $userProvider]; yield 'user stdClass' => ['scope' => 'user', 'provider' => new stdClass()]; yield 'user Environment' => [ 'scope' => 'user', - 'provider' => $this->getMockBuilder(EnvironmentProvider::class)->getMock() + 'provider' => $environmentProvider ]; - yield 'user Extra' => ['scope' => 'user', 'provider' => $this->getMockBuilder(ExtraProvider::class)->getMock()]; + yield 'user Extra' => ['scope' => 'user', 'provider' => $extraProvider]; yield 'user Release' => [ 'scope' => 'user', - 'provider' => $this->getMockBuilder(ReleaseProvider::class)->getMock() + 'provider' => $releaseProvider ]; - yield 'user Tag' => ['scope' => 'user', 'provider' => $this->getMockBuilder(TagProvider::class)->getMock()]; + yield 'user Tag' => ['scope' => 'user', 'provider' => $tagProvider]; } /** @@ -234,7 +265,6 @@ public function only_last_environment_is_returned(): void $this->objectManagerMock ->expects(self::exactly(2)) ->method('get') - ->withConsecutive(['EnvironmentMock1'], ['EnvironmentMock2']) ->willReturnOnConsecutiveCalls($environment1, $environment2); $this->provider->injectSettings([ @@ -275,7 +305,6 @@ public function extra_is_merged_recursively(): void $this->objectManagerMock ->expects(self::exactly(2)) ->method('get') - ->withConsecutive(['ExtraMock1'], ['ExtraMock2']) ->willReturnOnConsecutiveCalls($extra1, $extra2); $this->provider->injectSettings([ @@ -316,7 +345,6 @@ public function only_last_release_is_returned(): void $this->objectManagerMock ->expects(self::exactly(2)) ->method('get') - ->withConsecutive(['ReleaseMock1'], ['ReleaseMock2']) ->willReturnOnConsecutiveCalls($release1, $release2); $this->provider->injectSettings([ @@ -357,7 +385,6 @@ public function tags_are_merged_and_override_each_other(): void $this->objectManagerMock ->expects(self::exactly(2)) ->method('get') - ->withConsecutive(['TagMock1'], ['TagMock2']) ->willReturnOnConsecutiveCalls($tag1, $tag2); $this->provider->injectSettings([ @@ -398,7 +425,6 @@ public function user_is_merged_recursively(): void $this->objectManagerMock ->expects(self::exactly(2)) ->method('get') - ->withConsecutive(['UserMock1'], ['UserMock2']) ->willReturnOnConsecutiveCalls($user1, $user2); $this->provider->injectSettings([ @@ -425,16 +451,18 @@ public function withThrowable_triggers_the_callback(): void { $throwable = new Exception('foo', 123); - - $makeSureCallbackWasCalled = self::getMockBuilder(stdClass::class) - ->setMethods(['foo']) + $makeSureCallbackWasCalled = self::getMockBuilder(ClosureLike::class) ->getMock(); $makeSureCallbackWasCalled ->expects(self::once()) - ->method('foo'); + ->method('__invoke'); + + $makeSureCallbackWasCalled + ->expects(self::once()) + ->method('__invoke'); - $this->provider->withThrowable($throwable, [$makeSureCallbackWasCalled, 'foo']); + $this->provider->withThrowable($throwable, [$makeSureCallbackWasCalled, '__invoke']); } /** @@ -446,17 +474,16 @@ public function While_the_callable_runs_the_current_throwable_is_set(): void self::assertNull($this->provider->getCurrentThrowable()); - $makeSureCallbackWasCalled = self::getMockBuilder(stdClass::class) - ->setMethods(['foo']) + $makeSureCallbackWasCalled = self::getMockBuilder(ClosureLike::class) ->getMock(); $makeSureCallbackWasCalled ->expects(self::once()) - ->method('foo'); + ->method('__invoke'); $this->provider->withThrowable($throwable, function () use ($throwable, $makeSureCallbackWasCalled) { self::assertSame($throwable, $this->provider->getCurrentThrowable()); - [$makeSureCallbackWasCalled, 'foo'](); + [$makeSureCallbackWasCalled, '__invoke'](); }); self::assertNull($this->provider->getCurrentThrowable());