Skip to content

Commit

Permalink
Forward compatibility - define parameters schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 13, 2019
1 parent 2ce274c commit fcaef71
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
"require": {
"php": "^7.1",
"ext-simplexml": "*",
"phpstan/phpstan": "^0.11.4",
"phpstan/phpstan": "^0.11.7",
"nikic/php-parser": "^4.0"
},
"require-dev": {
"consistence/coding-standard": "^3.0.1",
"jakub-onderka/php-parallel-lint": "^1.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
"nette/di": "^3.0-stable",
"phpunit/phpunit": "^7.0",
"phing/phing": "^2.16.0",
"phpstan/phpstan-strict-rules": "^0.11",
Expand Down
7 changes: 7 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ parameters:
constant_hassers: true
console_application_loader: null

parametersSchema:
symfony: structure([
container_xml_path: schema(string(), nullable())
constant_hassers: bool()
console_application_loader: schema(string(), nullable())
])

rules:
- PHPStan\Rules\Symfony\ContainerInterfacePrivateServiceRule
- PHPStan\Rules\Symfony\ContainerInterfaceUnknownServiceRule
Expand Down
7 changes: 6 additions & 1 deletion tests/Symfony/NeonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Nette\DI\Compiler;
use Nette\DI\ContainerLoader;
use PHPStan\DependencyInjection\ParametersSchemaExtension;
use PHPStan\DependencyInjection\RulesExtension;
use PHPUnit\Framework\TestCase;
use function sprintf;
Expand All @@ -24,21 +25,25 @@ public function testExtensionNeon(): void

$class = $loader->load(function (Compiler $compiler): void {
$compiler->addExtension('rules', new RulesExtension());
$compiler->addExtension('parametersSchema', new ParametersSchemaExtension());
$compiler->addConfig(['parameters' => ['rootDir' => __DIR__]]);
$compiler->loadConfig(__DIR__ . '/../../extension.neon');
$compiler->loadConfig(__DIR__ . '/config.neon');
}, $key);
/** @var \Nette\DI\Container $container */
$container = new $class();

$parameters = $container->getParameters();
unset($parameters['__parametersSchema']);

self::assertSame([
'rootDir' => __DIR__,
'symfony' => [
'container_xml_path' => __DIR__ . '/container.xml',
'constant_hassers' => true,
'console_application_loader' => null,
],
], $container->getParameters());
], $parameters);

self::assertCount(6, $container->findByTag('phpstan.rules.rule'));
self::assertCount(11, $container->findByTag('phpstan.broker.dynamicMethodReturnTypeExtension'));
Expand Down

0 comments on commit fcaef71

Please sign in to comment.