Skip to content

Commit

Permalink
Add tests for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Eckerstorfer committed Nov 10, 2013
1 parent 89ce671 commit ad31350
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 0 deletions.
1 change: 1 addition & 0 deletions BraincraftedBootstrapBundle.php
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of BraincraftedBootstrapBundle.
*
Expand Down
18 changes: 18 additions & 0 deletions Command/GenerateCommand.php
@@ -1,15 +1,33 @@
<?php

/**
* This file is part of BraincraftedBootstrapBundle.
*
* (c) 2012-2013 by Florian Eckerstorfer
*/

namespace Braincrafted\Bundle\BootstrapBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* GenerateCommand
*
* @package BraincraftedBootstrapBundle
* @subpackage Command
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @copyright 2012-2013 Florian Eckerstorfer
* @license http://opensource.org/licenses/MIT The MIT License
* @link http://bootstrap.braincrafted.com BraincraftedBootstrapBundle
*/
class GenerateCommand extends ContainerAwareCommand
{
/**
* {@inheritDoc}
*
* @codeCoverageIgnore
*/
protected function configure()
{
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -4,6 +4,7 @@
By [Florian Eckerstorfer](http://florianeckerstorfer.com)

[![Build Status](https://secure.travis-ci.org/braincrafted/bootstrap-bundle.png)](http://travis-ci.org/braincrafted/bootstrap-bundle)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/braincrafted/bootstrap-bundle/badges/quality-score.png?s=28e07378182fddc3cdf2c764437a72b6eaf55a45)](https://scrutinizer-ci.com/g/braincrafted/bootstrap-bundle/)


About
Expand Down
131 changes: 131 additions & 0 deletions Tests/Command/GenerateCommandTest.php
@@ -0,0 +1,131 @@
<?php

/**
* This file is part of BraincraftedBootstrapBundle.
*
* (c) 2012-2013 by Florian Eckerstorfer
*/

namespace Braincrafted\Bundle\BootstrapBundle\Tests\Command;

use \Mockery as m;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Bundle\FrameworkBundle\Console\Application;

use Braincrafted\Bundle\BootstrapBundle\Command\GenerateCommand;

/**
* GenerateCommandTest
*
* @category Test
* @package BraincraftedBootstrapBundle
* @subpackage Command
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @copyright 2012-2013 Florian Eckerstorfer
* @license http://opensource.org/licenses/MIT The MIT License
* @link http://bootstrap.braincrafted.com BraincraftedBootstrapBundle
* @group unit
*/
class GenerateCommandTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->twig = m::mock('\Twig_Environment');

$this->container = m::mock('Symfony\Component\DependencyInjection\ContainerInterface');
$this->container->shouldReceive('get')->with('twig')->andReturn($this->twig);

$this->kernel = m::mock('Symfony\Component\HttpKernel\KernelInterface');
$this->kernel->shouldReceive('getName')->andReturn('app');
$this->kernel->shouldReceive('getEnvironment')->andReturn('prod');
$this->kernel->shouldReceive('isDebug')->andReturn(false);
$this->kernel->shouldReceive('getContainer')->andReturn($this->container);
}

public function tearDown()
{
if (true === file_exists(sprintf('%s/bootstrap.less', __DIR__))) {
unlink(sprintf('%s/bootstrap.less', __DIR__));
}
}

/**
* @covers Braincrafted\Bundle\BootstrapBundle\Command\GenerateCommand::execute()
* @covers Braincrafted\Bundle\BootstrapBundle\Command\GenerateCommand::executeGenerateBootstrap()
* @covers Braincrafted\Bundle\BootstrapBundle\Command\GenerateCommand::getRelativePath()
*/
public function testExecute()
{
$this->container
->shouldReceive('getParameter')
->with('braincrafted_bootstrap.customize_variables')
->andReturn(array(
'variables_file' => __DIR__.'/x/variables.less',
'bootstrap_output' => __DIR__.'/bootstrap.less',
'bootstrap_template' => __DIR__.'/bootstrap.html.twig'
));
$this->container->shouldReceive('getParameter')->with('braincrafted_bootstrap.less_filter')->andReturn('less');
$this->container->shouldReceive('getParameter')->with('braincrafted_bootstrap.assets_dir')->andReturn(__DIR__);

$this->twig
->shouldReceive('render')
->with(__DIR__.'/bootstrap.html.twig', array(
'variables_file' => './x/variables.less',
'assets_dir' => ''
));

// mock the Kernel or create one depending on your needs
$application = new Application($this->kernel);
$application->add(new GenerateCommand());

$command = $application->find('braincrafted:bootstrap:generate');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));

$this->assertRegExp('/Found custom variables file/', $commandTester->getDisplay());
$this->assertRegExp('/bootstrap\.less/', $commandTester->getDisplay());
}

/**
* @covers Braincrafted\Bundle\BootstrapBundle\Command\GenerateCommand::execute()
*/
public function testExecuteNoVariablesFile()
{
$this->container
->shouldReceive('getParameter')
->with('braincrafted_bootstrap.customize_variables')
->andReturn(array('variables_file' => null));

// mock the Kernel or create one depending on your needs
$application = new Application($this->kernel);
$application->add(new GenerateCommand());

$command = $application->find('braincrafted:bootstrap:generate');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));

$this->assertRegExp('/Found no custom variables\.less file/', $commandTester->getDisplay());
}

/**
* @covers Braincrafted\Bundle\BootstrapBundle\Command\GenerateCommand::execute()
*/
public function testExecuteNoLessFilter()
{
$this->container
->shouldReceive('getParameter')
->with('braincrafted_bootstrap.customize_variables')
->andReturn(array('variables_file' => __DIR__.'/x/variables.less'));
$this->container->shouldReceive('getParameter')->with('braincrafted_bootstrap.less_filter')->andReturn('none');

// mock the Kernel or create one depending on your needs
$application = new Application($this->kernel);
$application->add(new GenerateCommand());

$command = $application->find('braincrafted:bootstrap:generate');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));

$this->assertRegExp('/configured with "less" or "lessphp"/', $commandTester->getDisplay());
}
}
95 changes: 95 additions & 0 deletions Tests/Command/InstallCommandTest.php
@@ -0,0 +1,95 @@
<?php

/**
* This file is part of BraincraftedBootstrapBundle.
*
* (c) 2012-2013 by Florian Eckerstorfer
*/

namespace Braincrafted\Bundle\BootstrapBundle\Tests\Command;

use \Mockery as m;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Bundle\FrameworkBundle\Console\Application;

use Braincrafted\Bundle\BootstrapBundle\Command\InstallCommand;

/**
* InstallCommandTest
*
* @category Test
* @package BraincraftedBootstrapBundle
* @subpackage Command
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @copyright 2012-2013 Florian Eckerstorfer
* @license http://opensource.org/licenses/MIT The MIT License
* @link http://bootstrap.braincrafted.com BraincraftedBootstrapBundle
* @group unit
*/
class InstallCommandTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->container = m::mock('Symfony\Component\DependencyInjection\ContainerInterface');

$this->kernel = m::mock('Symfony\Component\HttpKernel\KernelInterface');
$this->kernel->shouldReceive('getName')->andReturn('app');
$this->kernel->shouldReceive('getEnvironment')->andReturn('prod');
$this->kernel->shouldReceive('isDebug')->andReturn(false);
$this->kernel->shouldReceive('getContainer')->andReturn($this->container);
}

public function tearDown()
{
$file = sprintf('%s/fixtures/web/fonts/font1.txt', __DIR__);
if (true === file_exists($file)) {
unlink($file);
}
}

/**
* @covers Braincrafted\Bundle\BootstrapBundle\Command\InstallCommand::execute()
* @covers Braincrafted\Bundle\BootstrapBundle\Command\InstallCommand::getSrcDir()
* @covers Braincrafted\Bundle\BootstrapBundle\Command\InstallCommand::getDestDir()
*/
public function testExecute()
{
$this->container
->shouldReceive('getParameter')
->with('kernel.root_dir')
->andReturn(__DIR__.'/fixtures/app');

// mock the Kernel or create one depending on your needs
$application = new Application($this->kernel);
$application->add(new InstallCommand());

$command = $application->find('braincrafted:bootstrap:install');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));

$this->assertRegExp('/Copied Glyphicon fonts/', $commandTester->getDisplay());
}

/**
* @covers Braincrafted\Bundle\BootstrapBundle\Command\InstallCommand::execute()
* @covers Braincrafted\Bundle\BootstrapBundle\Command\InstallCommand::getSrcDir()
* @covers Braincrafted\Bundle\BootstrapBundle\Command\InstallCommand::getDestDir()
*/
public function testExecuteInvalidDestDirectory()
{
$this->container
->shouldReceive('getParameter')
->with('kernel.root_dir')
->andReturn(__DIR__.'/invalid/app');

// mock the Kernel or create one depending on your needs
$application = new Application($this->kernel);
$application->add(new InstallCommand());

$command = $application->find('braincrafted:bootstrap:install');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));

$this->assertRegExp('/Could not create directory/', $commandTester->getDisplay());
}
}
Empty file.

0 comments on commit ad31350

Please sign in to comment.