Skip to content

Commit

Permalink
Fix the support of legacy scssphp formatters
Browse files Browse the repository at this point in the history
Scssphp 0.5 removed the deprecated classes. But as there was no warning,
people might not be aware that they were using a deprecated class.
This keeps support for the deprecated formatters in Assetic by matching
them to their replacement, and warns the user about it.
  • Loading branch information
stof committed Nov 12, 2015
1 parent c3bb677 commit d6641a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/Assetic/Filter/ScssphpFilter.php
Expand Up @@ -45,6 +45,19 @@ public function isCompassEnabled()

public function setFormatter($formatter)
{
$legacyFormatters = array(
'scss_formatter' => 'Leafo\ScssPhp\Formatter\Expanded',
'scss_formatter_nested' => 'Leafo\ScssPhp\Formatter\Nested',
'scss_formatter_compressed' => 'Leafo\ScssPhp\Formatter\Compressed',
'scss_formatter_crunched' => 'Leafo\ScssPhp\Formatter\Crunched',
);

if (isset($legacyFormatters[$formatter])) {
@trigger_error(sprintf('The scssphp formatter `%s` is deprecated. Use `%s` instead.', $formatter, $legacyFormatters[$formatter]), E_USER_DEPRECATED);

$formatter = $legacyFormatters[$formatter];
}

$this->formatter = $formatter;
}

Expand Down
28 changes: 25 additions & 3 deletions tests/Assetic/Test/Filter/ScssphpFilterTest.php
Expand Up @@ -91,8 +91,8 @@ public function testCompassExtensionCanBeEnabled()
public function testCompassExtensionCanBeDisabled()
{
$this->setExpectedExceptionRegExp(
"Exception",
"/Undefined mixin box\-shadow\: failed at `@include box\-shadow\(10px 10px 8px red\);`.*? line 4/"
'Exception',
'/Undefined mixin box\-shadow\: failed at `@include box\-shadow\(10px 10px 8px red\);`.*? line 4/'
);

$asset = new FileAsset(__DIR__.'/fixtures/sass/main_compass.scss');
Expand Down Expand Up @@ -135,7 +135,29 @@ public function testSetFormatter()
$actual->load();

$filter = $this->getFilter();
$filter->setFormatter("scss_formatter_compressed");
$filter->setFormatter('Leafo\ScssPhp\Formatter\Compressed');
$filter->filterLoad($actual);

$expected = new StringAsset('.foo{color:#fff}');
$expected->load();

$this->assertEquals(
$expected->getContent(),
$actual->getContent(),
'scss_formatter can be changed'
);
}

/**
* @group legacy
*/
public function testSetFormatterWithLegacyName()
{
$actual = new StringAsset(".foo {\n color: #fff;\n}");
$actual->load();

$filter = $this->getFilter();
$filter->setFormatter('scss_formatter_compressed');
$filter->filterLoad($actual);

$expected = new StringAsset('.foo{color:#fff}');
Expand Down

0 comments on commit d6641a5

Please sign in to comment.