diff --git a/.travis.yml b/.travis.yml index 9d6ca74dd9..40a4879bc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/lib/Alchemy/Phrasea/Command/Developer/JavascriptBuilder.php b/lib/Alchemy/Phrasea/Command/Developer/JavascriptBuilder.php index a51dd62197..b0b2208891 100644 --- a/lib/Alchemy/Phrasea/Command/Developer/JavascriptBuilder.php +++ b/lib/Alchemy/Phrasea/Command/Developer/JavascriptBuilder.php @@ -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 { diff --git a/lib/Alchemy/Phrasea/Command/Developer/LessCompiler.php b/lib/Alchemy/Phrasea/Command/Developer/LessCompiler.php index 7a59c8ef21..fcb0a9ddda 100644 --- a/lib/Alchemy/Phrasea/Command/Developer/LessCompiler.php +++ b/lib/Alchemy/Phrasea/Command/Developer/LessCompiler.php @@ -55,7 +55,7 @@ class LessCompiler extends Command try { $this->container['phraseanet.less-builder']->build($files); } catch (RuntimeException $e) { - $output->writeln(sprintf('Could not build less files %s', implode(', ', $e->getMessage()))); + $output->writeln(sprintf('Could not build less files %s', $e->getMessage())); return 1; } diff --git a/lib/Alchemy/Phrasea/Command/Plugin/AbstractPluginCommand.php b/lib/Alchemy/Phrasea/Command/Plugin/AbstractPluginCommand.php index f9b8850335..6bf7d21fd1 100644 --- a/lib/Alchemy/Phrasea/Command/Plugin/AbstractPluginCommand.php +++ b/lib/Alchemy/Phrasea/Command/Plugin/AbstractPluginCommand.php @@ -44,12 +44,12 @@ abstract class AbstractPluginCommand extends Command ); $output->write('Building Assets...'); - + try { $this->container['phraseanet.less-builder']->build($files); $output->writeln(" OK"); } catch (RuntimeException $e) { - $output->writeln(sprintf('Could not build less files %s', implode(', ', $e->getMessage()))); + $output->writeln(sprintf('Could not build less files %s', $e->getMessage())); } } } diff --git a/lib/Alchemy/Phrasea/Core/Provider/LessCompilerServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/LessCompilerServiceProvider.php index f19a829f5a..50700dbf01 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/LessCompilerServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/LessCompilerServiceProvider.php @@ -27,4 +27,4 @@ class LessCompilerServiceProvider implements ServiceProviderInterface public function boot(Application $app) { } -} \ No newline at end of file +} diff --git a/lib/Alchemy/Phrasea/Utilities/Less/Builder.php b/lib/Alchemy/Phrasea/Utilities/Less/Builder.php index 06091a07ea..9dd8c71b80 100644 --- a/lib/Alchemy/Phrasea/Utilities/Less/Builder.php +++ b/lib/Alchemy/Phrasea/Utilities/Less/Builder.php @@ -35,6 +35,8 @@ class Builder * Build LESS files * * @param array $files + * + * @throws RuntimeException */ public function build($files) { diff --git a/lib/Alchemy/Phrasea/Utilities/Less/Compiler.php b/lib/Alchemy/Phrasea/Utilities/Less/Compiler.php index f87a475638..7e7ab8c52f 100644 --- a/lib/Alchemy/Phrasea/Utilities/Less/Compiler.php +++ b/lib/Alchemy/Phrasea/Utilities/Less/Compiler.php @@ -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 { diff --git a/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDir/TestPlugin/account.less b/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDir/TestPlugin/account.less index be125cfe9f..a78f368f02 100644 --- a/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDir/TestPlugin/account.less +++ b/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDir/TestPlugin/account.less @@ -1 +1 @@ -@import "my-plugin/account.less"; \ No newline at end of file +@import "my-plugin/account.less"; diff --git a/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDir/TestPlugin/login.less b/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDir/TestPlugin/login.less index d39b765311..702702a608 100644 --- a/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDir/TestPlugin/login.less +++ b/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDir/TestPlugin/login.less @@ -1 +1 @@ -@import "my-plugin/login.less"; \ No newline at end of file +@import "my-plugin/login.less"; diff --git a/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDirInstalled/TestPlugin/account.less b/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDirInstalled/TestPlugin/account.less index be125cfe9f..a78f368f02 100644 --- a/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDirInstalled/TestPlugin/account.less +++ b/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDirInstalled/TestPlugin/account.less @@ -1 +1 @@ -@import "my-plugin/account.less"; \ No newline at end of file +@import "my-plugin/account.less"; diff --git a/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDirInstalled/TestPlugin/login.less b/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDirInstalled/TestPlugin/login.less index d39b765311..702702a608 100644 --- a/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDirInstalled/TestPlugin/login.less +++ b/tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDirInstalled/TestPlugin/login.less @@ -1 +1 @@ -@import "my-plugin/login.less"; \ No newline at end of file +@import "my-plugin/login.less"; diff --git a/tests/Alchemy/Tests/Phrasea/Utilities/Less/CompilerTest.php b/tests/Alchemy/Tests/Phrasea/Utilities/Less/CompilerTest.php index 036acd8562..19e9eb6287 100644 --- a/tests/Alchemy/Tests/Phrasea/Utilities/Less/CompilerTest.php +++ b/tests/Alchemy/Tests/Phrasea/Utilities/Less/CompilerTest.php @@ -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__); + } }