Skip to content

fix PHPUnit 9 deprecations #288

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 4 commits into from
Dec 12, 2019
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
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ jobs:
- 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
- stage: Code style and static analysis
name: PHPStan
php: 7.4
script:
- composer phpstan
env: PHPSTAN=true
- script:
- composer cs-check
env: CS-FIXER=true
name: PHP-CS-Fixer
- stage: coverage
script:
- phpdbg -qrr vendor/bin/phpunit --coverage-clover clover.xml
Expand Down
14 changes: 10 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ parameters:
- src/
- test/
ignoreErrors:
- "/Call to function method_exists.. with 'Symfony.+' and 'getProjectDir' will always evaluate to false./"
- "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./"
- "/Call to function method_exists.. with 'Sentry..Options' and 'getClassSerializers' will always evaluate to false./"
- "/Call to function method_exists.. with 'Sentry..Options' and 'getMaxRequestBodySi...' will always evaluate to false./"
- '/Parameter \$.+ of method Sentry\\SentryBundle\\EventListener\\ErrorListener::onConsoleException\(\) has invalid typehint type Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
- '/Call to method getException\(\) on an unknown class Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
- '/Access to undefined constant Symfony\\Component\\Console\\ConsoleEvents::EXCEPTION./'
- '/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

includes:
- vendor/jangregor/phpstan-prophecy/src/extension.neon
Expand Down
5 changes: 4 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
colors="true"
Expand All @@ -8,6 +8,9 @@
cacheResult="false"
processIsolation="true"
>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard failure on Symfony deprecations is required: we cannot let this bundle start them, or we could flood Sentry with unuseful events.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the assumption that hereby we would ignore the indirect deprecations.

Yes, the direct deprecations on this bundle's code should definitely fail CI. Maybe change the mode then?

</php>

<testsuites>
<testsuite name="SentryBundle test suite">
Expand Down
6 changes: 1 addition & 5 deletions test/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ protected function setCurrentHub(HubInterface $hub): void
}
}

/**
* @return GetResponseEvent|RequestEvent
*/
protected function createRequestEvent(Request $request = null, int $type = KernelInterface::MASTER_REQUEST)
{
if ($request === null) {
Expand All @@ -62,8 +59,7 @@ protected function createRequestEvent(Request $request = null, int $type = Kerne
$event = new RequestEvent(
$this->prophesize(KernelInterface::class)->reveal(),
$request,
$type,
$this->prophesize(Response::class)->reveal()
$type
);
} else {
$event = new GetResponseEvent(
Expand Down
22 changes: 11 additions & 11 deletions test/Command/SentryTestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public function testExecuteSuccessfully(): void
$commandTester = $this->executeCommand();

$output = $commandTester->getDisplay();
$this->assertContains('DSN correctly configured', $output);
$this->assertContains('Sending test message', $output);
$this->assertContains('Message sent', $output);
$this->assertContains($lastEventId, $output);
$this->assertStringContainsString('DSN correctly configured', $output);
$this->assertStringContainsString('Sending test message', $output);
$this->assertStringContainsString('Message sent', $output);
$this->assertStringContainsString($lastEventId, $output);
$this->assertSame(0, $commandTester->getStatusCode());
}

Expand All @@ -56,8 +56,8 @@ public function testExecuteFailsDueToMissingDSN(): void

$this->assertNotSame(0, $commandTester->getStatusCode());
$output = $commandTester->getDisplay();
$this->assertContains('No DSN configured', $output);
$this->assertContains('try bin/console debug:config sentry', $output);
$this->assertStringContainsString('No DSN configured', $output);
$this->assertStringContainsString('try bin/console debug:config sentry', $output);
}

public function testExecuteFailsDueToMessageNotSent(): void
Expand All @@ -80,9 +80,9 @@ public function testExecuteFailsDueToMessageNotSent(): void

$this->assertNotSame(0, $commandTester->getStatusCode());
$output = $commandTester->getDisplay();
$this->assertContains('DSN correctly configured', $output);
$this->assertContains('Sending test message', $output);
$this->assertContains('Message not sent', $output);
$this->assertStringContainsString('DSN correctly configured', $output);
$this->assertStringContainsString('Sending test message', $output);
$this->assertStringContainsString('Message not sent', $output);
}

public function testExecuteFailsDueToMissingClient(): void
Expand All @@ -97,8 +97,8 @@ public function testExecuteFailsDueToMissingClient(): void

$this->assertNotSame(0, $commandTester->getStatusCode());
$output = $commandTester->getDisplay();
$this->assertContains('No client found', $output);
$this->assertContains('DSN is probably missing', $output);
$this->assertStringContainsString('No client found', $output);
$this->assertStringContainsString('DSN is probably missing', $output);
}

private function executeCommand(): CommandTester
Expand Down
2 changes: 1 addition & 1 deletion test/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function testOptionValuesProcessing(string $option, $value): void
$input = ['options' => [$option => $value]];
$processed = $this->processConfiguration($input);

$this->assertArraySubset($input, $processed);
$this->assertContains($input, $processed);
}

public function optionValuesProvider(): array
Expand Down
14 changes: 3 additions & 11 deletions test/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Kernel;

class SentryExtensionTest extends BaseTestCase
{
Expand Down Expand Up @@ -57,13 +56,8 @@ public function testOptionsDefaultValues(): void
$container = $this->getContainer();
$options = $this->getOptionsFrom($container);

if (method_exists(Kernel::class, 'getProjectDir')) {
$vendorDir = '/dir/project/root/vendor';
$this->assertSame('/dir/project/root', $options->getProjectRoot());
} else {
$vendorDir = 'kernel/root/../vendor';
$this->assertSame('kernel/root/..', $options->getProjectRoot());
}
$vendorDir = '/dir/project/root/vendor';
$this->assertSame('/dir/project/root', $options->getProjectRoot());

$this->assertNull($options->getDsn());
$this->assertSame('test', $options->getEnvironment());
Expand Down Expand Up @@ -421,9 +415,7 @@ private function getContainer(array $configuration = []): Container
{
$containerBuilder = new ContainerBuilder();
$containerBuilder->setParameter('kernel.cache_dir', 'var/cache');
if (method_exists(Kernel::class, 'getProjectDir')) {
$containerBuilder->setParameter('kernel.project_dir', '/dir/project/root');
}
$containerBuilder->setParameter('kernel.project_dir', '/dir/project/root');
$containerBuilder->setParameter('kernel.environment', 'test');

$mockEventDispatcher = $this->createMock(EventDispatcherInterface::class);
Expand Down
2 changes: 1 addition & 1 deletion test/End2End/End2EndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testGet500(): void

$this->assertInstanceOf(Response::class, $response);
$this->assertSame(500, $response->getStatusCode());
$this->assertContains('intentional error', $response->getContent());
$this->assertStringContainsString('intentional error', $response->getContent() ?: '');
} catch (\Throwable $exception) {
if (! $exception instanceof \RuntimeException) {
throw $exception;
Expand Down
1 change: 0 additions & 1 deletion test/ErrorTypesParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class ErrorTypesParserTest extends TestCase
{
/**
* @dataProvider parsableValueProvider
* @param int|string $value
*/
public function testParse($value, int $expected): void
{
Expand Down
4 changes: 0 additions & 4 deletions test/EventListener/ConsoleListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ private function getTagsContext(Scope $scope): array
return $event->getTagsContext()->toArray();
}

/**
* @param $command
* @return ConsoleCommandEvent
*/
private function createConsoleCommandEvent(?Command $command): ConsoleCommandEvent
{
return new ConsoleCommandEvent(
Expand Down
3 changes: 0 additions & 3 deletions test/EventListener/RequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,6 @@ private function getTagsContext(Scope $scope): array
return $event->getTagsContext()->toArray();
}

/**
* @return FilterControllerEvent|ControllerEvent
*/
private function createControllerEvent(Request $request)
{
if (class_exists(ControllerEvent::class)) {
Expand Down
5 changes: 1 addition & 4 deletions test/SentryBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelEvents;

class SentryBundleTest extends TestCase
Expand Down Expand Up @@ -144,9 +143,7 @@ private function getContainer(array $configuration = []): ContainerBuilder
{
$containerBuilder = new ContainerBuilder();
$containerBuilder->setParameter('kernel.cache_dir', 'var/cache');
if (method_exists(Kernel::class, 'getProjectDir')) {
$containerBuilder->setParameter('kernel.project_dir', '/dir/project/root');
}
$containerBuilder->setParameter('kernel.project_dir', '/dir/project/root');

$containerBuilder->setParameter('kernel.environment', 'test');
$containerBuilder->set('event_dispatcher', $this->prophesize(EventDispatcherInterface::class)->reveal());
Expand Down