|
2 | 2 |
|
3 | 3 | namespace PHPStan\Symfony; |
4 | 4 |
|
5 | | -use Nette\DI\Compiler; |
6 | | -use Nette\DI\ContainerLoader; |
7 | | -use PHPStan\DependencyInjection\ParametersSchemaExtension; |
8 | | -use PHPStan\DependencyInjection\RulesExtension; |
| 5 | +use PHPStan\DependencyInjection\ContainerFactory; |
9 | 6 | use PHPUnit\Framework\TestCase; |
10 | | -use function sprintf; |
11 | | -use function unlink; |
12 | 7 |
|
13 | 8 | final class NeonTest extends TestCase |
14 | 9 | { |
15 | 10 |
|
16 | 11 | public function testExtensionNeon(): void |
17 | 12 | { |
18 | | - $key = ''; |
19 | 13 | $tmpDir = __DIR__ . '/../tmp'; |
20 | | - $loader = new ContainerLoader($tmpDir, true); |
21 | | - $generatedContainer = sprintf('%s/%s.php', $tmpDir, $loader->getClassName($key)); |
22 | | - |
23 | | - @unlink($generatedContainer); |
24 | | - self::assertFileNotExists($generatedContainer); |
25 | | - |
26 | | - $class = $loader->load(function (Compiler $compiler): void { |
27 | | - $compiler->addExtension('rules', new RulesExtension()); |
28 | | - $compiler->addExtension('parametersSchema', new ParametersSchemaExtension()); |
29 | | - $compiler->addConfig(['parameters' => ['rootDir' => __DIR__]]); |
30 | | - $compiler->loadConfig(__DIR__ . '/../../extension.neon'); |
31 | | - $compiler->loadConfig(__DIR__ . '/../../rules.neon'); |
32 | | - $compiler->loadConfig(__DIR__ . '/config.neon'); |
33 | | - }, $key); |
34 | | - /** @var \Nette\DI\Container $container */ |
35 | | - $container = new $class(); |
| 14 | + $containerFactory = new ContainerFactory(__DIR__); |
| 15 | + $container = $containerFactory->create($tmpDir, [ |
| 16 | + __DIR__ . '/../../extension.neon', |
| 17 | + __DIR__ . '/../../rules.neon', |
| 18 | + __DIR__ . '/config.neon', |
36 | 19 |
|
| 20 | + ], []); |
37 | 21 | $parameters = $container->getParameters(); |
38 | | - unset($parameters['__parametersSchema']); |
39 | | - |
40 | | - self::assertSame([ |
41 | | - 'rootDir' => __DIR__, |
42 | | - 'symfony' => [ |
43 | | - 'container_xml_path' => __DIR__ . '/container.xml', |
44 | | - 'constant_hassers' => true, |
45 | | - 'console_application_loader' => null, |
46 | | - ], |
47 | | - ], $parameters); |
48 | | - |
49 | | - self::assertCount(6, $container->findByTag('phpstan.rules.rule')); |
50 | | - self::assertCount(12, $container->findByTag('phpstan.broker.dynamicMethodReturnTypeExtension')); |
51 | | - self::assertCount(6, $container->findByTag('phpstan.typeSpecifier.methodTypeSpecifyingExtension')); |
| 22 | + $this->assertArrayHasKey('rootDir', $parameters); |
| 23 | + $this->assertSame(realpath(__DIR__ . '/../../vendor/phpstan/phpstan'), $parameters['rootDir']); |
| 24 | + |
| 25 | + $this->assertArrayHasKey('symfony', $parameters); |
| 26 | + $this->assertSame([ |
| 27 | + 'container_xml_path' => __DIR__ . '/container.xml', |
| 28 | + 'constant_hassers' => true, |
| 29 | + 'console_application_loader' => null, |
| 30 | + ] , $parameters['symfony']); |
| 31 | + |
| 32 | + self::assertCount(6, $container->getServicesByTag('phpstan.rules.rule')); |
| 33 | + self::assertCount(15, $container->getServicesByTag('phpstan.broker.dynamicMethodReturnTypeExtension')); |
| 34 | + self::assertCount(6, $container->getServicesByTag('phpstan.typeSpecifier.methodTypeSpecifyingExtension')); |
52 | 35 | self::assertInstanceOf(ServiceMap::class, $container->getByType(ServiceMap::class)); |
53 | 36 | } |
54 | 37 |
|
|
0 commit comments