diff --git a/composer.json b/composer.json index aafd1576..b26d6cd5 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,9 @@ "require-dev": { "humbug/humbug": "dev-master@dev", "mikey179/vfsStream": "^1.6", - "phpstan/phpstan": "^0.9.0@dev", - "phpunit/phpunit": "^6.4", + "phpstan/phpstan": "^0.9", + "phpstan/phpstan-phpunit": "^0.9", + "phpunit/phpunit": "^6.5", "squizlabs/php_codesniffer": "^3.1", "symfony/proxy-manager-bridge": "^3.3|^4.0", "symfony/yaml": "^3.3|^4.0" diff --git a/phpstan.neon b/phpstan.neon index e3848282..18c6d6d7 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,2 @@ -parameters: - ignoreErrors: - # Ignore PHPUnit mock stuff - - '#PHPUnit\\Framework\\MockObject\\MockObject.* given#' - - '#PHPUnit\\Framework\\MockObject\\MockObject::.*\(\)#' +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/src/Compiler.php b/src/Compiler.php index 759db2a4..30f2e099 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -73,8 +73,12 @@ private function updateDump( ): void { $container->compile(); + $options = $config->getDumpOptions(); + $options['file'] = $dump->getPath(); + $options['debug'] = $container->getParameter('app.devmode'); + $dump->write( - $this->getDumper($container)->dump($config->getDumpOptions()), + $this->getDumper($container)->dump($options), $container->getResources() ); } diff --git a/src/Config/ContainerConfiguration.php b/src/Config/ContainerConfiguration.php index ab3f4db4..baf01d74 100644 --- a/src/Config/ContainerConfiguration.php +++ b/src/Config/ContainerConfiguration.php @@ -202,6 +202,8 @@ public function getDumpOptions(): array $options['base_class'] = $this->baseClass; } + $options['hot_path_tag'] = 'container.hot_path'; + return $options; } } diff --git a/src/ContainerBuilder.php b/src/ContainerBuilder.php index 8c3c856d..b31585a5 100644 --- a/src/ContainerBuilder.php +++ b/src/ContainerBuilder.php @@ -55,6 +55,7 @@ public function __construct( private function setDefaultConfiguration(): void { $this->parameterBag->set('app.devmode', false); + $this->parameterBag->set('container.dumper.inline_class_loader', true); $this->config->addPass($this->parameterBag); } @@ -102,6 +103,7 @@ public function addPackage(string $className, array $constructArguments = []): B public function useDevelopmentMode(): Builder { $this->parameterBag->set('app.devmode', true); + $this->parameterBag->set('container.dumper.inline_class_loader', false); return $this; } diff --git a/test/Config/ContainerConfigurationTest.php b/test/Config/ContainerConfigurationTest.php index b568d0a5..70c319ff 100644 --- a/test/Config/ContainerConfigurationTest.php +++ b/test/Config/ContainerConfigurationTest.php @@ -391,9 +391,12 @@ public function getDumpFileCanAlsoAddPrefixForTheFile(): void public function getDumpOptionsShouldReturnTheDumpingInformation(): void { $config = new ContainerConfiguration(); - $options = ['class' => 'Project' . md5('') . 'ServiceContainer']; + $options = [ + 'class' => 'Project' . md5('') . 'ServiceContainer', + 'hot_path_tag' => 'container.hot_path', + ]; - self::assertEquals($options, $config->getDumpOptions()); + self::assertSame($options, $config->getDumpOptions()); } /** @@ -409,8 +412,13 @@ public function getDumpOptionsShouldIncludeBaseWhenWasConfigured(): void { $config = new ContainerConfiguration(); $config->setBaseClass('Test'); - $options = ['class' => 'Project' . md5('') . 'ServiceContainer', 'base_class' => 'Test']; - self::assertEquals($options, $config->getDumpOptions()); + $options = [ + 'class' => 'Project' . md5('') . 'ServiceContainer', + 'base_class' => 'Test', + 'hot_path_tag' => 'container.hot_path', + ]; + + self::assertSame($options, $config->getDumpOptions()); } } diff --git a/test/GeneratorTest.php b/test/GeneratorTest.php index d1fb9d3f..dbaee092 100644 --- a/test/GeneratorTest.php +++ b/test/GeneratorTest.php @@ -3,11 +3,13 @@ namespace Lcobucci\DependencyInjection; +use Lcobucci\DependencyInjection\Compiler\ParameterBag; use Lcobucci\DependencyInjection\Config\ContainerConfiguration; use org\bovigo\vfs\vfsStream; use stdClass; use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; @@ -67,6 +69,7 @@ public function constructShouldCreateACompilerWhenNotInformed(): void * @uses \Lcobucci\DependencyInjection\Generator::__construct * @uses \Lcobucci\DependencyInjection\Config\ContainerConfiguration * @uses \Lcobucci\DependencyInjection\Compiler + * @uses \Lcobucci\DependencyInjection\Compiler\ParameterBag */ public function generateShouldCompileAndLoadTheContainer(): void { @@ -76,8 +79,12 @@ public function generateShouldCompileAndLoadTheContainer(): void ['services.yml' => 'services: { testing: { class: stdClass, public: true } }'] ); - $config = new ContainerConfiguration([vfsStream::url('tests/services.yml')]); - $dump = new ConfigCache(vfsStream::url('tests/container.php'), false); + $config = new ContainerConfiguration( + [vfsStream::url('tests/services.yml')], + [[new ParameterBag(['app.devmode' => true]), PassConfig::TYPE_BEFORE_OPTIMIZATION]] + ); + + $dump = new ConfigCache(vfsStream::url('tests/container.php'), false); $this->generator->method('getLoader')->willReturnCallback( function (SymfonyBuilder $container, array $paths) {