Skip to content

RC10 improved composer handler, now it accepts as well absolute paths #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/ScriptHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,26 @@ public static function generateCSS(Event $event)
static::validateConfiguration($extra);

$processor = new Processor($event->getIO());
$currentDirectory = getcwd();

foreach ($extra[static::CONFIG_MAIN_KEY] as $config) {
foreach ($config[static::OPTION_KEY_INPUT] as $value) {
$processor->attachFiles("{$currentDirectory}/{$value}", "{$currentDirectory}/{$config[static::OPTION_KEY_OUTPUT]}");
foreach ($config[static::OPTION_KEY_INPUT] as $inputSource) {
$processor->attachFiles(
static::resolvePath($inputSource, getcwd()),
static::resolvePath($config[static::OPTION_KEY_OUTPUT], getcwd())
);
}

$formatter = isset($config[static::OPTION_KEY_FORMATTER]) ? $config[static::OPTION_KEY_FORMATTER] : static::DEFAULT_OPTION_FORMATTER;

$processor->processFiles($formatter);
}
$processor->saveOutput();
}

protected static function resolvePath($path, $prefix)
{
return '/' === substr($path, 0, 1) ? $path : "{$prefix}/{$path}";
}

/**
* @param array $config
*
Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit/Processor/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ public function saveOutput()
{
$processor = new Processor($this->io);

$expectedOutputFile = $this->getRootDirectory() . '/../var/tests/' . __FUNCTION__ . '.css';
$expectedOutputFile = $this->getCacheDirectory() . '/' . __FUNCTION__ . '.css';
@unlink($expectedOutputFile);

$processor->attachFiles(
$this->getSharedFixturesDirectory() . '/scss',
$expectedOutputFile
Expand Down
47 changes: 47 additions & 0 deletions tests/phpunit/ScriptHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace EM\CssCompiler\Tests\PHPUnit;

use Composer\Composer;
use Composer\Config;
use Composer\IO\IOInterface;
use Composer\Package\RootPackage;
use Composer\Script\Event;
use EM\CssCompiler\ScriptHandler;
use EM\CssCompiler\Tests\Environment\IntegrationTestSuite;

Expand Down Expand Up @@ -148,4 +153,46 @@ private function validateOptions($config)
{
return $this->invokeMethod(new ScriptHandler(), 'validateOptions', [[$config]]);
}

/*** *************************** INTEGRATION *************************** ***/
/**
* @see ScriptHandler::generateCSS
* @test
*/
public function generateCSS()
{
$composer = (new Composer());
/** @var RootPackage|\PHPUnit_Framework_MockObject_MockObject $rootPackage */
$rootPackage = $this->getMockBuilder(RootPackage::class)
->setConstructorArgs(['css-compiler', 'dev-master', 'dev'])
->setMethods(['getExtra'])
->getMock();
/** @var IOInterface|\PHPUnit_Framework_MockObject_MockObject $io */
$io = $this->getMockBuilder(IOInterface::class)->getMock();

$output = $this->getCacheDirectory() . '/' . __FUNCTION__ . '.css';
@unlink($output);

$extra = [
'css-compiler' => [
[
'format' => 'compact',
'input' => [
$this->getSharedFixturesDirectory() . '/less'
],
'output' => $output
]
]
];

$rootPackage->expects($this->once())
->method('getExtra')
->willReturn($extra);
$composer->setPackage($rootPackage);

$event = new Event('onInstall', $composer, $io);

ScriptHandler::generateCSS($event);
$this->assertFileExists($output);
}
}
11 changes: 8 additions & 3 deletions tests/shared-enviroment/IntegrationTestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ protected function invokeMethod($object, $methodName, array $methodArguments = [
/**
* @return string
*/
public static function getRootDirectory()
protected function getRootDirectory()
{
return dirname(__DIR__);
}

/**
* @return string
*/
public static function getSharedFixturesDirectory()
protected function getSharedFixturesDirectory()
{
return static::getRootDirectory() . '/shared-fixtures';
}
Expand All @@ -50,8 +50,13 @@ public static function getSharedFixturesDirectory()
*
* @return string
*/
public static function getSharedFixtureContent(string $filename)
protected function getSharedFixtureContent(string $filename)
{
return file_get_contents(static::getSharedFixturesDirectory() . "/$filename");
}

protected function getCacheDirectory()
{
return dirname($this->getRootDirectory()) . '/var/cache/tests';
}
}