From 0583d11a13fc36704536ee83f4406c7e5b7c8be9 Mon Sep 17 00:00:00 2001 From: Eugene Matvejev Date: Wed, 6 Jul 2016 12:30:46 +0100 Subject: [PATCH 1/5] RC11 improve composer handler --- src/ScriptHandler.php | 76 ++++++++--------------------- tests/phpunit/ScriptHandlerTest.php | 49 ++++++++++++------- 2 files changed, 52 insertions(+), 73 deletions(-) diff --git a/src/ScriptHandler.php b/src/ScriptHandler.php index 29b8b7f..64c40aa 100644 --- a/src/ScriptHandler.php +++ b/src/ScriptHandler.php @@ -48,6 +48,12 @@ public static function generateCSS(Event $event) $processor->saveOutput(); } + /** + * @param string $path + * @param string $prefix + * + * @return string + */ protected static function resolvePath($path, $prefix) { return '/' === substr($path, 0, 1) ? $path : "{$prefix}/{$path}"; @@ -69,79 +75,39 @@ protected static function validateConfiguration(array $config) throw new \InvalidArgumentException('the extra.css-compiler setting must be an array of objects'); } - return static::validateOptions($config[static::CONFIG_MAIN_KEY]); - } - - /** - * @param array $config - * - * @return bool - * @throws \InvalidArgumentException - */ - protected static function validateOptions(array $config) - { - foreach ($config as $option) { - if (!is_array($option)) { + foreach ($config[static::CONFIG_MAIN_KEY] as $options) { + if (!is_array($options)) { throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[]." . static::OPTION_KEY_INPUT . ' array'); } - static::validateMandatoryOptions($option); + static::validateMandatoryOptions($options); } - - return true; } /** - * @param array $config + * @param array $options * - * @return bool * @throws \InvalidArgumentException */ - protected static function validateMandatoryOptions(array $config) + protected static function validateMandatoryOptions(array $options) { - foreach (static::$mandatoryOptions as $option) { - if (empty($config[$option])) { - throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[].{$option} is required!"); + foreach (static::$mandatoryOptions as $optionIndex) { + if (!isset($options[$optionIndex])) { + throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[].{$optionIndex} is required!"); } - switch ($option) { + switch ($optionIndex) { case static::OPTION_KEY_INPUT: - static::validateIsArray($config[$option]); + if (!is_array($options[$optionIndex])) { + throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[].{$optionIndex} should be array!"); + } break; case static::OPTION_KEY_OUTPUT: - static::validateIsString($config[$option]); + if (!is_string($options[$optionIndex])) { + throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[].{$optionIndex} should string!"); + } break; } } - - return true; - } - - /** - * @param array $option - * - * @return bool - */ - protected static function validateIsArray($option) - { - if (!is_array($option)) { - throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . '[]' . static::OPTION_KEY_INPUT . ' should be array!'); - } - - return true; - } - - /** - * @param string $option - * - * @return bool - */ - protected static function validateIsString($option) - { - if (!is_string($option)) { - throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . '[]' . static::OPTION_KEY_OUTPUT . ' should string!'); - } - - return true; } } diff --git a/tests/phpunit/ScriptHandlerTest.php b/tests/phpunit/ScriptHandlerTest.php index 83fdd80..db1ed1d 100644 --- a/tests/phpunit/ScriptHandlerTest.php +++ b/tests/phpunit/ScriptHandlerTest.php @@ -72,88 +72,101 @@ public function validateConfigurationOnValid() ] ]; - $this->assertTrue($this->validateConfiguration($args)); + $this->assertNull($this->validateConfiguration($args)); } + /** + * @see ScriptHandler::validateConfiguration + * + * @param $args + * + * @return bool + */ private function validateConfiguration($args) { return $this->invokeMethod(new ScriptHandler(), 'validateConfiguration', [$args]); } /*** *************************** OPTIONS VALIDATION *************************** ***/ /** - * @see ScriptHandler::validateOptions + * @see ScriptHandler::validateMandatoryOptions * @test * * @expectedException \InvalidArgumentException */ public function validateOptionsExpectedExceptionOnMissingInput() { - $this->validateOptions([[ScriptHandler::OPTION_KEY_OUTPUT => 'output']]); + $this->validateMandatoryOptions([[ScriptHandler::OPTION_KEY_OUTPUT => 'output']]); } /** - * @see ScriptHandler::validateOptions + * @see ScriptHandler::validateMandatoryOptions * @test * * @expectedException \InvalidArgumentException */ public function validateOptionsExpectedExceptionOnMissingOutput() { - $this->validateOptions([ScriptHandler::OPTION_KEY_INPUT => 'input']); + $this->validateMandatoryOptions([ScriptHandler::OPTION_KEY_INPUT => 'input']); } /** - * @see ScriptHandler::validateOptions + * @see ScriptHandler::validateMandatoryOptions * @test * * @expectedException \InvalidArgumentException */ public function validateOptionsExpectedExceptionOnInputNotArray() { - $this->validateOptions([ + $this->validateMandatoryOptions([ ScriptHandler::OPTION_KEY_INPUT => 'string', ScriptHandler::OPTION_KEY_OUTPUT => 'string' ]); } /** - * @see ScriptHandler::validateOptions + * @see ScriptHandler::validateMandatoryOptions * @test * * @expectedException \InvalidArgumentException */ public function validateOptionsExpectedExceptionOnOutputNotString() { - $this->validateOptions([ + $this->validateMandatoryOptions([ ScriptHandler::OPTION_KEY_INPUT => ['string'], ScriptHandler::OPTION_KEY_OUTPUT => ['string'] ]); } /** - * @see ScriptHandler::validateOptions + * @see ScriptHandler::validateMandatoryOptions * @test + * + * @group tester */ public function validateOptionsOnValid() { - $this->assertTrue( - $this->validateOptions([ - ScriptHandler::OPTION_KEY_INPUT => ['string'], - ScriptHandler::OPTION_KEY_OUTPUT => 'string' - ]) + $this->assertNull( + $this->validateMandatoryOptions( + [ + ScriptHandler::OPTION_KEY_INPUT => ['string'], + ScriptHandler::OPTION_KEY_OUTPUT => 'string' + ] + ) ); } /** + * @see ScriptHandler::validateMandatoryOptions + * * @param array $config * * @return bool */ - private function validateOptions($config) + private function validateMandatoryOptions($config) { - return $this->invokeMethod(new ScriptHandler(), 'validateOptions', [[$config]]); + return $this->invokeMethod(new ScriptHandler(), 'validateMandatoryOptions', [$config]); } - + /*** *************************** INTEGRATION *************************** ***/ /** * @see ScriptHandler::generateCSS From 30c19fdcb9c2b438880ce7c57a8f97077e5818b8 Mon Sep 17 00:00:00 2001 From: Eugene Matvejev Date: Thu, 7 Jul 2016 15:40:39 +0100 Subject: [PATCH 2/5] improved composer handler --- src/ScriptHandler.php | 48 +++++++++++++---------------- tests/phpunit/ScriptHandlerTest.php | 2 +- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/ScriptHandler.php b/src/ScriptHandler.php index 64c40aa..732cc59 100644 --- a/src/ScriptHandler.php +++ b/src/ScriptHandler.php @@ -18,11 +18,13 @@ class ScriptHandler const OPTION_KEY_FORMATTER = 'format'; const DEFAULT_OPTION_FORMATTER = 'compact'; protected static $mandatoryOptions = [ - self::OPTION_KEY_INPUT, - self::OPTION_KEY_OUTPUT + self::OPTION_KEY_INPUT => 'array', + self::OPTION_KEY_OUTPUT => 'string' ]; /** + * @api + * * @param Event $event * * @throws \InvalidArgumentException @@ -34,15 +36,15 @@ public static function generateCSS(Event $event) $processor = new Processor($event->getIO()); - foreach ($extra[static::CONFIG_MAIN_KEY] as $config) { - foreach ($config[static::OPTION_KEY_INPUT] as $inputSource) { + foreach ($extra[static::CONFIG_MAIN_KEY] as $options) { + foreach ($options[static::OPTION_KEY_INPUT] as $inputSource) { $processor->attachFiles( static::resolvePath($inputSource, getcwd()), - static::resolvePath($config[static::OPTION_KEY_OUTPUT], getcwd()) + static::resolvePath($options[static::OPTION_KEY_OUTPUT], getcwd()) ); } - $formatter = isset($config[static::OPTION_KEY_FORMATTER]) ? $config[static::OPTION_KEY_FORMATTER] : static::DEFAULT_OPTION_FORMATTER; + $formatter = array_key_exists(static::OPTION_KEY_FORMATTER, $options) ? $options[static::OPTION_KEY_FORMATTER] : static::DEFAULT_OPTION_FORMATTER; $processor->processFiles($formatter); } $processor->saveOutput(); @@ -62,51 +64,43 @@ protected static function resolvePath($path, $prefix) /** * @param array $config * - * @return bool * @throws \InvalidArgumentException */ protected static function validateConfiguration(array $config) { - if (empty($config[static::CONFIG_MAIN_KEY])) { + if (!array_key_exists(static::CONFIG_MAIN_KEY, $config)) { throw new \InvalidArgumentException('compiler should needs to be configured through the extra.css-compiler setting'); } if (!is_array($config[static::CONFIG_MAIN_KEY])) { - throw new \InvalidArgumentException('the extra.css-compiler setting must be an array of objects'); + throw new \InvalidArgumentException('the extra.' . static::CONFIG_MAIN_KEY . ' setting must be an array of objects'); } - foreach ($config[static::CONFIG_MAIN_KEY] as $options) { + foreach ($config[static::CONFIG_MAIN_KEY] as $index => $options) { if (!is_array($options)) { - throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[]." . static::OPTION_KEY_INPUT . ' array'); + throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[$index] should be an array"); } - static::validateMandatoryOptions($options); + static::validateMandatoryOptions($options, $index); } } /** * @param array $options + * @param int $index * * @throws \InvalidArgumentException */ - protected static function validateMandatoryOptions(array $options) + protected static function validateMandatoryOptions(array $options, $index) { - foreach (static::$mandatoryOptions as $optionIndex) { - if (!isset($options[$optionIndex])) { - throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[].{$optionIndex} is required!"); + foreach (static::$mandatoryOptions as $optionIndex => $type) { + if (!array_key_exists($optionIndex, $options)) { + throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[$index].{$optionIndex} is required!"); } - switch ($optionIndex) { - case static::OPTION_KEY_INPUT: - if (!is_array($options[$optionIndex])) { - throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[].{$optionIndex} should be array!"); - } - break; - case static::OPTION_KEY_OUTPUT: - if (!is_string($options[$optionIndex])) { - throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[].{$optionIndex} should string!"); - } - break; + $callable = "is_{$type}"; + if (!$callable($options[$optionIndex])) { + throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[$index].{$optionIndex} should be {$type}!"); } } } diff --git a/tests/phpunit/ScriptHandlerTest.php b/tests/phpunit/ScriptHandlerTest.php index db1ed1d..3ba63c4 100644 --- a/tests/phpunit/ScriptHandlerTest.php +++ b/tests/phpunit/ScriptHandlerTest.php @@ -164,7 +164,7 @@ public function validateOptionsOnValid() */ private function validateMandatoryOptions($config) { - return $this->invokeMethod(new ScriptHandler(), 'validateMandatoryOptions', [$config]); + return $this->invokeMethod(new ScriptHandler(), 'validateMandatoryOptions', [$config, 1]); } /*** *************************** INTEGRATION *************************** ***/ From 0abb92a1dc4e95521cd4b7fdc3361cddcd8dcc46 Mon Sep 17 00:00:00 2001 From: Eugene Matvejev Date: Mon, 6 Mar 2017 13:32:51 +0000 Subject: [PATCH 3/5] Update README.md --- README.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2bc5b87..b550fe1 100644 --- a/README.md +++ b/README.md @@ -10,19 +10,16 @@ [![composer.lock](https://poser.pugx.org/eugene-matvejev/css-compiler/composerlock)](https://packagist.org/packages/eugene-matvejev/css-compiler) -# PHP CSS Compiler +# PHP CSS compiler with composer handler _can be triggered from composer's script's section: compiles SCSS with compass|LESS_ -# How to use: -``` -composer require "eugene-matvejev/css-compiler" -``` +## how to use +`composer require eugene-matvejev/css-compiler` -### add callback into into composer's __scripts__: -``` -"EM\\CssCompiler\\ScriptHandler::generateCSS" -``` -_example_: +### add callback into into composer's __scripts__ +`"EM\\CssCompiler\\ScriptHandler::generateCSS"` + +_example_ ``` "scripts": { "post-update-cmd": "@custom-events", @@ -32,12 +29,13 @@ _example_: ] } ``` + ### add _css-compiler_ information inside of the _extra_ composer configuration * _format_: compression format * _input_: array of relative paths to the composer.json, all files will be picked up recursivly inside of the directory - * _output_: relative file path to the composer.json, where to save output (hard-copy) + * _output_: relative file path to the composer.json, where to save output (hard-copy) -_example_: +_example_ ``` "extra": { "css-compiler": [ From a0d6ba951b8a5f70bbbbf6ca53c827064de73d42 Mon Sep 17 00:00:00 2001 From: Eugene Matvejev Date: Mon, 6 Mar 2017 13:42:37 +0000 Subject: [PATCH 4/5] Update .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 97dda12..8353067 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ php: - "5.5" - "5.6" - "7.0" + - "7.1" - "hhvm" before_script: From d3c4975e2ad1756d7f1cea2a6733ca0bebba4fb3 Mon Sep 17 00:00:00 2001 From: Eugene Matvejev Date: Mon, 6 Mar 2017 13:46:28 +0000 Subject: [PATCH 5/5] Create circle.yml --- circle.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 circle.yml diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..d34193f --- /dev/null +++ b/circle.yml @@ -0,0 +1,15 @@ +machine: + php: + version: 7.1.0 + +dependencies: + cache_directories: + - ~/.composer/cache + override: + - composer install --no-progress --no-interaction + +test: + override: + - phpunit -c . + post: + - bash <(curl -s https://codecov.io/bash) -t eaad9275-9810-4190-bd1e-55cb0f5a8899 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy