Skip to content

Commit

Permalink
Merge pull request #7 from lcobucci/fix/hotpath-compatibility
Browse files Browse the repository at this point in the history
Fix hotpath compatibility
  • Loading branch information
lcobucci authored Dec 11, 2017
2 parents e1ca26d + 50171b4 commit 8f64e1b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 2 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Config/ContainerConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public function getDumpOptions(): array
$options['base_class'] = $this->baseClass;
}

$options['hot_path_tag'] = 'container.hot_path';

return $options;
}
}
2 changes: 2 additions & 0 deletions src/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 12 additions & 4 deletions test/Config/ContainerConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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());
}
}
11 changes: 9 additions & 2 deletions test/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -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) {
Expand Down

0 comments on commit 8f64e1b

Please sign in to comment.