|
8 | 8 | use PHPStan\Analyser\ScopeFactory; |
9 | 9 | use PHPStan\Analyser\TypeSpecifier; |
10 | 10 | use PHPStan\BetterReflection\Reflector\Reflector; |
11 | | -use PHPStan\DependencyInjection\Container; |
12 | | -use PHPStan\DependencyInjection\ContainerFactory; |
13 | 11 | use PHPStan\DependencyInjection\Reflection\ClassReflectionExtensionRegistryProvider; |
14 | 12 | use PHPStan\DependencyInjection\Type\ExpressionTypeResolverExtensionRegistryProvider; |
15 | 13 | use PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider; |
16 | | -use PHPStan\File\FileHelper; |
17 | | -use PHPStan\Internal\DirectoryCreator; |
18 | | -use PHPStan\Internal\DirectoryCreatorException; |
19 | 14 | use PHPStan\Node\Printer\ExprPrinter; |
20 | 15 | use PHPStan\Parser\Parser; |
21 | 16 | use PHPStan\Php\ComposerPhpVersionFactory; |
|
32 | 27 | use PHPStan\Type\UsefulTypeAliasResolver; |
33 | 28 | use PHPUnit\Framework\ExpectationFailedException; |
34 | 29 | use PHPUnit\Framework\TestCase; |
35 | | -use function array_merge; |
36 | 30 | use function count; |
37 | | -use function hash; |
38 | 31 | use function implode; |
39 | 32 | use function rtrim; |
40 | 33 | use function sprintf; |
41 | | -use function sys_get_temp_dir; |
42 | 34 | use const DIRECTORY_SEPARATOR; |
43 | | -use const PHP_VERSION_ID; |
44 | 35 |
|
45 | 36 | /** @api */ |
46 | 37 | abstract class PHPStanTestCase extends TestCase |
47 | 38 | { |
48 | 39 |
|
49 | | - /** @var array<string, Container> */ |
50 | | - private static array $containers = []; |
51 | | - |
52 | | - /** @api */ |
53 | | - public static function getContainer(): Container |
54 | | - { |
55 | | - $additionalConfigFiles = [__DIR__ . '/TestCase.neon']; |
56 | | - foreach (static::getAdditionalConfigFiles() as $configFile) { |
57 | | - $additionalConfigFiles[] = $configFile; |
58 | | - } |
59 | | - $cacheKey = hash('sha256', implode("\n", $additionalConfigFiles)); |
60 | | - |
61 | | - if (!isset(self::$containers[$cacheKey])) { |
62 | | - $tmpDir = sys_get_temp_dir() . '/phpstan-tests'; |
63 | | - try { |
64 | | - DirectoryCreator::ensureDirectoryExists($tmpDir, 0777); |
65 | | - } catch (DirectoryCreatorException $e) { |
66 | | - self::fail($e->getMessage()); |
67 | | - } |
68 | | - |
69 | | - $rootDir = __DIR__ . '/../..'; |
70 | | - $fileHelper = new FileHelper($rootDir); |
71 | | - $rootDir = $fileHelper->normalizePath($rootDir, '/'); |
72 | | - $containerFactory = new ContainerFactory($rootDir); |
73 | | - $container = $containerFactory->create($tmpDir, array_merge([ |
74 | | - $containerFactory->getConfigDirectory() . '/config.level8.neon', |
75 | | - ], $additionalConfigFiles), []); |
76 | | - self::$containers[$cacheKey] = $container; |
77 | | - |
78 | | - foreach ($container->getParameter('bootstrapFiles') as $bootstrapFile) { |
79 | | - (static function (string $file) use ($container): void { |
80 | | - require_once $file; |
81 | | - })($bootstrapFile); |
82 | | - } |
83 | | - |
84 | | - if (PHP_VERSION_ID >= 80000) { |
85 | | - require_once __DIR__ . '/../../stubs/runtime/Enum/UnitEnum.php'; |
86 | | - require_once __DIR__ . '/../../stubs/runtime/Enum/BackedEnum.php'; |
87 | | - require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnum.php'; |
88 | | - require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnumUnitCase.php'; |
89 | | - require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnumBackedCase.php'; |
90 | | - } |
91 | | - } else { |
92 | | - ContainerFactory::postInitializeContainer(self::$containers[$cacheKey]); |
93 | | - } |
94 | | - |
95 | | - return self::$containers[$cacheKey]; |
96 | | - } |
97 | | - |
98 | | - /** |
99 | | - * @return string[] |
100 | | - */ |
101 | | - public static function getAdditionalConfigFiles(): array |
102 | | - { |
103 | | - return []; |
104 | | - } |
| 40 | + use PHPStanTestCaseTrait; |
105 | 41 |
|
106 | 42 | public static function getParser(): Parser |
107 | 43 | { |
@@ -188,11 +124,6 @@ protected function shouldTreatPhpDocTypesAsCertain(): bool |
188 | 124 | return true; |
189 | 125 | } |
190 | 126 |
|
191 | | - public static function getFileHelper(): FileHelper |
192 | | - { |
193 | | - return self::getContainer()->getByType(FileHelper::class); |
194 | | - } |
195 | | - |
196 | 127 | /** |
197 | 128 | * Provides a DIRECTORY_SEPARATOR agnostic assertion helper, to compare file paths. |
198 | 129 | * |
|
0 commit comments