Skip to content

Commit

Permalink
Merge pull request #301 from mumia/issue300/generatorFailsForCustomVa…
Browse files Browse the repository at this point in the history
…riable.less

Proposal for fixing custom bootstrap.less generator
  • Loading branch information
Florian Eckerstorfer committed Sep 18, 2014
2 parents 5623159 + 6df8f5a commit f4ba62a
Show file tree
Hide file tree
Showing 3 changed files with 40 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
29 changes: 29 additions & 0 deletions Tests/Command/GenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;

use Braincrafted\Bundle\BootstrapBundle\Command\GenerateCommand;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelInterface;

/**
* GenerateCommandTest
Expand All @@ -28,6 +31,21 @@
*/
class GenerateCommandTest extends \PHPUnit_Framework_TestCase
{
/**
* @var m\Mock|\Twig_Environment
*/
private $twig;

/**
* @var m\Mock|ContainerInterface
*/
private $container;

/**
* @var m\Mock|KernelInterface
*/
private $kernel;

public function setUp()
{
$this->twig = m::mock('\Twig_Environment');
Expand Down Expand Up @@ -66,6 +84,17 @@ 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',
\Mockery::type('Symfony\Component\HttpFoundation\Request'),
'request'
)
);
}

$this->twig
->shouldReceive('render')
->with(__DIR__.'/bootstrap.html.twig', array(
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 f4ba62a

Please sign in to comment.