Skip to content

Commit e557b20

Browse files
committed
Specifically check for ContainerNotInitializedException
1 parent 896bc89 commit e557b20

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tests/DrupalIntegrationTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\Drupal;
44

5+
use Drupal\Core\DependencyInjection\ContainerNotInitializedException;
56
use PHPStan\Analyser\Analyser;
67
use PHPStan\DependencyInjection\ContainerFactory;
78
use PHPStan\File\FileHelper;
@@ -53,7 +54,12 @@ private function runAnalyze(string $path) {
5354
(static function (string $file): void {
5455
require_once $file;
5556
})($bootstrapFile);
56-
} catch (\Throwable $e) {
57+
} catch (ContainerNotInitializedException $e) {
58+
$trace = $e->getTrace();
59+
$offending_file = $trace[1];
60+
$this->fail(sprintf('%s called the Drupal container from unscoped code.', $offending_file['file']));
61+
}
62+
catch (\Throwable $e) {
5763
$this->fail('Could not load the bootstrap file');
5864
}
5965
}

0 commit comments

Comments
 (0)