Skip to content

Commit 9928f7c

Browse files
committed
bug #775 Fix the support of legacy scssphp formatters (stof)
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
2 parents c3bb677 + b422ec4 commit 9928f7c

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

src/Assetic/Filter/ScssphpFilter.php

+13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ public function isCompassEnabled()
4545

4646
public function setFormatter($formatter)
4747
{
48+
$legacyFormatters = array(
49+
'scss_formatter' => 'Leafo\ScssPhp\Formatter\Expanded',
50+
'scss_formatter_nested' => 'Leafo\ScssPhp\Formatter\Nested',
51+
'scss_formatter_compressed' => 'Leafo\ScssPhp\Formatter\Compressed',
52+
'scss_formatter_crunched' => 'Leafo\ScssPhp\Formatter\Crunched',
53+
);
54+
55+
if (isset($legacyFormatters[$formatter])) {
56+
@trigger_error(sprintf('The scssphp formatter `%s` is deprecated. Use `%s` instead.', $formatter, $legacyFormatters[$formatter]), E_USER_DEPRECATED);
57+
58+
$formatter = $legacyFormatters[$formatter];
59+
}
60+
4861
$this->formatter = $formatter;
4962
}
5063

tests/Assetic/Test/Filter/ScssphpFilterTest.php

+26-14
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public function testCompassExtensionCanBeEnabled()
9191
public function testCompassExtensionCanBeDisabled()
9292
{
9393
$this->setExpectedExceptionRegExp(
94-
"Exception",
95-
"/Undefined mixin box\-shadow\: failed at `@include box\-shadow\(10px 10px 8px red\);`.*? line 4/"
94+
'Exception',
95+
'/Undefined mixin box\-shadow\: failed at `@include box\-shadow\(10px 10px 8px red\);`.*? line:? 4/'
9696
);
9797

9898
$asset = new FileAsset(__DIR__.'/fixtures/sass/main_compass.scss');
@@ -110,7 +110,7 @@ public function testSetImportPath()
110110
$asset->load();
111111
$filter->filterLoad($asset);
112112

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

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

125-
$expected = new StringAsset('.foo{ color: red;}');
126-
$expected->load();
127-
$filter->filterLoad($expected);
128-
129-
$this->assertEquals($expected->getContent(), $asset->getContent(), 'custom function can be registered');
125+
$this->assertContains('color: red', $asset->getContent(), 'custom function can be registered');
130126
}
131127

132128
public function testSetFormatter()
@@ -135,14 +131,30 @@ public function testSetFormatter()
135131
$actual->load();
136132

137133
$filter = $this->getFilter();
138-
$filter->setFormatter("scss_formatter_compressed");
134+
$filter->setFormatter('Leafo\ScssPhp\Formatter\Compressed');
139135
$filter->filterLoad($actual);
140136

141-
$expected = new StringAsset('.foo{color:#fff}');
142-
$expected->load();
137+
$this->assertRegExp(
138+
'/^\.foo{color:#fff;?}$/',
139+
$actual->getContent(),
140+
'scss_formatter can be changed'
141+
);
142+
}
143143

144-
$this->assertEquals(
145-
$expected->getContent(),
144+
/**
145+
* @group legacy
146+
*/
147+
public function testSetFormatterWithLegacyName()
148+
{
149+
$actual = new StringAsset(".foo {\n color: #fff;\n}");
150+
$actual->load();
151+
152+
$filter = $this->getFilter();
153+
$filter->setFormatter('scss_formatter_compressed');
154+
$filter->filterLoad($actual);
155+
156+
$this->assertRegExp(
157+
'/^\.foo{color:#fff;?}$/',
146158
$actual->getContent(),
147159
'scss_formatter can be changed'
148160
);
@@ -179,7 +191,7 @@ public function testSetVariables()
179191
$asset->load();
180192
$filter->filterLoad($asset);
181193

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

185197
// private

0 commit comments

Comments
 (0)