File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace mglaman \PHPStanDrupal \Drupal ;
4
4
5
+ use Composer \Autoload \ClassLoader ;
5
6
use Drupal \Core \DependencyInjection \ContainerNotInitializedException ;
7
+ use Drupal \Core \DrupalKernelInterface ;
6
8
use Drupal \TestTools \PhpUnitCompatibility \PhpUnit8 \ClassWriter ;
7
9
use DrupalFinder \DrupalFinder ;
8
10
use Drush \Drush ;
@@ -102,6 +104,10 @@ public function register(Container $container): void
102
104
$ this ->serviceYamls ['core ' ] = $ drupalRoot . '/core/core.services.yml ' ;
103
105
$ this ->serviceClassProviders ['core ' ] = '\Drupal\Core\CoreServiceProvider ' ;
104
106
$ this ->serviceMap ['service_provider.core.service_provider ' ] = ['class ' => $ this ->serviceClassProviders ['core ' ]];
107
+ // Attach synthetic services
108
+ // @see \Drupal\Core\DrupalKernel::attachSynthetic
109
+ $ this ->serviceMap ['kernel ' ] = ['class ' => DrupalKernelInterface::class];
110
+ $ this ->serviceMap ['class_loader ' ] = ['class ' => ClassLoader::class];
105
111
106
112
$ extensionDiscovery = new ExtensionDiscovery ($ this ->drupalRoot );
107
113
$ extensionDiscovery ->setProfileDirectories ([]);
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ public static function dataFileAsserts(): iterable
18
18
yield from self ::gatherAssertTypes (__DIR__ . '/data/drupal-class-resolver.php ' );
19
19
yield from self ::gatherAssertTypes (__DIR__ . '/data/bug-563.php ' );
20
20
yield from self ::gatherAssertTypes (__DIR__ . '/data/container-optional.php ' );
21
+ yield from self ::gatherAssertTypes (__DIR__ . '/data/synthetic.php ' );
21
22
}
22
23
23
24
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace DrupalContainerSyntheticServices ;
4
+
5
+ use Composer \Autoload \ClassLoader ;
6
+ use Drupal \Core \DrupalKernelInterface ;
7
+ use function PHPStan \Testing \assertType ;
8
+
9
+ function foo (): void {
10
+ $ container = \Drupal::getContainer ();
11
+ assertType (DrupalKernelInterface::class, $ container ->get ('kernel ' ));
12
+ assertType (ClassLoader::class, $ container ->get ('class_loader ' ));
13
+ }
You can’t perform that action at this time.
0 commit comments