Skip to content

Commit

Permalink
Merge pull request #25 from netlogix/bugfix/phpunit-10
Browse files Browse the repository at this point in the history
BUGFIX: Ensure phpunit 10 compatibility
  • Loading branch information
tweis authored Jun 1, 2023
2 parents 4561240 + b9802f2 commit 6b2eafe
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 40 deletions.
5 changes: 3 additions & 2 deletions Tests/Unit/Integration/NetlogixIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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',
Expand Down
12 changes: 12 additions & 0 deletions Tests/Unit/Scope/ClosureLike.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Netlogix\Sentry\Tests\Unit\Scope;

class ClosureLike
{
public function __invoke()
{
}
}
2 changes: 1 addition & 1 deletion Tests/Unit/Scope/Environment/FlowSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function empty_environments_are_converted_to_null($environment): void
self::assertNull($flowSettings->getEnvironment());
}

public function provideEmptyEnvironments(): iterable
public static function provideEmptyEnvironments(): iterable
{
yield 'Empty String' => ['environment' => ''];
yield 'NULL' => ['environment' => null];
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Scope/Release/FlowSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
99 changes: 63 additions & 36 deletions Tests/Unit/Scope/ScopeProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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];
}

/**
Expand All @@ -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([
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand All @@ -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']);
}

/**
Expand All @@ -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());
Expand Down

0 comments on commit 6b2eafe

Please sign in to comment.