Skip to content

Commit

Permalink
Add empty request to container on symfony 2.5 or above
Browse files Browse the repository at this point in the history
  • Loading branch information
mumia committed Sep 17, 2014
1 parent 5623159 commit e7e4321
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Symfony\Component\Console\Output\OutputInterface;

use Braincrafted\Bundle\BootstrapBundle\Util\PathUtil;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Kernel;

/**
* GenerateCommand
Expand Down Expand Up @@ -100,8 +102,15 @@ protected function executeGenerateBootstrap(array $config)
basename($config['variables_file'])
);

$container = $this->getContainer();

if (Kernel::VERSION_ID >= 20500) {
$container->enterScope('request');
$container->set('request', new Request(), 'request');
}

// We can now use Twig to render the bootstrap.less file and save it
$content = $this->getContainer()->get('twig')->render(
$content = $container->get('twig')->render(
$config['bootstrap_template'],
array(
'variables_file' => $variablesFile,
Expand Down
6 changes: 6 additions & 0 deletions Tests/Command/GenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;

use Braincrafted\Bundle\BootstrapBundle\Command\GenerateCommand;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Kernel;

/**
* GenerateCommandTest
Expand Down Expand Up @@ -65,6 +67,10 @@ public function testExecute()
));
$this->container->shouldReceive('getParameter')->with('braincrafted_bootstrap.less_filter')->andReturn('less');
$this->container->shouldReceive('getParameter')->with('braincrafted_bootstrap.assets_dir')->andReturn(__DIR__);
if (Kernel::VERSION_ID >= 20500) {
$this->container->shouldReceive('enterScope')->with('request');
$this->container->shouldReceive('set')->withArgs(array('request', new Request(), 'request'));
}

$this->twig
->shouldReceive('render')
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"knplabs/knp-menu-bundle": "~2.0@alpha",
"knplabs/knp-paginator-bundle": "dev-master",
"phpunit/phpunit": "3.7.*",
"mockery/mockery": "0.8.*"
"mockery/mockery": "0.9.*"
},
"suggest": {
"knplabs/knp-paginator-bundle": "BraincraftedBootstrapBundle styles the pagination provided by KnpPaginatorBundle.",
Expand Down

0 comments on commit e7e4321

Please sign in to comment.