Skip to content

Commit e4ea3c1

Browse files
committed
Test drupal container related type inference
1 parent d66a20f commit e4ea3c1

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

tests/src/Type/DrupalClassResolverDynamicReturnTypeExtensionTest.php renamed to tests/src/Type/DrupalContainerDynamicReturnTypeTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
use mglaman\PHPStanDrupal\Tests\AdditionalConfigFilesTrait;
88
use PHPStan\Testing\TypeInferenceTestCase;
99

10-
class DrupalClassResolverDynamicReturnTypeExtensionTest extends TypeInferenceTestCase
10+
final class DrupalContainerDynamicReturnTypeTest extends TypeInferenceTestCase
1111
{
1212
use AdditionalConfigFilesTrait;
1313

1414
public function dataFileAsserts(): iterable
1515
{
16+
yield from $this->gatherAssertTypes(__DIR__ . '/data/container.php');
17+
yield from $this->gatherAssertTypes(__DIR__ . '/data/drupal-service-static.php');
1618
yield from $this->gatherAssertTypes(__DIR__ . '/data/drupal-class-resolver.php');
1719
}
1820

tests/src/Type/data/container.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace DrupalContainerStatic;
4+
5+
use Drupal\service_map\MyService;
6+
use function PHPStan\Testing\assertType;
7+
8+
$container = \Drupal::getContainer();
9+
10+
assertType(MyService::class, $container->get('service_map.my_service'));
11+
assertType('true', $container->has('service_map.my_service'));
12+
assertType('false', $container->has('unknown_service'));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace DrupalServiceStatic;
4+
5+
use Drupal\service_map\MyService;
6+
use function PHPStan\Testing\assertType;
7+
8+
assertType(MyService::class, \Drupal::service('service_map.my_service'));

0 commit comments

Comments
 (0)