Skip to content

Test with Composer 2 and no Ocramius subdependency in CI #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ jobs:
- travis_retry travis_wait composer install --no-interaction --prefer-dist
- composer remove --dev friendsofphp/php-cs-fixer phpstan/phpstan phpstan/phpstan-phpunit jangregor/phpstan-prophecy --no-update
- travis_retry travis_wait composer update --no-interaction --prefer-dist --prefer-stable --prefer-lowest
- name: Composer 2
before_install:
- composer self-update --snapshot
- composer require jean85/pretty-package-versions:^1.4 --no-interaction --no-update
- stage: Code style and static analysis
name: PHPStan
script:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

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

## 3.4.4 (2020-03-16)
Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.8",
"jangregor/phpstan-prophecy": "^0.3.0",
"jangregor/phpstan-prophecy": "^0.6.2",
"monolog/monolog": "^1.11||^2.0",
"php-http/mock-client": "^1.0",
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-shim": "^0.11",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.19",
"phpstan/phpstan-phpunit": "^0.12.8",
"phpunit/phpunit": "^7.5||^8.5",
"symfony/browser-kit": "^3.4||^4.0||^5.0",
"symfony/expression-language": "^3.4||^4.0||^5.0",
Expand All @@ -45,6 +46,9 @@
"symfony/phpunit-bridge": "^5.0",
"symfony/yaml": "^3.4||^4.0||^5.0"
},
"conflict": {
"ocramius/package-versions": "<1.3"
},
"suggest": {
"monolog/monolog": "Required to use the Monolog handler"
},
Expand Down
342 changes: 342 additions & 0 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

25 changes: 1 addition & 24 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@ parameters:
- src/
- test/
ignoreErrors:
- "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./"
- "/Call to function method_exists.. with 'Symfony.+' and 'getThrowable' will always evaluate to false./"
- '/Class PHPUnit_Framework_TestCase not found/'
- '/Symfony\\Component\\HttpKernel\\Event\\(GetResponse|FilterController)Event not found.$/'
-
message: '/Symfony\\Bundle\\FrameworkBundle\\Client/'
path: test/End2End/End2EndTest.php
-
message: '/^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root...$/'
path: src/DependencyInjection/Configuration.php
-
message: '/Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent.$/'
path: src/EventListener/ErrorListener.php
-
message: '/Sentry\\SentryBundle\\EventListener\\RequestListener(Request|Controller)Event( not found)?.$/'
path: src/EventListener/RequestListener.php
-
message: '/Sentry\\SentryBundle\\EventListener\\SubRequestListenerRequestEvent( not found)?.$/'
path: src/EventListener/SubRequestListener.php
-
message: '/Class Symfony\\Component\\Messenger\\Event\\WorkerMessage[a-zA-Z]*Event constructor invoked with [0-9]+ parameters, [0-9]+ required\.$/'
path: test/EventListener/MessengerListenerTest.php

includes:
- vendor/jangregor/phpstan-prophecy/src/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- phpstan-baseline.neon
12 changes: 10 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sentry\SentryBundle\DependencyInjection;

use Composer\InstalledVersions;
use Jean85\PrettyVersions;
use PackageVersions\Versions;
use Sentry\Options;
Expand Down Expand Up @@ -111,10 +112,17 @@ public function getConfigTreeBuilder(): TreeBuilder
->defaultValue($defaultValues->getPrefixes())
->prototype('scalar');
$optionsChildNodes->scalarNode('project_root');
$optionsChildNodes->scalarNode('release')
->defaultValue(PrettyVersions::getVersion(Versions::ROOT_PACKAGE_NAME)->getPrettyVersion())

$releaseNode = $optionsChildNodes->scalarNode('release')
->info('Release version to be reported to sentry, see https://docs.sentry.io/workflow/releases/?platform=php')
->example('my/application@ff11bb');

if (class_exists(InstalledVersions::class)) {
$releaseNode->defaultValue(PrettyVersions::getVersion(InstalledVersions::getRootPackage()['name'])->getPrettyVersion());
} elseif (class_exists(Versions::class)) {
$releaseNode->defaultValue(PrettyVersions::getVersion(Versions::ROOT_PACKAGE_NAME)->getPrettyVersion());
}

$optionsChildNodes->floatNode('sample_rate')
->min(0.0)
->max(1.0);
Expand Down
3 changes: 3 additions & 0 deletions src/DependencyInjection/IntegrationFilterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

class IntegrationFilterFactory
{
/**
* @param IntegrationInterface[] $integrationsFromConfiguration
*/
public static function create(array $integrationsFromConfiguration): callable
{
return function (array $integrations) use ($integrationsFromConfiguration) {
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
$options->addMethodCall('setIntegrations', [$integrationsCallable]);
}

/**
* @param string|Reference $value
* @return string|Reference
*/
private function valueToCallable($value)
{
if (is_string($value) && 0 === strpos($value, '@')) {
Expand Down
1 change: 1 addition & 0 deletions src/EventListener/RequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function onKernelController(RequestListenerControllerEvent $event): void

/**
* @param UserInterface | object | string $user
* @return array<string, string>
*/
private function getUserData($user): array
{
Expand Down
1 change: 1 addition & 0 deletions test/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function testListenerPriorities(): void

/**
* @dataProvider optionsValueProvider
* @param bool|int|float|string|string[] $value
*/
public function testValuesArePassedToOptions(string $name, $value, string $getter = null): void
{
Expand Down
8 changes: 6 additions & 2 deletions test/End2End/App/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel as SymfonyKernel;

class Kernel extends SymfonyKernel
{
/**
* @return BundleInterface[]
*/
public function registerBundles()
{
$bundles = [
Expand All @@ -19,14 +23,14 @@ public function registerBundles()
return $bundles;
}

public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__ . '/config.yml');
}

protected function build(ContainerBuilder $container)
{
$container->setParameter('routing_config_dir', __DIR__);
parent::build($container); // TODO: Change the autogenerated stub
parent::build($container);
}
}
12 changes: 0 additions & 12 deletions test/EventListener/MessengerListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public function testSoftFailsAreRecorded(): void
{
if (! $this->supportsMessenger()) {
self::markTestSkipped('Messenger not supported in this environment.');

return;
}

$error = new \RuntimeException();
Expand All @@ -47,8 +45,6 @@ public function testHardFailsAreRecorded(): void
{
if (! $this->supportsMessenger()) {
self::markTestSkipped('Messenger not supported in this environment.');

return;
}

$error = new \RuntimeException();
Expand All @@ -68,8 +64,6 @@ public function testSoftFailsAreNotRecorded(): void
{
if (! $this->supportsMessenger()) {
self::markTestSkipped('Messenger not supported in this environment.');

return;
}

$error = new \RuntimeException();
Expand All @@ -89,8 +83,6 @@ public function testHardFailsAreRecordedWithCaptureSoftDisabled(): void
{
if (! $this->supportsMessenger()) {
self::markTestSkipped('Messenger not supported in this environment.');

return;
}

$error = new \RuntimeException();
Expand All @@ -110,8 +102,6 @@ public function testHandlerFailedExceptionIsUnwrapped(): void
{
if (! $this->supportsMessenger()) {
self::markTestSkipped('Messenger not supported in this environment.');

return;
}

$message = (object) ['foo' => 'bar'];
Expand All @@ -132,8 +122,6 @@ public function testClientIsFlushedWhenMessageHandled(): void
{
if (! $this->supportsMessenger()) {
self::markTestSkipped('Messenger not supported in this environment.');

return;
}

$this->client->flush()->shouldBeCalled();
Expand Down
37 changes: 18 additions & 19 deletions test/EventListener/SubRequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,13 @@

class SubRequestListenerTest extends BaseTestCase
{
private $currentHub;

protected function setUp(): void
{
$this->currentHub = $this->prophesize(HubInterface::class);

SentrySdk::setCurrentHub($this->currentHub->reveal());
}

public function testOnKernelRequestWithMasterRequest(): void
{
$listener = new SubRequestListener();

$masterRequestEvent = $this->createRequestEvent();

$this->currentHub->pushScope()
->shouldNotBeCalled();
$this->mockHub();

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

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

$this->currentHub->pushScope()
->shouldBeCalledTimes(1)
->willReturn(new Scope());
$this->mockHub(1);

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

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

$this->currentHub->popScope()
->shouldNotBeCalled();
$this->mockHub();

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

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

$this->currentHub->popScope()
->shouldBeCalledTimes(1)
->willReturn(true);
$this->mockHub(0, 1);

$listener->onKernelFinishRequest($subRequestEvent);
}

private function mockHub(int $pushCount = 0, int $popCount = 0): void
{
$currentHub = $this->prophesize(HubInterface::class);
SentrySdk::setCurrentHub($currentHub->reveal());

$currentHub->pushScope()
->shouldBeCalledTimes($pushCount)
->willReturn(new Scope());

$currentHub->popScope()
->shouldBeCalledTimes($popCount)
->willReturn(true);
}

private function createFinishRequestEvent(int $type): FinishRequestEvent
{
return new FinishRequestEvent(
Expand Down
4 changes: 2 additions & 2 deletions test/SentryBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function testIntegrationsListenersAreDisabledByDefault(): void
$this->assertNull($hub->getIntegration(ExceptionListenerIntegration::class));
}

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

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

SentrySdk::setCurrentHub(new Hub());

Expand Down