mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 14:03:27 +00:00
Add more tests
This commit is contained in:
@@ -55,9 +55,9 @@ php:
|
||||
- 5.5
|
||||
|
||||
script:
|
||||
- bin/setup assets:compile-less
|
||||
- bin/setup assets:build-javascript
|
||||
- bin/setup system:upgrade -y -v -f
|
||||
- php hudson/cleanupSubdefs.php
|
||||
- bin/developer assets:compile-less
|
||||
- bin/developer assets:build-javascript
|
||||
- sh tests/js/run.sh
|
||||
- bin/phpunit
|
||||
|
@@ -18,7 +18,7 @@ use Symfony\Component\Process\ProcessBuilder;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
|
||||
/**
|
||||
* This command builds less file
|
||||
* This command builds javascript files
|
||||
*/
|
||||
class JavascriptBuilder extends Command
|
||||
{
|
||||
|
@@ -55,7 +55,7 @@ class LessCompiler extends Command
|
||||
try {
|
||||
$this->container['phraseanet.less-builder']->build($files);
|
||||
} 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;
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ abstract class AbstractPluginCommand extends Command
|
||||
$this->container['phraseanet.less-builder']->build($files);
|
||||
$output->writeln(" <comment>OK</comment>");
|
||||
} 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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -35,6 +35,8 @@ class Builder
|
||||
* Build LESS files
|
||||
*
|
||||
* @param array $files
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function build($files)
|
||||
{
|
||||
|
@@ -15,7 +15,6 @@ use Alchemy\Phrasea\Application;
|
||||
use Alchemy\BinaryDriver\BinaryInterface;
|
||||
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class Compiler
|
||||
@@ -52,19 +51,19 @@ class Compiler
|
||||
$files = new \ArrayObject(is_array($files) ? $files : array($files));
|
||||
}
|
||||
|
||||
$files = new ArrayCollection((array) $files);
|
||||
$files = (array) $files;
|
||||
|
||||
if ($files->forAll(function($file) {
|
||||
return is_file($file);
|
||||
})) {
|
||||
throw new RuntimeException($files . ' does not exists.');
|
||||
foreach($files as $file) {
|
||||
if (false === is_file($file)) {
|
||||
throw new RuntimeException($file . ' does not exists.');
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_writable(dirname($target))) {
|
||||
throw new RuntimeException(realpath(dirname($target)) . ' is not writable.');
|
||||
}
|
||||
|
||||
$commands = $files->toArray();
|
||||
$commands = $files;
|
||||
array_unshift($commands, '--compile');
|
||||
|
||||
try {
|
||||
|
@@ -12,8 +12,9 @@
|
||||
namespace Alchemy\Tests\Phrasea\Utilities\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()
|
||||
{
|
||||
@@ -28,4 +29,42 @@ class CompilerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$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__);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user