Add more tests

This commit is contained in:
Nicolas Le Goff
2013-07-10 12:48:57 +02:00
parent 5b0bc8b284
commit 577aed3ed8
12 changed files with 59 additions and 19 deletions

View File

@@ -55,9 +55,9 @@ php:
- 5.5 - 5.5
script: script:
- bin/setup assets:compile-less
- bin/setup assets:build-javascript
- bin/setup system:upgrade -y -v -f - bin/setup system:upgrade -y -v -f
- php hudson/cleanupSubdefs.php - php hudson/cleanupSubdefs.php
- bin/developer assets:compile-less
- bin/developer assets:build-javascript
- sh tests/js/run.sh - sh tests/js/run.sh
- bin/phpunit - bin/phpunit

View File

@@ -18,7 +18,7 @@ use Symfony\Component\Process\ProcessBuilder;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\RuntimeException;
/** /**
* This command builds less file * This command builds javascript files
*/ */
class JavascriptBuilder extends Command class JavascriptBuilder extends Command
{ {

View File

@@ -55,7 +55,7 @@ class LessCompiler extends Command
try { try {
$this->container['phraseanet.less-builder']->build($files); $this->container['phraseanet.less-builder']->build($files);
} catch (RuntimeException $e) { } catch (RuntimeException $e) {
$output->writeln(sprintf('<error>Could not build less files %s</error>', implode(', ', $e->getMessage()))); $output->writeln(sprintf('<error>Could not build less files %s</error>', $e->getMessage()));
return 1; return 1;
} }

View File

@@ -44,12 +44,12 @@ abstract class AbstractPluginCommand extends Command
); );
$output->write('Building Assets...'); $output->write('Building Assets...');
try { try {
$this->container['phraseanet.less-builder']->build($files); $this->container['phraseanet.less-builder']->build($files);
$output->writeln(" <comment>OK</comment>"); $output->writeln(" <comment>OK</comment>");
} catch (RuntimeException $e) { } catch (RuntimeException $e) {
$output->writeln(sprintf('<error>Could not build less files %s</error>', implode(', ', $e->getMessage()))); $output->writeln(sprintf('<error>Could not build less files %s</error>', $e->getMessage()));
} }
} }
} }

View File

@@ -27,4 +27,4 @@ class LessCompilerServiceProvider implements ServiceProviderInterface
public function boot(Application $app) public function boot(Application $app)
{ {
} }
} }

View File

@@ -35,6 +35,8 @@ class Builder
* Build LESS files * Build LESS files
* *
* @param array $files * @param array $files
*
* @throws RuntimeException
*/ */
public function build($files) public function build($files)
{ {

View File

@@ -15,7 +15,6 @@ use Alchemy\Phrasea\Application;
use Alchemy\BinaryDriver\BinaryInterface; use Alchemy\BinaryDriver\BinaryInterface;
use Alchemy\BinaryDriver\Exception\ExecutionFailureException; use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\RuntimeException;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
class Compiler class Compiler
@@ -52,19 +51,19 @@ class Compiler
$files = new \ArrayObject(is_array($files) ? $files : array($files)); $files = new \ArrayObject(is_array($files) ? $files : array($files));
} }
$files = new ArrayCollection((array) $files); $files = (array) $files;
if ($files->forAll(function($file) { foreach($files as $file) {
return is_file($file); if (false === is_file($file)) {
})) { throw new RuntimeException($file . ' does not exists.');
throw new RuntimeException($files . ' does not exists.'); }
} }
if (!is_writable(dirname($target))) { if (!is_writable(dirname($target))) {
throw new RuntimeException(realpath(dirname($target)) . ' is not writable.'); throw new RuntimeException(realpath(dirname($target)) . ' is not writable.');
} }
$commands = $files->toArray(); $commands = $files;
array_unshift($commands, '--compile'); array_unshift($commands, '--compile');
try { try {

View File

@@ -1 +1 @@
@import "my-plugin/account.less"; @import "my-plugin/account.less";

View File

@@ -1 +1 @@
@import "my-plugin/login.less"; @import "my-plugin/login.less";

View File

@@ -1 +1 @@
@import "my-plugin/account.less"; @import "my-plugin/account.less";

View File

@@ -1 +1 @@
@import "my-plugin/login.less"; @import "my-plugin/login.less";

View File

@@ -12,8 +12,9 @@
namespace Alchemy\Tests\Phrasea\Utilities\Compiler; namespace Alchemy\Tests\Phrasea\Utilities\Compiler;
use Alchemy\Phrasea\Utilities\Less\Compiler; use Alchemy\Phrasea\Utilities\Less\Compiler;
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
class CompilerTest extends \PHPUnit_Framework_TestCase class CompilerTest extends \PhraseanetPHPUnitAbstract
{ {
public function testCompileSuccess() public function testCompileSuccess()
{ {
@@ -28,4 +29,42 @@ class CompilerTest extends \PHPUnit_Framework_TestCase
$compiler->compile(__DIR__ . '/output.css', __FILE__); $compiler->compile(__DIR__ . '/output.css', __FILE__);
} }
public function testCreate()
{
$compiler = Compiler::create(self::$DI['app']);
$this->assertInstanceOf('Alchemy\Phrasea\Utilities\Less\Compiler', $compiler);
}
/**
* @expectedException Alchemy\Phrasea\Exception\RuntimeException
*/
public function testCompileFileNotExists()
{
$recessDriver = $this->getMock('Alchemy\BinaryDriver\BinaryInterface');
$filesystem = $this->getMock('Symfony\Component\Filesystem\Filesystem');
$filesystem->expects($this->once())->method('mkdir');
$compiler = new Compiler($filesystem, $recessDriver);
$compiler->compile(__DIR__ . '/output.css', 'not_existsing_file');
}
/**
* @expectedException Alchemy\Phrasea\Exception\RuntimeException
*/
public function testCompileExecutionFailure()
{
$recessDriver = $this->getMock('Alchemy\BinaryDriver\BinaryInterface');
$recessDriver->expects($this->once())->method('command')->will(
$this->throwException(new ExecutionFailureException())
);
$filesystem = $this->getMock('Symfony\Component\Filesystem\Filesystem');
$compiler = new Compiler($filesystem, $recessDriver);
$compiler->compile(__DIR__ . '/output.css', __FILE__);
}
} }