Skip to content

Commit f8578aa

Browse files
committed
Add test for app.root union error
1 parent f3613a6 commit f8578aa

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

src/Type/ServiceDynamicReturnTypeExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Reflection\ParametersAcceptorSelector;
1212
use PHPStan\ShouldNotHappenException;
1313
use PHPStan\Type\Constant\ConstantBooleanType;
14+
use Psr\Container\ContainerInterface;
1415

1516
class ServiceDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
1617
{
@@ -26,7 +27,7 @@ public function __construct(ServiceMap $serviceMap)
2627

2728
public function getClass(): string
2829
{
29-
return 'Symfony\Component\DependencyInjection\ContainerInterface';
30+
return ContainerInterface::class;
3031
}
3132

3233
public function isMethodSupported(MethodReflection $methodReflection): bool

tests/fixtures/drupal/modules/phpstan_fixtures/phpstan_fixtures.module

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ function phpstan_fixtures_IfConstantConditionRule() {
1111
function phpstan_fixtures_MissingReturnRule(): string {
1212

1313
}
14+
15+
function phpstan_fixtures_get_app_root(): string {
16+
$app_root = \Drupal::getContainer()->get('app.root');
17+
return $app_root . '/core/includes/install.inc';
18+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Drupal\phpstan_fixtures;
4+
5+
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6+
use Symfony\Component\DependencyInjection\ContainerInterface;
7+
8+
final class AppRootParameter implements ContainerInjectionInterface {
9+
10+
private $appRoot;
11+
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public static function create(ContainerInterface $container)
16+
{
17+
return new self($container->get('app.root'));
18+
}
19+
20+
/**
21+
* AppRootParameter constructor.
22+
*
23+
* @param string $app_root
24+
* The app root.
25+
*/
26+
public function __construct(string $app_root)
27+
{
28+
$this->appRoot = $app_root;
29+
}
30+
31+
public function testUnion(): string {
32+
return $this->appRoot . '/core';
33+
}
34+
}

tests/src/DrupalIntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,10 @@ public function testServiceMapping() {
6060
$this->assertEquals($errorMessages[$key], $error->getMessage());
6161
}
6262
}
63+
64+
public function testAppRootPseudoService() {
65+
$errorMessages = [];
66+
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/modules/phpstan_fixtures/src/AppRootParameter.php');
67+
$this->assertCount(0, $errors, var_export($errors, TRUE));
68+
}
6369
}

0 commit comments

Comments
 (0)