Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2b2b53d

Browse files
author
Eugene Matvejev
authored
Merge pull request #26 from learn-symfony/master
sync with main repository
2 parents 58f2c53 + 8b4c857 commit 2b2b53d

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed

‎src/ScriptHandler.php‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,26 @@ public static function generateCSS(Event $event)
3333
static::validateConfiguration($extra);
3434

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

3837
foreach ($extra[static::CONFIG_MAIN_KEY] as $config) {
39-
foreach ($config[static::OPTION_KEY_INPUT] as $value) {
40-
$processor->attachFiles("{$currentDirectory}/{$value}", "{$currentDirectory}/{$config[static::OPTION_KEY_OUTPUT]}");
38+
foreach ($config[static::OPTION_KEY_INPUT] as $inputSource) {
39+
$processor->attachFiles(
40+
static::resolvePath($inputSource, getcwd()),
41+
static::resolvePath($config[static::OPTION_KEY_OUTPUT], getcwd())
42+
);
4143
}
4244

4345
$formatter = isset($config[static::OPTION_KEY_FORMATTER]) ? $config[static::OPTION_KEY_FORMATTER] : static::DEFAULT_OPTION_FORMATTER;
44-
4546
$processor->processFiles($formatter);
4647
}
4748
$processor->saveOutput();
4849
}
4950

51+
protected static function resolvePath($path, $prefix)
52+
{
53+
return '/' === substr($path, 0, 1) ? $path : "{$prefix}/{$path}";
54+
}
55+
5056
/**
5157
* @param array $config
5258
*

‎tests/phpunit/Processor/ProcessorTest.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function attachFiles()
3030
static::getSharedFixturesDirectory() . '/compass' => 1,
3131
static::getSharedFixturesDirectory() . '/scss/layout.scss' => 1,
3232
static::getSharedFixturesDirectory() . '/scss' => 4,
33-
static::getSharedFixturesDirectory() => 9
3433
];
3534
foreach ($paths as $path => $expectedFiles) {
3635
$processor = new Processor($this->io);
@@ -256,8 +255,9 @@ public function saveOutput()
256255
{
257256
$processor = new Processor($this->io);
258257

259-
$expectedOutputFile = $this->getRootDirectory() . '/../var/tests/' . __FUNCTION__ . '.css';
258+
$expectedOutputFile = $this->getCacheDirectory() . '/' . __FUNCTION__ . '.css';
260259
@unlink($expectedOutputFile);
260+
261261
$processor->attachFiles(
262262
$this->getSharedFixturesDirectory() . '/scss',
263263
$expectedOutputFile

‎tests/phpunit/ScriptHandlerTest.php‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace EM\CssCompiler\Tests\PHPUnit;
44

5+
use Composer\Composer;
6+
use Composer\Config;
7+
use Composer\IO\IOInterface;
8+
use Composer\Package\RootPackage;
9+
use Composer\Script\Event;
510
use EM\CssCompiler\ScriptHandler;
611
use EM\CssCompiler\Tests\Environment\IntegrationTestSuite;
712

@@ -148,4 +153,46 @@ private function validateOptions($config)
148153
{
149154
return $this->invokeMethod(new ScriptHandler(), 'validateOptions', [[$config]]);
150155
}
156+
157+
/*** *************************** INTEGRATION *************************** ***/
158+
/**
159+
* @see ScriptHandler::generateCSS
160+
* @test
161+
*/
162+
public function generateCSS()
163+
{
164+
$composer = (new Composer());
165+
/** @var RootPackage|\PHPUnit_Framework_MockObject_MockObject $rootPackage */
166+
$rootPackage = $this->getMockBuilder(RootPackage::class)
167+
->setConstructorArgs(['css-compiler', 'dev-master', 'dev'])
168+
->setMethods(['getExtra'])
169+
->getMock();
170+
/** @var IOInterface|\PHPUnit_Framework_MockObject_MockObject $io */
171+
$io = $this->getMockBuilder(IOInterface::class)->getMock();
172+
173+
$output = $this->getCacheDirectory() . '/' . __FUNCTION__ . '.css';
174+
@unlink($output);
175+
176+
$extra = [
177+
'css-compiler' => [
178+
[
179+
'format' => 'compact',
180+
'input' => [
181+
$this->getSharedFixturesDirectory() . '/less'
182+
],
183+
'output' => $output
184+
]
185+
]
186+
];
187+
188+
$rootPackage->expects($this->once())
189+
->method('getExtra')
190+
->willReturn($extra);
191+
$composer->setPackage($rootPackage);
192+
193+
$event = new Event('onInstall', $composer, $io);
194+
195+
ScriptHandler::generateCSS($event);
196+
$this->assertFileExists($output);
197+
}
151198
}

‎tests/shared-enviroment/IntegrationTestSuite.php‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ protected function invokeMethod($object, $methodName, array $methodArguments = [
3030
/**
3131
* @return string
3232
*/
33-
publicstatic function getRootDirectory()
33+
protected function getRootDirectory()
3434
{
3535
return dirname(__DIR__);
3636
}
3737

3838
/**
3939
* @return string
4040
*/
41-
publicstatic function getSharedFixturesDirectory()
41+
protected function getSharedFixturesDirectory()
4242
{
4343
return static::getRootDirectory() . '/shared-fixtures';
4444
}
@@ -50,8 +50,13 @@ public static function getSharedFixturesDirectory()
5050
*
5151
* @return string
5252
*/
53-
publicstatic function getSharedFixtureContent(string $filename)
53+
protected function getSharedFixtureContent(string $filename)
5454
{
5555
return file_get_contents(static::getSharedFixturesDirectory() . "/$filename");
5656
}
57+
58+
protected function getCacheDirectory()
59+
{
60+
return dirname($this->getRootDirectory()) . '/var/cache/tests';
61+
}
5762
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /