Skip to content

Commit 6c3f323

Browse files
authored
Test with Composer 2 and no Ocramius subdependency in CI (#335)
* Test with Composer 2 and no Ocramius subdependency in CI * Make release default value work on Composer 2 * Add conflict rule to avoid installing dep without Versions::ROOT_PACKAGE_NAME * Upgrade PHPStan * Fix CS * Add changelog entry
1 parent 6e9278d commit 6c3f323

14 files changed

+401
-64
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ jobs:
4848
- travis_retry travis_wait composer install --no-interaction --prefer-dist
4949
- composer remove --dev friendsofphp/php-cs-fixer phpstan/phpstan phpstan/phpstan-phpunit jangregor/phpstan-prophecy --no-update
5050
- travis_retry travis_wait composer update --no-interaction --prefer-dist --prefer-stable --prefer-lowest
51+
- name: Composer 2
52+
before_install:
53+
- composer self-update --snapshot
54+
- composer require jean85/pretty-package-versions:^1.4 --no-interaction --no-update
5155
- stage: Code style and static analysis
5256
name: PHPStan
5357
script:

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## Unreleased
88
- Capture and flush messages in a Messenger Worker context (#326, thanks to @emarref)
9+
- Support Composer 2 (#335)
10+
- Avoid issues with dependency lower bound, fix #331 (#335)
911
- ...
1012

1113
## 3.4.4 (2020-03-16)

composer.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
},
3232
"require-dev": {
3333
"friendsofphp/php-cs-fixer": "^2.8",
34-
"jangregor/phpstan-prophecy": "^0.3.0",
34+
"jangregor/phpstan-prophecy": "^0.6.2",
3535
"monolog/monolog": "^1.11||^2.0",
3636
"php-http/mock-client": "^1.0",
37-
"phpstan/phpstan-phpunit": "^0.11",
38-
"phpstan/phpstan-shim": "^0.11",
37+
"phpstan/extension-installer": "^1.0",
38+
"phpstan/phpstan": "^0.12.19",
39+
"phpstan/phpstan-phpunit": "^0.12.8",
3940
"phpunit/phpunit": "^7.5||^8.5",
4041
"symfony/browser-kit": "^3.4||^4.0||^5.0",
4142
"symfony/expression-language": "^3.4||^4.0||^5.0",
@@ -45,6 +46,9 @@
4546
"symfony/phpunit-bridge": "^5.0",
4647
"symfony/yaml": "^3.4||^4.0||^5.0"
4748
},
49+
"conflict": {
50+
"ocramius/package-versions": "<1.3"
51+
},
4852
"suggest": {
4953
"monolog/monolog": "Required to use the Monolog handler"
5054
},

phpstan-baseline.neon

+342
Large diffs are not rendered by default.

phpstan.neon

+1-24
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,6 @@ parameters:
44
- src/
55
- test/
66
ignoreErrors:
7-
- "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./"
8-
- "/Call to function method_exists.. with 'Symfony.+' and 'getThrowable' will always evaluate to false./"
9-
- '/Class PHPUnit_Framework_TestCase not found/'
107
- '/Symfony\\Component\\HttpKernel\\Event\\(GetResponse|FilterController)Event not found.$/'
11-
-
12-
message: '/Symfony\\Bundle\\FrameworkBundle\\Client/'
13-
path: test/End2End/End2EndTest.php
14-
-
15-
message: '/^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root...$/'
16-
path: src/DependencyInjection/Configuration.php
17-
-
18-
message: '/Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent.$/'
19-
path: src/EventListener/ErrorListener.php
20-
-
21-
message: '/Sentry\\SentryBundle\\EventListener\\RequestListener(Request|Controller)Event( not found)?.$/'
22-
path: src/EventListener/RequestListener.php
23-
-
24-
message: '/Sentry\\SentryBundle\\EventListener\\SubRequestListenerRequestEvent( not found)?.$/'
25-
path: src/EventListener/SubRequestListener.php
26-
-
27-
message: '/Class Symfony\\Component\\Messenger\\Event\\WorkerMessage[a-zA-Z]*Event constructor invoked with [0-9]+ parameters, [0-9]+ required\.$/'
28-
path: test/EventListener/MessengerListenerTest.php
29-
308
includes:
31-
- vendor/jangregor/phpstan-prophecy/src/extension.neon
32-
- vendor/phpstan/phpstan-phpunit/extension.neon
9+
- phpstan-baseline.neon

src/DependencyInjection/Configuration.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Sentry\SentryBundle\DependencyInjection;
44

5+
use Composer\InstalledVersions;
56
use Jean85\PrettyVersions;
67
use PackageVersions\Versions;
78
use Sentry\Options;
@@ -111,10 +112,17 @@ public function getConfigTreeBuilder(): TreeBuilder
111112
->defaultValue($defaultValues->getPrefixes())
112113
->prototype('scalar');
113114
$optionsChildNodes->scalarNode('project_root');
114-
$optionsChildNodes->scalarNode('release')
115-
->defaultValue(PrettyVersions::getVersion(Versions::ROOT_PACKAGE_NAME)->getPrettyVersion())
115+
116+
$releaseNode = $optionsChildNodes->scalarNode('release')
116117
->info('Release version to be reported to sentry, see https://docs.sentry.io/workflow/releases/?platform=php')
117118
->example('my/application@ff11bb');
119+
120+
if (class_exists(InstalledVersions::class)) {
121+
$releaseNode->defaultValue(PrettyVersions::getVersion(InstalledVersions::getRootPackage()['name'])->getPrettyVersion());
122+
} elseif (class_exists(Versions::class)) {
123+
$releaseNode->defaultValue(PrettyVersions::getVersion(Versions::ROOT_PACKAGE_NAME)->getPrettyVersion());
124+
}
125+
118126
$optionsChildNodes->floatNode('sample_rate')
119127
->min(0.0)
120128
->max(1.0);

src/DependencyInjection/IntegrationFilterFactory.php

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
class IntegrationFilterFactory
1010
{
11+
/**
12+
* @param IntegrationInterface[] $integrationsFromConfiguration
13+
*/
1114
public static function create(array $integrationsFromConfiguration): callable
1215
{
1316
return function (array $integrations) use ($integrationsFromConfiguration) {

src/DependencyInjection/SentryExtension.php

+4
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
142142
$options->addMethodCall('setIntegrations', [$integrationsCallable]);
143143
}
144144

145+
/**
146+
* @param string|Reference $value
147+
* @return string|Reference
148+
*/
145149
private function valueToCallable($value)
146150
{
147151
if (is_string($value) && 0 === strpos($value, '@')) {

src/EventListener/RequestListener.php

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public function onKernelController(RequestListenerControllerEvent $event): void
106106

107107
/**
108108
* @param UserInterface | object | string $user
109+
* @return array<string, string>
109110
*/
110111
private function getUserData($user): array
111112
{

test/DependencyInjection/SentryExtensionTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function testListenerPriorities(): void
8888

8989
/**
9090
* @dataProvider optionsValueProvider
91+
* @param bool|int|float|string|string[] $value
9192
*/
9293
public function testValuesArePassedToOptions(string $name, $value, string $getter = null): void
9394
{

test/End2End/App/Kernel.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
use Symfony\Component\Config\Loader\LoaderInterface;
66
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
78
use Symfony\Component\HttpKernel\Kernel as SymfonyKernel;
89

910
class Kernel extends SymfonyKernel
1011
{
12+
/**
13+
* @return BundleInterface[]
14+
*/
1115
public function registerBundles()
1216
{
1317
$bundles = [
@@ -19,14 +23,14 @@ public function registerBundles()
1923
return $bundles;
2024
}
2125

22-
public function registerContainerConfiguration(LoaderInterface $loader)
26+
public function registerContainerConfiguration(LoaderInterface $loader): void
2327
{
2428
$loader->load(__DIR__ . '/config.yml');
2529
}
2630

2731
protected function build(ContainerBuilder $container)
2832
{
2933
$container->setParameter('routing_config_dir', __DIR__);
30-
parent::build($container); // TODO: Change the autogenerated stub
34+
parent::build($container);
3135
}
3236
}

test/EventListener/MessengerListenerTest.php

-12
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public function testSoftFailsAreRecorded(): void
2626
{
2727
if (! $this->supportsMessenger()) {
2828
self::markTestSkipped('Messenger not supported in this environment.');
29-
30-
return;
3129
}
3230

3331
$error = new \RuntimeException();
@@ -47,8 +45,6 @@ public function testHardFailsAreRecorded(): void
4745
{
4846
if (! $this->supportsMessenger()) {
4947
self::markTestSkipped('Messenger not supported in this environment.');
50-
51-
return;
5248
}
5349

5450
$error = new \RuntimeException();
@@ -68,8 +64,6 @@ public function testSoftFailsAreNotRecorded(): void
6864
{
6965
if (! $this->supportsMessenger()) {
7066
self::markTestSkipped('Messenger not supported in this environment.');
71-
72-
return;
7367
}
7468

7569
$error = new \RuntimeException();
@@ -89,8 +83,6 @@ public function testHardFailsAreRecordedWithCaptureSoftDisabled(): void
8983
{
9084
if (! $this->supportsMessenger()) {
9185
self::markTestSkipped('Messenger not supported in this environment.');
92-
93-
return;
9486
}
9587

9688
$error = new \RuntimeException();
@@ -110,8 +102,6 @@ public function testHandlerFailedExceptionIsUnwrapped(): void
110102
{
111103
if (! $this->supportsMessenger()) {
112104
self::markTestSkipped('Messenger not supported in this environment.');
113-
114-
return;
115105
}
116106

117107
$message = (object) ['foo' => 'bar'];
@@ -132,8 +122,6 @@ public function testClientIsFlushedWhenMessageHandled(): void
132122
{
133123
if (! $this->supportsMessenger()) {
134124
self::markTestSkipped('Messenger not supported in this environment.');
135-
136-
return;
137125
}
138126

139127
$this->client->flush()->shouldBeCalled();

test/EventListener/SubRequestListenerTest.php

+18-19
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,13 @@
1313

1414
class SubRequestListenerTest extends BaseTestCase
1515
{
16-
private $currentHub;
17-
18-
protected function setUp(): void
19-
{
20-
$this->currentHub = $this->prophesize(HubInterface::class);
21-
22-
SentrySdk::setCurrentHub($this->currentHub->reveal());
23-
}
24-
2516
public function testOnKernelRequestWithMasterRequest(): void
2617
{
2718
$listener = new SubRequestListener();
2819

2920
$masterRequestEvent = $this->createRequestEvent();
3021

31-
$this->currentHub->pushScope()
32-
->shouldNotBeCalled();
22+
$this->mockHub();
3323

3424
$listener->onKernelRequest($masterRequestEvent);
3525
}
@@ -40,9 +30,7 @@ public function testOnKernelRequestWithSubRequest(): void
4030

4131
$subRequestEvent = $this->createRequestEvent(null, KernelInterface::SUB_REQUEST);
4232

43-
$this->currentHub->pushScope()
44-
->shouldBeCalledTimes(1)
45-
->willReturn(new Scope());
33+
$this->mockHub(1);
4634

4735
$listener->onKernelRequest($subRequestEvent);
4836
}
@@ -53,8 +41,7 @@ public function testOnKernelFinishRequestWithMasterRequest(): void
5341

5442
$masterRequestEvent = $this->createFinishRequestEvent(KernelInterface::MASTER_REQUEST);
5543

56-
$this->currentHub->popScope()
57-
->shouldNotBeCalled();
44+
$this->mockHub();
5845

5946
$listener->onKernelFinishRequest($masterRequestEvent);
6047
}
@@ -65,13 +52,25 @@ public function testOnKernelFinishRequestWithSubRequest(): void
6552

6653
$subRequestEvent = $this->createFinishRequestEvent(KernelInterface::SUB_REQUEST);
6754

68-
$this->currentHub->popScope()
69-
->shouldBeCalledTimes(1)
70-
->willReturn(true);
55+
$this->mockHub(0, 1);
7156

7257
$listener->onKernelFinishRequest($subRequestEvent);
7358
}
7459

60+
private function mockHub(int $pushCount = 0, int $popCount = 0): void
61+
{
62+
$currentHub = $this->prophesize(HubInterface::class);
63+
SentrySdk::setCurrentHub($currentHub->reveal());
64+
65+
$currentHub->pushScope()
66+
->shouldBeCalledTimes($pushCount)
67+
->willReturn(new Scope());
68+
69+
$currentHub->popScope()
70+
->shouldBeCalledTimes($popCount)
71+
->willReturn(true);
72+
}
73+
7574
private function createFinishRequestEvent(int $type): FinishRequestEvent
7675
{
7776
return new FinishRequestEvent(

test/SentryBundleTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function testIntegrationsListenersAreDisabledByDefault(): void
139139
$this->assertNull($hub->getIntegration(ExceptionListenerIntegration::class));
140140
}
141141

142-
private function getContainer(array $configuration = []): ContainerBuilder
142+
private function getContainer(): ContainerBuilder
143143
{
144144
$containerBuilder = new ContainerBuilder();
145145
$containerBuilder->setParameter('kernel.cache_dir', 'var/cache');
@@ -149,7 +149,7 @@ private function getContainer(array $configuration = []): ContainerBuilder
149149
$containerBuilder->set('event_dispatcher', $this->prophesize(EventDispatcherInterface::class)->reveal());
150150

151151
$extension = new SentryExtension();
152-
$extension->load(['sentry' => $configuration], $containerBuilder);
152+
$extension->load([], $containerBuilder);
153153

154154
SentrySdk::setCurrentHub(new Hub());
155155

0 commit comments

Comments
 (0)