Skip to content

Commit aa3f563

Browse files
committed
Fixed compatibility with prefixed PHPStan PHAR in NeonTest
1 parent b34aef6 commit aa3f563

File tree

4 files changed

+23
-53
lines changed

4 files changed

+23
-53
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"consistence/coding-standard": "^3.0.1",
3434
"jakub-onderka/php-parallel-lint": "^1.0",
3535
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
36-
"nette/di": "^3.0-stable",
3736
"phpunit/phpunit": "^7.0",
3837
"phing/phing": "^2.16.0",
3938
"phpstan/phpstan-strict-rules": "^0.12",

tests/Symfony/NeonTest.php

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,36 @@
22

33
namespace PHPStan\Symfony;
44

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;
96
use PHPUnit\Framework\TestCase;
10-
use function sprintf;
11-
use function unlink;
127

138
final class NeonTest extends TestCase
149
{
1510

1611
public function testExtensionNeon(): void
1712
{
18-
$key = '';
1913
$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',
3619

20+
], []);
3721
$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'));
5235
self::assertInstanceOf(ServiceMap::class, $container->getByType(ServiceMap::class));
5336
}
5437

tests/Symfony/config.neon

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
parameters:
22
symfony:
3-
container_xml_path: %rootDir%/container.xml
4-
5-
services:
6-
- PhpParser\PrettyPrinter\Standard
7-
8-
-
9-
class: PHPStan\DependencyInjection\Container
10-
factory: PHPStan\DependencyInjection\Nette\NetteContainer
11-
12-
broker:
13-
class: PHPStan\Broker\Broker
14-
factory: @brokerFactory::create
15-
16-
brokerFactory:
17-
class: PHPStan\Broker\BrokerFactory
3+
container_xml_path: container.xml

tests/Type/Symfony/ExtensionTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Cache\Cache;
1212
use PHPStan\File\FileHelper;
1313
use PHPStan\Node\VirtualNode;
14+
use PHPStan\PhpDoc\PhpDocNodeResolver;
1415
use PHPStan\PhpDoc\PhpDocStringResolver;
1516
use PHPStan\PhpDoc\TypeNodeResolver;
1617
use PHPStan\Testing\TestCase;
@@ -43,6 +44,7 @@ protected function processFile(
4344
new FileTypeMapper(
4445
$parser,
4546
$phpDocStringResolver,
47+
self::getContainer()->getByType(PhpDocNodeResolver::class),
4648
$this->createMock(Cache::class),
4749
$this->createMock(AnonymousClassNameHelper::class),
4850
$typeNodeResolver

0 commit comments

Comments
 (0)