diff --git a/tests/Symfony/ExampleContainer.php b/tests/Symfony/ExampleContainer.php deleted file mode 100644 index 785004a1..00000000 --- a/tests/Symfony/ExampleContainer.php +++ /dev/null @@ -1,154 +0,0 @@ - [ - 'PHPStan\Rules\Rule' => [['rules.0', 'rules.1']], - 'PHPStan\Rules\Symfony\ContainerInterfacePrivateServiceRule' => [['rules.0']], - 'PHPStan\Rules\Symfony\ContainerInterfaceUnknownServiceRule' => [['rules.1']], - 'PhpParser\PrettyPrinterAbstract' => [1 => ['3_PhpParser_PrettyPrinter_Standard']], - 'PhpParser\PrettyPrinter\Standard' => [1 => ['3_PhpParser_PrettyPrinter_Standard']], - 'PHPStan\Symfony\ServiceMap' => [1 => ['4']], - 'PHPStan\Symfony\ServiceMapFactory' => [1 => ['symfony.serviceMapFactory']], - 'PHPStan\Type\DynamicMethodReturnTypeExtension' => [1 => ['6', '10', '11', '12']], - 'PHPStan\Type\Symfony\RequestDynamicReturnTypeExtension' => [1 => ['6']], - 'PHPStan\Type\MethodTypeSpecifyingExtension' => [1 => ['7', '8', '9']], - 'PHPStan\Analyser\TypeSpecifierAwareExtension' => [1 => ['7', '8', '9']], - 'PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension' => [1 => ['7', '8', '9']], - 'PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension' => [1 => ['10', '11', '12']], - 'Nette\DI\Container' => [1 => ['container']], - ], - 'services' => [ - '3_PhpParser_PrettyPrinter_Standard' => 'PhpParser\PrettyPrinter\Standard', - 'container' => 'Nette\DI\Container', - 'rules.0' => 'PHPStan\Rules\Symfony\ContainerInterfacePrivateServiceRule', - 'rules.1' => 'PHPStan\Rules\Symfony\ContainerInterfaceUnknownServiceRule', - 'symfony.serviceMapFactory' => 'PHPStan\Symfony\ServiceMapFactory', - 4 => 'PHPStan\Symfony\ServiceMap', - 6 => 'PHPStan\Type\Symfony\RequestDynamicReturnTypeExtension', - 'PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension', - 'PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension', - 'PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension', - 'PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension', - 'PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension', - 'PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension', - ], - 'tags' => [ - 'phpstan.rules.rule' => ['rules.0' => true, 'rules.1' => true], - 'phpstan.broker.dynamicMethodReturnTypeExtension' => [6 => true, 10 => true, true, true], - 'phpstan.typeSpecifier.methodTypeSpecifyingExtension' => [7 => true, true, true], - ], - 'aliases' => [], - ]; - - - public function __construct(array $params = []) - { - $this->parameters = $params; - $this->parameters += ['symfony' => ['container_xml_path' => '', 'constant_hassers' => true]]; - } - - - public function createService__3_PhpParser_PrettyPrinter_Standard(): PhpParser\PrettyPrinter\Standard - { - $service = new PhpParser\PrettyPrinter\Standard; - return $service; - } - - - public function createServiceContainer(): Nette\DI\Container - { - return $this; - } - - - public function createServiceRules__0(): PHPStan\Rules\Symfony\ContainerInterfacePrivateServiceRule - { - $service = new PHPStan\Rules\Symfony\ContainerInterfacePrivateServiceRule($this->getService('4')); - return $service; - } - - - public function createServiceRules__1(): PHPStan\Rules\Symfony\ContainerInterfaceUnknownServiceRule - { - $service = new PHPStan\Rules\Symfony\ContainerInterfaceUnknownServiceRule($this->getService('4'), $this->getService('3_PhpParser_PrettyPrinter_Standard')); - return $service; - } - - - public function createServiceSymfony__serviceMapFactory(): PHPStan\Symfony\ServiceMapFactory - { - $service = new PHPStan\Symfony\XmlServiceMapFactory(''); - return $service; - } - - - public function createService__4(): PHPStan\Symfony\ServiceMap - { - $service = new PHPStan\Symfony\ServiceMap($this->getService('symfony.serviceMapFactory')->create()); - return $service; - } - - - public function createService__6(): PHPStan\Type\Symfony\RequestDynamicReturnTypeExtension - { - $service = new PHPStan\Type\Symfony\RequestDynamicReturnTypeExtension; - return $service; - } - - - public function createService__7(): PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension - { - $service = new PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension( - 'Symfony\Bundle\FrameworkBundle\Controller\AbstractController', - $this->getService('3_PhpParser_PrettyPrinter_Standard') - ); - return $service; - } - - - public function createService__8(): PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension - { - $service = new PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension( - 'Symfony\Bundle\FrameworkBundle\Controller\Controller', - $this->getService('3_PhpParser_PrettyPrinter_Standard') - ); - return $service; - } - - - public function createService__9(): PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension - { - $service = new PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension( - 'Symfony\Component\DependencyInjection\ContainerInterface', - $this->getService('3_PhpParser_PrettyPrinter_Standard') - ); - return $service; - } - - - public function createService__10(): PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension - { - $service = new PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension('Symfony\Bundle\FrameworkBundle\Controller\AbstractController', true, $this->getService('4')); - return $service; - } - - - public function createService__11(): PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension - { - $service = new PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension('Symfony\Bundle\FrameworkBundle\Controller\Controller', true, $this->getService('4')); - return $service; - } - - - public function createService__12(): PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension - { - $service = new PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension('Symfony\Component\DependencyInjection\ContainerInterface', true, $this->getService('4')); - return $service; - } - - - public function initialize() - { - } -} diff --git a/tests/Symfony/NeonTest.php b/tests/Symfony/NeonTest.php index 5e9f6dd4..ad73f9a0 100644 --- a/tests/Symfony/NeonTest.php +++ b/tests/Symfony/NeonTest.php @@ -22,13 +22,24 @@ public function testExtensionNeon(): void @unlink($generatedContainer); self::assertFileNotExists($generatedContainer); - $loader->load(function (Compiler $compiler): void { + $class = $loader->load(function (Compiler $compiler): void { $compiler->addExtension('rules', new RulesExtension()); $compiler->loadConfig(__DIR__ . '/config.neon'); $compiler->loadConfig(__DIR__ . '/../../extension.neon'); }, $key); - - self::assertFileEquals(__DIR__ . '/ExampleContainer.php', $generatedContainer); + /** @var \Nette\DI\Container $container */ + $container = new $class(); + + self::assertSame([ + 'symfony' => [ + 'container_xml_path' => '', + 'constant_hassers' => true, + ], + ], $container->getParameters()); + + self::assertCount(2, $container->findByTag('phpstan.rules.rule')); + self::assertCount(4, $container->findByTag('phpstan.broker.dynamicMethodReturnTypeExtension')); + self::assertCount(3, $container->findByTag('phpstan.typeSpecifier.methodTypeSpecifyingExtension')); } } diff --git a/tests/Type/Symfony/ExtensionTestCase.php b/tests/Type/Symfony/ExtensionTestCase.php index d5bc09fe..9cd9d2a6 100644 --- a/tests/Type/Symfony/ExtensionTestCase.php +++ b/tests/Type/Symfony/ExtensionTestCase.php @@ -10,14 +10,12 @@ use PHPStan\Broker\AnonymousClassNameHelper; use PHPStan\Cache\Cache; use PHPStan\File\FileHelper; -use PHPStan\File\RelativePathHelper; use PHPStan\PhpDoc\PhpDocStringResolver; use PHPStan\PhpDoc\TypeNodeResolver; use PHPStan\Testing\TestCase; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\FileTypeMapper; use PHPStan\Type\VerbosityLevel; -use const DIRECTORY_SEPARATOR; abstract class ExtensionTestCase extends TestCase { @@ -41,13 +39,13 @@ protected function processFile( $resolver = new NodeScopeResolver( $broker, $parser, - new FileTypeMapper( + new FileTypeMapper(...[ // PHPStan commit 7b23c31 broke the constructor so we have to use splat here $parser, $phpDocStringResolver, $this->createMock(Cache::class), - new AnonymousClassNameHelper($fileHelper, new RelativePathHelper($currentWorkingDirectory, DIRECTORY_SEPARATOR, [])), - $typeNodeResolver - ), + $this->createMock(AnonymousClassNameHelper::class), // PHPStan commit 4fcdccc broke the helper so we have to use a mock here + $typeNodeResolver, + ]), $fileHelper, $typeSpecifier, true, @@ -66,7 +64,7 @@ function (Node $node, Scope $scope) use ($expression, $type, &$run): void { } /** @var \PhpParser\Node\Stmt\Expression $expNode */ $expNode = $this->getParser()->parseString(sprintf('getType($expNode->expr)->describe(VerbosityLevel::precise())); + self::assertSame($type, $scope->getType($expNode->expr)->describe(VerbosityLevel::typeOnly())); $run = true; } );