Skip to content

Commit 2aecc24

Browse files
author
Eugene Matvejev
authored
Merge pull request #67 from eugene-matvejev/cover-compiler-exceptions
RC10 - improve compiler exceptions
2 parents e71d61c + 3fa8259 commit 2aecc24

File tree

5 files changed

+130
-56
lines changed

5 files changed

+130
-56
lines changed

src/Processor/Processor.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use EM\CssCompiler\Exception\CompilerException;
88
use EM\CssCompiler\Exception\FileException;
99
use Leafo\ScssPhp\Compiler as SASSCompiler;
10+
use Leafo\ScssPhp\Exception\ParserException;
1011
use lessc as LESSCompiler;
1112
use scss_compass as CompassCompiler;
1213

@@ -156,12 +157,20 @@ public function processFile(FileContainer $file)
156157
{
157158
switch ($file->getType()) {
158159
case FileContainer::TYPE_SCSS:
159-
$this->sass->addImportPath(dirname($file->getInputPath()));
160-
$content = $this->sass->compile($file->getInputContent());
161-
162-
return $file->setOutputContent($content);
160+
try {
161+
$this->sass->addImportPath(dirname($file->getInputPath()));
162+
$content = $this->sass->compile($file->getInputContent());
163+
164+
return $file->setOutputContent($content);
165+
} catch (ParserException $e) {
166+
throw new CompilerException($e->getMessage(), 1, $e);
167+
}
163168
case FileContainer::TYPE_LESS:
164-
return $file->setOutputContent($this->less->compileFile($file->getInputPath()));
169+
try {
170+
return $file->setOutputContent($this->less->compileFile($file->getInputPath()));
171+
} catch (\Exception $e) {
172+
throw new CompilerException($e->getMessage(), 1, $e);
173+
}
165174
}
166175

167176
throw new CompilerException('unknown compiler');

tests/phpunit/Processor/ProcessorTest.php

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
*/
1313
class ProcessorTest extends IntegrationTestSuite
1414
{
15-
protected $event;
1615
protected $io;
17-
protected $package;
1816

1917
protected function setUp()
2018
{
@@ -32,7 +30,7 @@ public function attachFiles()
3230
static::getSharedFixturesDirectory() . '/compass' => 1,
3331
static::getSharedFixturesDirectory() . '/scss/layout.scss' => 1,
3432
static::getSharedFixturesDirectory() . '/scss' => 4,
35-
static::getSharedFixturesDirectory() => 7
33+
static::getSharedFixturesDirectory() => 9
3634
];
3735
foreach ($paths as $path => $expectedFiles) {
3836
$processor = new Processor($this->io);
@@ -169,4 +167,84 @@ public function fetchInputContextIntoFileOnException()
169167
{
170168
$this->invokeMethod(new Processor($this->io), 'fetchInputContextIntoFile', [new FileContainer('input', 'output')]);
171169
}
170+
171+
/**
172+
* @see Processor::processFiles
173+
* @test
174+
*/
175+
public function processFilesOnSCSS()
176+
{
177+
$this->assertProcessFilesOnValid($this->getSharedFixturesDirectory() . '/scss', '');
178+
}
179+
180+
/**
181+
* @see Processor::processFiles
182+
* @test
183+
*/
184+
public function processFilesOnNotValidSCSS()
185+
{
186+
$this->assertProcessFilesOnNotValid($this->getSharedFixturesDirectory() . '/not-valid-scss', '');
187+
}
188+
189+
/**
190+
* @see Processor::processFiles
191+
* @test
192+
*/
193+
public function processFilesOnLESS()
194+
{
195+
$this->assertProcessFilesOnValid($this->getSharedFixturesDirectory() . '/less', '');
196+
}
197+
198+
/**
199+
* @see Processor::processFiles
200+
* @test
201+
*/
202+
public function processFilesOnNotValidLESS()
203+
{
204+
$this->assertProcessFilesOnNotValid($this->getSharedFixturesDirectory() . '/not-valid-less', '');
205+
}
206+
207+
/**
208+
* @see Processor::processFiles
209+
*
210+
* @param string $input
211+
* @param string $output
212+
*/
213+
private function assertProcessFilesOnValid($input, $output)
214+
{
215+
foreach ($this->processFiles($input, $output) as $file) {
216+
$this->assertNotNull($file->getOutputContent());
217+
}
218+
}
219+
220+
/**
221+
* @see Processor::processFiles
222+
*
223+
* @param string $input
224+
* @param string $output
225+
*/
226+
private function assertProcessFilesOnNotValid($input, $output)
227+
{
228+
foreach ($this->processFiles($input, $output) as $file) {
229+
$this->assertNull($file->getOutputContent());
230+
}
231+
}
232+
233+
/**
234+
* @see Processor::processFiles
235+
*
236+
* @param string $input
237+
* @param string $output
238+
*
239+
* @return FileContainer[]
240+
*/
241+
private function processFiles($input, $output)
242+
{
243+
$processor = new Processor($this->io);
244+
245+
$processor->attachFiles($input, $output);
246+
$processor->processFiles(Processor::FORMATTER_COMPRESSED);
247+
248+
return $processor->getFiles();
249+
}
172250
}

tests/shared-fixtures/less/print.less

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
/*! Source: https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css */
2-
3-
// ==========================================================================
4-
// Print styles.
5-
// Inlined to avoid the additional HTTP request: h5bp.com/r
6-
// ==========================================================================
7-
81
@media print {
92
*,
103
*:before,
@@ -45,27 +38,6 @@
4538
display: table-header-group; // h5bp.com/t
4639
}
4740

48-
tr,
49-
img {
50-
page-break-inside: avoid;
51-
}
52-
53-
img {
54-
max-width: 100% !important;
55-
}
56-
57-
p,
58-
h2,
59-
h3 {
60-
orphans: 3;
61-
widows: 3;
62-
}
63-
64-
h2,
65-
h3 {
66-
page-break-after: avoid;
67-
}
68-
6941
// Bootstrap specific changes start
7042

7143
// Bootstrap components
@@ -78,24 +50,4 @@
7850
border-top-color: #000 !important;
7951
}
8052
}
81-
.label {
82-
border: 1px solid #000;
83-
}
84-
85-
.table {
86-
border-collapse: collapse !important;
87-
88-
td,
89-
th {
90-
background-color: #fff !important;
91-
}
92-
}
93-
.table-bordered {
94-
th,
95-
td {
96-
border: 1px solid #ddd !important;
97-
}
98-
}
99-
100-
// Bootstrap specific changes end
10153
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*! Source: https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css */
2+
3+
// ==========================================================================
4+
// Print styles.
5+
// Inlined to avoid the additional HTTP request: h5bp.com/r
6+
// ==========================================================================
7+
8+
@media print
9+
10+
//*,
11+
12, // ERROR
12+
*:before,
13+
*:after {
14+
background: transparent !important;
15+
color: #000 !important; // Black prints faster: h5bp.com/s
16+
box-shadow: none !important;
17+
text-shadow: none !important;
18+
}
19+
20+
a,
21+
a:visited {
22+
text-decoration: underline;
23+
}
24+
25+
a[href]:after {
26+
content: " (" attr(href) ")";
27+
}
28+
29+
abbr[title]:after {
30+
content: " (" attr(title) ")";
31+
}
32+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
div#game-results-area table.table {
2+
margin 20px 0; // ERROR
3+
}

0 commit comments

Comments
 (0)