Skip to content

Commit b74b49f

Browse files
rvanlaakJean85
authored andcommitted
fix PHPUnit 9 deprecations (#288)
* fix PHPUnit 9 deprecations * do not hard-fail in framework deprecations * Fix PHPStan errors * Run PHPStan on PHP 7.4 (so it will use Symfony 5)
1 parent 7532496 commit b74b49f

12 files changed

+35
-48
lines changed

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ jobs:
4444
- composer remove --dev friendsofphp/php-cs-fixer phpstan/phpstan phpstan/phpstan-phpunit jangregor/phpstan-prophecy --no-update
4545
- travis_retry travis_wait composer update --no-interaction --prefer-dist --prefer-stable --prefer-lowest
4646
- stage: Code style and static analysis
47+
name: PHPStan
48+
php: 7.4
4749
script:
4850
- composer phpstan
49-
env: PHPSTAN=true
5051
- script:
5152
- composer cs-check
52-
env: CS-FIXER=true
53+
name: PHP-CS-Fixer
5354
- stage: coverage
5455
script:
5556
- phpdbg -qrr vendor/bin/phpunit --coverage-clover clover.xml

phpstan.neon

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ parameters:
44
- src/
55
- test/
66
ignoreErrors:
7-
- "/Call to function method_exists.. with 'Symfony.+' and 'getProjectDir' will always evaluate to false./"
87
- "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./"
98
- "/Call to function method_exists.. with 'Sentry..Options' and 'getClassSerializers' will always evaluate to false./"
109
- "/Call to function method_exists.. with 'Sentry..Options' and 'getMaxRequestBodySi...' will always evaluate to false./"
11-
- '/Parameter \$.+ of method Sentry\\SentryBundle\\EventListener\\ErrorListener::onConsoleException\(\) has invalid typehint type Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
12-
- '/Call to method getException\(\) on an unknown class Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
13-
- '/Access to undefined constant Symfony\\Component\\Console\\ConsoleEvents::EXCEPTION./'
1410
- '/Class PHPUnit_Framework_TestCase not found/'
11+
- '/Symfony\\Component\\HttpKernel\\Event\\(GetResponse|FilterController)Event not found.$/'
12+
-
13+
message: '/Symfony\\Bundle\\FrameworkBundle\\Client/'
14+
path: test/End2End/End2EndTest.php
15+
-
16+
message: '/^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root...$/'
17+
path: src/DependencyInjection/Configuration.php
18+
-
19+
message: '/Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent.$/'
20+
path: src/EventListener/ErrorListener.php
1521

1622
includes:
1723
- vendor/jangregor/phpstan-prophecy/src/extension.neon

phpunit.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
2+
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
55
colors="true"
@@ -8,6 +8,9 @@
88
cacheResult="false"
99
processIsolation="true"
1010
>
11+
<php>
12+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
13+
</php>
1114

1215
<testsuites>
1316
<testsuite name="SentryBundle test suite">

test/BaseTestCase.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ protected function setCurrentHub(HubInterface $hub): void
4949
}
5050
}
5151

52-
/**
53-
* @return GetResponseEvent|RequestEvent
54-
*/
5552
protected function createRequestEvent(Request $request = null, int $type = KernelInterface::MASTER_REQUEST)
5653
{
5754
if ($request === null) {
@@ -62,8 +59,7 @@ protected function createRequestEvent(Request $request = null, int $type = Kerne
6259
$event = new RequestEvent(
6360
$this->prophesize(KernelInterface::class)->reveal(),
6461
$request,
65-
$type,
66-
$this->prophesize(Response::class)->reveal()
62+
$type
6763
);
6864
} else {
6965
$event = new GetResponseEvent(

test/Command/SentryTestCommandTest.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public function testExecuteSuccessfully(): void
3333
$commandTester = $this->executeCommand();
3434

3535
$output = $commandTester->getDisplay();
36-
$this->assertContains('DSN correctly configured', $output);
37-
$this->assertContains('Sending test message', $output);
38-
$this->assertContains('Message sent', $output);
39-
$this->assertContains($lastEventId, $output);
36+
$this->assertStringContainsString('DSN correctly configured', $output);
37+
$this->assertStringContainsString('Sending test message', $output);
38+
$this->assertStringContainsString('Message sent', $output);
39+
$this->assertStringContainsString($lastEventId, $output);
4040
$this->assertSame(0, $commandTester->getStatusCode());
4141
}
4242

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

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

6363
public function testExecuteFailsDueToMessageNotSent(): void
@@ -80,9 +80,9 @@ public function testExecuteFailsDueToMessageNotSent(): void
8080

8181
$this->assertNotSame(0, $commandTester->getStatusCode());
8282
$output = $commandTester->getDisplay();
83-
$this->assertContains('DSN correctly configured', $output);
84-
$this->assertContains('Sending test message', $output);
85-
$this->assertContains('Message not sent', $output);
83+
$this->assertStringContainsString('DSN correctly configured', $output);
84+
$this->assertStringContainsString('Sending test message', $output);
85+
$this->assertStringContainsString('Message not sent', $output);
8686
}
8787

8888
public function testExecuteFailsDueToMissingClient(): void
@@ -97,8 +97,8 @@ public function testExecuteFailsDueToMissingClient(): void
9797

9898
$this->assertNotSame(0, $commandTester->getStatusCode());
9999
$output = $commandTester->getDisplay();
100-
$this->assertContains('No client found', $output);
101-
$this->assertContains('DSN is probably missing', $output);
100+
$this->assertStringContainsString('No client found', $output);
101+
$this->assertStringContainsString('DSN is probably missing', $output);
102102
}
103103

104104
private function executeCommand(): CommandTester

test/DependencyInjection/ConfigurationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function testOptionValuesProcessing(string $option, $value): void
9292
$input = ['options' => [$option => $value]];
9393
$processed = $this->processConfiguration($input);
9494

95-
$this->assertArraySubset($input, $processed);
95+
$this->assertContains($input, $processed);
9696
}
9797

9898
public function optionValuesProvider(): array

test/DependencyInjection/SentryExtensionTest.php

+3-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use Symfony\Component\DependencyInjection\Exception\LogicException;
2626
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2727
use Symfony\Component\HttpFoundation\RequestStack;
28-
use Symfony\Component\HttpKernel\Kernel;
2928

3029
class SentryExtensionTest extends BaseTestCase
3130
{
@@ -57,13 +56,8 @@ public function testOptionsDefaultValues(): void
5756
$container = $this->getContainer();
5857
$options = $this->getOptionsFrom($container);
5958

60-
if (method_exists(Kernel::class, 'getProjectDir')) {
61-
$vendorDir = '/dir/project/root/vendor';
62-
$this->assertSame('/dir/project/root', $options->getProjectRoot());
63-
} else {
64-
$vendorDir = 'kernel/root/../vendor';
65-
$this->assertSame('kernel/root/..', $options->getProjectRoot());
66-
}
59+
$vendorDir = '/dir/project/root/vendor';
60+
$this->assertSame('/dir/project/root', $options->getProjectRoot());
6761

6862
$this->assertNull($options->getDsn());
6963
$this->assertSame('test', $options->getEnvironment());
@@ -421,9 +415,7 @@ private function getContainer(array $configuration = []): Container
421415
{
422416
$containerBuilder = new ContainerBuilder();
423417
$containerBuilder->setParameter('kernel.cache_dir', 'var/cache');
424-
if (method_exists(Kernel::class, 'getProjectDir')) {
425-
$containerBuilder->setParameter('kernel.project_dir', '/dir/project/root');
426-
}
418+
$containerBuilder->setParameter('kernel.project_dir', '/dir/project/root');
427419
$containerBuilder->setParameter('kernel.environment', 'test');
428420

429421
$mockEventDispatcher = $this->createMock(EventDispatcherInterface::class);

test/End2End/End2EndTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function testGet500(): void
9898

9999
$this->assertInstanceOf(Response::class, $response);
100100
$this->assertSame(500, $response->getStatusCode());
101-
$this->assertContains('intentional error', $response->getContent());
101+
$this->assertStringContainsString('intentional error', $response->getContent() ?: '');
102102
} catch (\Throwable $exception) {
103103
if (! $exception instanceof \RuntimeException) {
104104
throw $exception;

test/ErrorTypesParserTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class ErrorTypesParserTest extends TestCase
99
{
1010
/**
1111
* @dataProvider parsableValueProvider
12-
* @param int|string $value
1312
*/
1413
public function testParse($value, int $expected): void
1514
{

test/EventListener/ConsoleListenerTest.php

-4
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ private function getTagsContext(Scope $scope): array
8484
return $event->getTagsContext()->toArray();
8585
}
8686

87-
/**
88-
* @param $command
89-
* @return ConsoleCommandEvent
90-
*/
9187
private function createConsoleCommandEvent(?Command $command): ConsoleCommandEvent
9288
{
9389
return new ConsoleCommandEvent(

test/EventListener/RequestListenerTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ private function getTagsContext(Scope $scope): array
306306
return $event->getTagsContext()->toArray();
307307
}
308308

309-
/**
310-
* @return FilterControllerEvent|ControllerEvent
311-
*/
312309
private function createControllerEvent(Request $request)
313310
{
314311
if (class_exists(ControllerEvent::class)) {

test/SentryBundleTest.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\Component\DependencyInjection\ContainerBuilder;
2121
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2222
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
23-
use Symfony\Component\HttpKernel\Kernel;
2423
use Symfony\Component\HttpKernel\KernelEvents;
2524

2625
class SentryBundleTest extends TestCase
@@ -144,9 +143,7 @@ private function getContainer(array $configuration = []): ContainerBuilder
144143
{
145144
$containerBuilder = new ContainerBuilder();
146145
$containerBuilder->setParameter('kernel.cache_dir', 'var/cache');
147-
if (method_exists(Kernel::class, 'getProjectDir')) {
148-
$containerBuilder->setParameter('kernel.project_dir', '/dir/project/root');
149-
}
146+
$containerBuilder->setParameter('kernel.project_dir', '/dir/project/root');
150147

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

0 commit comments

Comments
 (0)