Skip to content

Commit 0138f6f

Browse files
committed
Update tests using APIs removed in newer Symfony versions
1 parent 8aed8b1 commit 0138f6f

9 files changed

Lines changed: 77 additions & 41 deletions

‎tests/Rules/Symfony/ContainerInterfacePrivateServiceRuleFakeTest.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public function testGetPrivateService(): void
3434

3535
public function testGetPrivateServiceInAbstractController(): void
3636
{
37-
if (!class_exists('Symfony\Bundle\FrameworkBundle\Controller\Controller')) {
37+
if (!class_exists('Symfony\Bundle\FrameworkBundle\Controller\AbstractController')) {
38+
self::markTestSkipped();
39+
}
40+
if (!method_exists('Symfony\Bundle\FrameworkBundle\Controller\AbstractController', 'get')) {
3841
self::markTestSkipped();
3942
}
4043
$this->analyse(

‎tests/Rules/Symfony/console_application_loader.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
require_once __DIR__ . '/../../../vendor/autoload.php';
77

88
$application = new Application();
9-
$application->add(new ExampleCommand());
9+
$application->addCommands([new ExampleCommand()]);
1010
return $application;

‎tests/Type/Symfony/ExtensionTest.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function dataFileAsserts(): iterable
5252

5353
if (class_exists('Symfony\Bundle\FrameworkBundle\Controller\AbstractController')) {
5454
yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleAbstractController.php');
55+
56+
if (method_exists('Symfony\Bundle\FrameworkBundle\Controller\AbstractController', 'get')) {
57+
yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleAbstractControllerServices.php');
58+
}
5559
}
5660

5761
yield from $this->gatherAssertTypes(__DIR__ . '/data/serializer.php');

tests/Type/Symfony/ExtensionTestWithoutContainer.php renamed to tests/Type/Symfony/ExtensionWithoutContainerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PHPStan\Testing\TypeInferenceTestCase;
66
use function class_exists;
77

8-
class ExtensionTestWithoutContainer extends TypeInferenceTestCase
8+
class ExtensionWithoutContainerTest extends TypeInferenceTestCase
99
{
1010

1111
public function dataExampleController(): iterable
@@ -23,7 +23,11 @@ public function dataAbstractController(): iterable
2323
return;
2424
}
2525

26-
yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleAbstractController.php');
26+
yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleAbstractControllerWithoutContainer.php');
27+
28+
if (method_exists('Symfony\Bundle\FrameworkBundle\Controller\AbstractController', 'get')) {
29+
yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleAbstractControllerServicesWithoutContainer.php');
30+
}
2731
}
2832

2933
/**

‎tests/Type/Symfony/console_application_loader.php‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
require_once __DIR__ . '/../../../vendor/autoload.php';
1111

1212
$application = new Application();
13-
$application->add(new ExampleACommand());
14-
$application->add(new ExampleBCommand());
15-
$application->add(new ExampleOptionCommand());
13+
$application->addCommands([new ExampleACommand(), new ExampleBCommand(), new ExampleOptionCommand()]);
1614

1715
if (class_exists(LazyCommand::class)) {
18-
$application->add(new LazyCommand('lazy-example-option', [], '', false, static fn () => new ExampleOptionLazyCommand()));
16+
$application->addCommands([new LazyCommand('lazy-example-option', [], '', false, static fn () => new ExampleOptionLazyCommand())]);
1917
} else {
20-
$application->add(new ExampleOptionLazyCommand());
18+
$application->addCommands([new ExampleOptionLazyCommand()]);
2119
}
2220

2321
return $application;

‎tests/Type/Symfony/data/ExampleAbstractController.php‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,6 @@
1010
final class ExampleAbstractController extends AbstractController
1111
{
1212

13-
public function services(): void
14-
{
15-
assertType('Foo', $this->get('foo'));
16-
assertType('Foo', $this->get('parameterised_foo'));
17-
assertType('Foo\Bar', $this->get('parameterised_bar'));
18-
assertType('Synthetic', $this->get('synthetic'));
19-
assertType('object', $this->get('bar'));
20-
assertType('object', $this->get(doFoo()));
21-
assertType('object', $this->get());
22-
23-
assertType('true', $this->has('foo'));
24-
assertType('true', $this->has('synthetic'));
25-
assertType('false', $this->has('bar'));
26-
assertType('bool', $this->has(doFoo()));
27-
assertType('bool', $this->has());
28-
}
29-
3013
public function parameters(ContainerInterface $container, ParameterBagInterface $parameterBag): void
3114
{
3215
assertType('array|bool|float|int|string|null', $container->getParameter('unknown'));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Symfony;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6+
use Symfony\Component\DependencyInjection\ContainerInterface;
7+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
8+
use function PHPStan\Testing\assertType;
9+
10+
final class ExampleAbstractControllerServices extends AbstractController
11+
{
12+
13+
public function services(): void
14+
{
15+
assertType('Foo', $this->get('foo'));
16+
assertType('Foo', $this->get('parameterised_foo'));
17+
assertType('Foo\Bar', $this->get('parameterised_bar'));
18+
assertType('Synthetic', $this->get('synthetic'));
19+
assertType('object', $this->get('bar'));
20+
assertType('object', $this->get(doFoo()));
21+
assertType('object', $this->get());
22+
23+
assertType('true', $this->has('foo'));
24+
assertType('true', $this->has('synthetic'));
25+
assertType('false', $this->has('bar'));
26+
assertType('bool', $this->has(doFoo()));
27+
assertType('bool', $this->has());
28+
}
29+
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Symfony;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6+
use Symfony\Component\DependencyInjection\ContainerInterface;
7+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
8+
use function PHPStan\Testing\assertType;
9+
10+
final class ExampleAbstractControllerServicesWithoutContainer extends AbstractController
11+
{
12+
13+
public function services(): void
14+
{
15+
assertType('object', $this->get('foo'));
16+
assertType('object', $this->get('synthetic'));
17+
assertType('object', $this->get('bar'));
18+
assertType('object', $this->get(doFoo()));
19+
assertType('object', $this->get());
20+
21+
assertType('bool', $this->has('foo'));
22+
assertType('bool', $this->has('synthetic'));
23+
assertType('bool', $this->has('bar'));
24+
assertType('bool', $this->has(doFoo()));
25+
assertType('bool', $this->has());
26+
}
27+
28+
}

‎tests/Type/Symfony/data/ExampleAbstractControllerWithoutContainer.php‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,11 @@
55
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
66
use Symfony\Component\DependencyInjection\ContainerInterface;
77
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
8+
use function PHPStan\Testing\assertType;
89

910
final class ExampleAbstractControllerWithoutContainer extends AbstractController
1011
{
1112

12-
public function services(): void
13-
{
14-
assertType('object', $this->get('foo'));
15-
assertType('object', $this->get('synthetic'));
16-
assertType('object', $this->get('bar'));
17-
assertType('object', $this->get(doFoo()));
18-
assertType('object', $this->get());
19-
20-
assertType('bool', $this->has('foo'));
21-
assertType('bool', $this->has('synthetic'));
22-
assertType('bool', $this->has('bar'));
23-
assertType('bool', $this->has(doFoo()));
24-
assertType('bool', $this->has());
25-
}
26-
2713
public function parameters(ContainerInterface $container, ParameterBagInterface $parameterBag): void
2814
{
2915
assertType('array|bool|float|int|string|null', $container->getParameter('unknown'));

0 commit comments

Comments
 (0)