From 3fa82596331eb9b7110a7010fb923fb7ce7431c9 Mon Sep 17 00:00:00 2001 From: Eugene Matvejev Date: Thu, 30 Jun 2016 18:11:43 +0100 Subject: [PATCH 1/2] improve compiler exceptions --- src/Processor/Processor.php | 19 +++-- tests/phpunit/Processor/ProcessorTest.php | 84 ++++++++++++++++++- tests/shared-fixtures/less/print.less | 48 ----------- .../shared-fixtures/not-valid-less/print.less | 32 +++++++ .../not-valid-scss/game-results.scss | 3 + 5 files changed, 130 insertions(+), 56 deletions(-) create mode 100644 tests/shared-fixtures/not-valid-less/print.less create mode 100644 tests/shared-fixtures/not-valid-scss/game-results.scss diff --git a/src/Processor/Processor.php b/src/Processor/Processor.php index 044bb83..b4dc79e 100644 --- a/src/Processor/Processor.php +++ b/src/Processor/Processor.php @@ -7,6 +7,7 @@ use EM\CssCompiler\Exception\CompilerException; use EM\CssCompiler\Exception\FileException; use Leafo\ScssPhp\Compiler as SASSCompiler; +use Leafo\ScssPhp\Exception\ParserException; use lessc as LESSCompiler; use scss_compass as CompassCompiler; @@ -156,12 +157,20 @@ public function processFile(FileContainer $file) { switch ($file->getType()) { case FileContainer::TYPE_SCSS: - $this->sass->addImportPath(dirname($file->getInputPath())); - $content = $this->sass->compile($file->getInputContent()); - - return $file->setOutputContent($content); + try { + $this->sass->addImportPath(dirname($file->getInputPath())); + $content = $this->sass->compile($file->getInputContent()); + + return $file->setOutputContent($content); + } catch (ParserException $e) { + throw new CompilerException($e->getMessage(), 1, $e); + } case FileContainer::TYPE_LESS: - return $file->setOutputContent($this->less->compileFile($file->getInputPath())); + try { + return $file->setOutputContent($this->less->compileFile($file->getInputPath())); + } catch (\Exception $e) { + throw new CompilerException($e->getMessage(), 1, $e); + } } throw new CompilerException('unknown compiler'); diff --git a/tests/phpunit/Processor/ProcessorTest.php b/tests/phpunit/Processor/ProcessorTest.php index 64a7f9a..b7343ad 100644 --- a/tests/phpunit/Processor/ProcessorTest.php +++ b/tests/phpunit/Processor/ProcessorTest.php @@ -12,9 +12,7 @@ */ class ProcessorTest extends IntegrationTestSuite { - protected $event; protected $io; - protected $package; protected function setUp() { @@ -32,7 +30,7 @@ public function attachFiles() static::getSharedFixturesDirectory() . '/compass' => 1, static::getSharedFixturesDirectory() . '/scss/layout.scss' => 1, static::getSharedFixturesDirectory() . '/scss' => 4, - static::getSharedFixturesDirectory() => 7 + static::getSharedFixturesDirectory() => 9 ]; foreach ($paths as $path => $expectedFiles) { $processor = new Processor($this->io); @@ -169,4 +167,84 @@ public function fetchInputContextIntoFileOnException() { $this->invokeMethod(new Processor($this->io), 'fetchInputContextIntoFile', [new FileContainer('input', 'output')]); } + + /** + * @see Processor::processFiles + * @test + */ + public function processFilesOnSCSS() + { + $this->assertProcessFilesOnValid($this->getSharedFixturesDirectory() . '/scss', ''); + } + + /** + * @see Processor::processFiles + * @test + */ + public function processFilesOnNotValidSCSS() + { + $this->assertProcessFilesOnNotValid($this->getSharedFixturesDirectory() . '/not-valid-scss', ''); + } + + /** + * @see Processor::processFiles + * @test + */ + public function processFilesOnLESS() + { + $this->assertProcessFilesOnValid($this->getSharedFixturesDirectory() . '/less', ''); + } + + /** + * @see Processor::processFiles + * @test + */ + public function processFilesOnNotValidLESS() + { + $this->assertProcessFilesOnNotValid($this->getSharedFixturesDirectory() . '/not-valid-less', ''); + } + + /** + * @see Processor::processFiles + * + * @param string $input + * @param string $output + */ + private function assertProcessFilesOnValid($input, $output) + { + foreach ($this->processFiles($input, $output) as $file) { + $this->assertNotNull($file->getOutputContent()); + } + } + + /** + * @see Processor::processFiles + * + * @param string $input + * @param string $output + */ + private function assertProcessFilesOnNotValid($input, $output) + { + foreach ($this->processFiles($input, $output) as $file) { + $this->assertNull($file->getOutputContent()); + } + } + + /** + * @see Processor::processFiles + * + * @param string $input + * @param string $output + * + * @return FileContainer[] + */ + private function processFiles($input, $output) + { + $processor = new Processor($this->io); + + $processor->attachFiles($input, $output); + $processor->processFiles(Processor::FORMATTER_COMPRESSED); + + return $processor->getFiles(); + } } diff --git a/tests/shared-fixtures/less/print.less b/tests/shared-fixtures/less/print.less index 66e54ab..0401cd7 100644 --- a/tests/shared-fixtures/less/print.less +++ b/tests/shared-fixtures/less/print.less @@ -1,10 +1,3 @@ -/*! Source: https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css */ - -// ========================================================================== -// Print styles. -// Inlined to avoid the additional HTTP request: h5bp.com/r -// ========================================================================== - @media print { *, *:before, @@ -45,27 +38,6 @@ display: table-header-group; // h5bp.com/t } - tr, - img { - page-break-inside: avoid; - } - - img { - max-width: 100% !important; - } - - p, - h2, - h3 { - orphans: 3; - widows: 3; - } - - h2, - h3 { - page-break-after: avoid; - } - // Bootstrap specific changes start // Bootstrap components @@ -78,24 +50,4 @@ border-top-color: #000 !important; } } - .label { - border: 1px solid #000; - } - - .table { - border-collapse: collapse !important; - - td, - th { - background-color: #fff !important; - } - } - .table-bordered { - th, - td { - border: 1px solid #ddd !important; - } - } - - // Bootstrap specific changes end } diff --git a/tests/shared-fixtures/not-valid-less/print.less b/tests/shared-fixtures/not-valid-less/print.less new file mode 100644 index 0000000..40cf155 --- /dev/null +++ b/tests/shared-fixtures/not-valid-less/print.less @@ -0,0 +1,32 @@ +/*! Source: https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css */ + +// ========================================================================== +// Print styles. +// Inlined to avoid the additional HTTP request: h5bp.com/r +// ========================================================================== + +@media print + + //*, + 12, // ERROR + *:before, + *:after { + background: transparent !important; + color: #000 !important; // Black prints faster: h5bp.com/s + box-shadow: none !important; + text-shadow: none !important; + } + + a, + a:visited { + text-decoration: underline; + } + + a[href]:after { + content: " (" attr(href) ")"; + } + + abbr[title]:after { + content: " (" attr(title) ")"; + } +} diff --git a/tests/shared-fixtures/not-valid-scss/game-results.scss b/tests/shared-fixtures/not-valid-scss/game-results.scss new file mode 100644 index 0000000..6ccd7da --- /dev/null +++ b/tests/shared-fixtures/not-valid-scss/game-results.scss @@ -0,0 +1,3 @@ +div#game-results-area table.table { + margin 20px 0; // ERROR +} From d930b27f6b90f10cc562bc41861db1b493ea65e5 Mon Sep 17 00:00:00 2001 From: Eugene Matvejev Date: Thu, 30 Jun 2016 18:13:10 +0100 Subject: [PATCH 2/2] clean testing fixtures --- tests/shared-fixtures/scss/game.scss | 1 - tests/shared-fixtures/scss/layout.scss | 106 ------------------------- 2 files changed, 107 deletions(-) diff --git a/tests/shared-fixtures/scss/game.scss b/tests/shared-fixtures/scss/game.scss index ed94cfe..45e2cec 100644 --- a/tests/shared-fixtures/scss/game.scss +++ b/tests/shared-fixtures/scss/game.scss @@ -1,4 +1,3 @@ - .battlefield-cell-container { display: flex; diff --git a/tests/shared-fixtures/scss/layout.scss b/tests/shared-fixtures/scss/layout.scss index 7a2f1da..ca16409 100644 --- a/tests/shared-fixtures/scss/layout.scss +++ b/tests/shared-fixtures/scss/layout.scss @@ -19,23 +19,6 @@ body { } } -.page-sidebar, -.page-content { - transition: all 0.5s ease; - color: #fff; -} - -.page-sidebar { - position: fixed; - height: 100%; - left: 0; - z-index: 1000; - overflow-y: auto; - /*background: linear-gradient(to bottom, #b26cab 0%,#765c8b 100%); !* W3C *!*/ - background: linear-gradient(to bottom, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0.5) 50%, rgba(255, 255, 255, 0) 100%); - border-right: 1px solid #fff; -} - .page-sidebar, .sidebar-nav > li { width: 250px; @@ -60,23 +43,6 @@ body { } } -.toggle-btn { - cursor: pointer; -} - -.page-header { - font-size: 24px; - margin: 0; - padding: 40px 0 0 20px; - - &, - & > span { - line-height: 32px; - height: 75px; - } - -} - .sidebar-nav { list-style-type: none; padding: 0; @@ -107,75 +73,3 @@ body { cursor: pointer; } } - -.page-content:not(.toggled) .toggle-btn { - opacity: 0; -} - -.page-loading { - background: rgba(2, 2, 2, 0.5); - z-index: 10002; - width: 100%; - height: 100%; - position: absolute; - - & > .loading-animation { - margin: auto; - top: 50%; - zoom: 4; - } -} - -.no-scroll-mode { - position: fixed; -} - -#notification-area { - width: calc(100% - 50px); - border: 1px solid; - min-height: 100px; - position: absolute; - border-radius: 10px; - - font-size: 72px; - z-index: 1; - text-align: center; - font-style: italic; -} - -#notification-area > .notification-control { - float: right; - margin: 10px; - font-size: 24px; - - &:hover { - font-weight: bolder; - cursor: pointer; - } -} - -#modal-area { - color: #000; - h4, label { - text-transform: uppercase; - } - - .help-block { - font-size: 14px; - font-style: italic; - } -} - -.container-fluid { - padding-left: 0; - padding-right: 0; - padding-bottom: 25px; -} - -.pagination-area { - text-align: center; -} - -a.history-title { - color: #F5DEB3; -}