From d6641a51ba448fa42879cae43c647dc92b9091ad Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 12 Nov 2015 12:02:17 +0100 Subject: [PATCH 1/2] 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. --- src/Assetic/Filter/ScssphpFilter.php | 13 +++++++++ .../Assetic/Test/Filter/ScssphpFilterTest.php | 28 +++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) 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..166950760 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'); @@ -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}'); From b422ec4285bcf2214e85bfd632cb5da44b21e0f5 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 12 Nov 2015 13:00:19 +0100 Subject: [PATCH 2/2] Update the scssphp tests to be less strict about formatting Different versions are producing a slightly different output regarding formatting. --- .../Assetic/Test/Filter/ScssphpFilterTest.php | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/tests/Assetic/Test/Filter/ScssphpFilterTest.php b/tests/Assetic/Test/Filter/ScssphpFilterTest.php index 166950760..e7aec7adb 100644 --- a/tests/Assetic/Test/Filter/ScssphpFilterTest.php +++ b/tests/Assetic/Test/Filter/ScssphpFilterTest.php @@ -92,7 +92,7 @@ public function testCompassExtensionCanBeDisabled() { $this->setExpectedExceptionRegExp( 'Exception', - '/Undefined mixin box\-shadow\: failed at `@include box\-shadow\(10px 10px 8px red\);`.*? line 4/' + '/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() @@ -138,11 +134,8 @@ public function testSetFormatter() $filter->setFormatter('Leafo\ScssPhp\Formatter\Compressed'); $filter->filterLoad($actual); - $expected = new StringAsset('.foo{color:#fff}'); - $expected->load(); - - $this->assertEquals( - $expected->getContent(), + $this->assertRegExp( + '/^\.foo{color:#fff;?}$/', $actual->getContent(), 'scss_formatter can be changed' ); @@ -160,11 +153,8 @@ public function testSetFormatterWithLegacyName() $filter->setFormatter('scss_formatter_compressed'); $filter->filterLoad($actual); - $expected = new StringAsset('.foo{color:#fff}'); - $expected->load(); - - $this->assertEquals( - $expected->getContent(), + $this->assertRegExp( + '/^\.foo{color:#fff;?}$/', $actual->getContent(), 'scss_formatter can be changed' ); @@ -201,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