Skip to content

Commit

Permalink
bug #775 Fix the support of legacy scssphp formatters (stof)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.4-dev branch.

Discussion
----------

Fix the support of legacy scssphp formatters

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.

Commits
-------

b422ec4 Update the scssphp tests to be less strict about formatting
d6641a5 Fix the support of legacy scssphp formatters
  • Loading branch information
stof committed Nov 12, 2015
2 parents c3bb677 + b422ec4 commit 9928f7c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
13 changes: 13 additions & 0 deletions src/Assetic/Filter/ScssphpFilter.php
Original file line number Diff line number Diff line change
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
40 changes: 26 additions & 14 deletions tests/Assetic/Test/Filter/ScssphpFilterTest.php
Original file line number Diff line number Diff line change
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 All @@ -110,7 +110,7 @@ public function testSetImportPath()
$asset->load();
$filter->filterLoad($asset);

$this->assertEquals("#test {\n color: red; }\n", $asset->getContent(), 'Import paths are correctly used');
$this->assertContains('color: red', $asset->getContent(), 'Import paths are correctly used');
}

public function testRegisterFunction()
Expand All @@ -122,11 +122,7 @@ public function testRegisterFunction()
$filter->registerFunction('bar',function () { return 'red';});
$filter->filterLoad($asset);

$expected = new StringAsset('.foo{ color: red;}');
$expected->load();
$filter->filterLoad($expected);

$this->assertEquals($expected->getContent(), $asset->getContent(), 'custom function can be registered');
$this->assertContains('color: red', $asset->getContent(), 'custom function can be registered');
}

public function testSetFormatter()
Expand All @@ -135,14 +131,30 @@ 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->assertRegExp(
'/^\.foo{color:#fff;?}$/',
$actual->getContent(),
'scss_formatter can be changed'
);
}

$this->assertEquals(
$expected->getContent(),
/**
* @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);

$this->assertRegExp(
'/^\.foo{color:#fff;?}$/',
$actual->getContent(),
'scss_formatter can be changed'
);
Expand Down Expand Up @@ -179,7 +191,7 @@ public function testSetVariables()
$asset->load();
$filter->filterLoad($asset);

$this->assertEquals("#test {\n color: red; }\n", $asset->getContent(), "Variables can be added");
$this->assertContains('color: red', $asset->getContent(), 'Variables can be added');
}

// private
Expand Down

0 comments on commit 9928f7c

Please sign in to comment.