diff --git a/src/Assetic/Filter/ScssphpFilter.php b/src/Assetic/Filter/ScssphpFilter.php index 059c7b82c..c2252a146 100644 --- a/src/Assetic/Filter/ScssphpFilter.php +++ b/src/Assetic/Filter/ScssphpFilter.php @@ -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; } diff --git a/tests/Assetic/Test/Filter/ScssphpFilterTest.php b/tests/Assetic/Test/Filter/ScssphpFilterTest.php index 2e0b5e417..e7aec7adb 100644 --- a/tests/Assetic/Test/Filter/ScssphpFilterTest.php +++ b/tests/Assetic/Test/Filter/ScssphpFilterTest.php @@ -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'); @@ -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() @@ -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() @@ -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' ); @@ -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