From 9136b3b9c45f35d680bd15d6516a7b8eff41318b Mon Sep 17 00:00:00 2001 From: SpazzMarticus Date: Fri, 18 Sep 2015 11:17:32 +0200 Subject: [PATCH 1/5] Added documentation --- src/eCSStractor.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/eCSStractor.php b/src/eCSStractor.php index 808005b..aa6cce1 100644 --- a/src/eCSStractor.php +++ b/src/eCSStractor.php @@ -14,6 +14,10 @@ */ class eCSStractor { + /** + * Libxml-Option-Setting + * @var int + */ protected $_libxmlOptions=0; /** From 868e5686cad7ba8f9bf40a8a20adb19677dba820 Mon Sep 17 00:00:00 2001 From: SpazzMarticus Date: Fri, 31 May 2019 10:00:27 +0100 Subject: [PATCH 2/5] Updated Dependencies; Added newer PHP-Versions --- .travis.yml | 31 +++++----- build/phpunitconfig.xml | 58 +++++++++--------- composer.json | 64 ++++++++++---------- src/eCSStractor.php | 6 +- tests/unit/eCSStractorTest.php | 106 ++++++++++++++++++--------------- 5 files changed, 138 insertions(+), 127 deletions(-) diff --git a/.travis.yml b/.travis.yml index e99849a..46d6088 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,18 @@ -language: php -php: - - 5.4 - - 5.5 - - 5.6 - - hhvm - - nightly - - 7 - -before_install: -- composer self-update -install: -- travis_retry composer install --no-interaction --prefer-source -script: +language: php +php: + - 5.4 + - 5.5 + - 5.6 + - hhvm + - nightly + - 7.0 + - 7.1 + - 7.2 + - 7.3 + +before_install: +- composer self-update +install: +- travis_retry composer install --no-interaction --prefer-source +script: - vendor/bin/phpunit --configuration ./build/phpunitconfig.xml \ No newline at end of file diff --git a/build/phpunitconfig.xml b/build/phpunitconfig.xml index 10e07fd..4c42799 100644 --- a/build/phpunitconfig.xml +++ b/build/phpunitconfig.xml @@ -1,31 +1,29 @@ - - - - - ../tests/unit - - - - - ../src - - - - - - + + + + + ../tests/unit + + + + + ../src + + + + + + \ No newline at end of file diff --git a/composer.json b/composer.json index 68e6bcc..a54deee 100644 --- a/composer.json +++ b/composer.json @@ -1,32 +1,32 @@ -{ - "name": "spazzmarticus/e-css-tractor", - "description": "Extracts CSS from HTML (Style-Tags)", - "type": "library", - "license":"MIT", - "keywords": ["css", "extract", "stylesheet"], - "authors": [ - { - "name": "SpazzMarticus", - "homepage": "https://github.com/SpazzMarticus" - } - ], - "autoload": { - "psr-4": { - "SpazzMarticus\\eCSStractor\\": "src/" - }, - "classmap": [ - "src/" - ] - }, - "require": { - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "*", - "phpdocumentor/phpdocumentor": "*" - }, - "scripts": { - "test": "phpunit -c build/phpunitconfig.xml", - "doc": "phpdoc -c build/phpdocumentor.xml --template=\"xml\" --template=\"clean\"" - } -} +{ + "name": "spazzmarticus/e-css-tractor", + "description": "Extracts CSS from HTML (Style-Tags)", + "type": "library", + "license":"MIT", + "keywords": ["css", "extract", "stylesheet"], + "authors": [ + { + "name": "SpazzMarticus", + "homepage": "https://github.com/SpazzMarticus" + } + ], + "autoload": { + "psr-4": { + "SpazzMarticus\\eCSStractor\\": "src/" + }, + "classmap": [ + "src/" + ] + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpdocumentor/phpdocumentor": "*", + "phpunit/phpunit": "^8.1" + }, + "scripts": { + "test": "phpunit -c build/phpunitconfig.xml", + "doc": "phpdoc -c build/phpdocumentor.xml --template=\"xml\" --template=\"clean\"" + } +} diff --git a/src/eCSStractor.php b/src/eCSStractor.php index aa6cce1..3bac24b 100644 --- a/src/eCSStractor.php +++ b/src/eCSStractor.php @@ -24,7 +24,7 @@ class eCSStractor * Returns the Libxml-Option-Setting used when parsing the HTML string * @return int */ - public function getLibxmlOptions() + public function getLibxmlOptions(): int { return $this->_libxmlOptions; } @@ -35,7 +35,7 @@ public function getLibxmlOptions() * @param int $libxmlOptions * @return \SpazzMarticus\eCSStractor\eCSStractor */ - public function setLibxmlOptions($libxmlOptions) + public function setLibxmlOptions(int $libxmlOptions) { $this->_libxmlOptions=$libxmlOptions; return $this; @@ -46,7 +46,7 @@ public function setLibxmlOptions($libxmlOptions) * @param string $html * @return string */ - public function extract($html) + public function extract($html): string { $errorHandling=libxml_use_internal_errors(true); diff --git a/tests/unit/eCSStractorTest.php b/tests/unit/eCSStractorTest.php index 66bf25b..b0a6a04 100644 --- a/tests/unit/eCSStractorTest.php +++ b/tests/unit/eCSStractorTest.php @@ -1,48 +1,58 @@ -_eCSStractor=new eCSStractor(); - } - - /** - * @dataProvider providerExtract - * @covers \SpazzMarticus\eCSStractor\eCSStractor::extract - */ - public function testExtract($html, $cssFormat) - { - $this->assertStringMatchesFormat($cssFormat, $this->_eCSStractor->extract($html)); - } - - public function providerExtract() - { - $path=__DIR__.'/../fixtures/'; - return [ - ['plaintext', ''], - [123.2123, ''], - [file_get_contents($path.'01.html'), $this->loadFormat($path.'01.css')], - [file_get_contents($path.'02.html'), $this->loadFormat($path.'02.css')], - [file_get_contents($path.'03.html'), $this->loadFormat($path.'03.css')], - [file_get_contents($path.'04.html'), $this->loadFormat($path.'04.css')], - ]; - } - - public function loadFormat($file) - { - $format=file_get_contents($file); - if (!$format) - { - return false; - } - return str_replace('%w%w','%w','%w'.preg_replace('/\s/', '%w', $format).'%w'); - } -} +_eCSStractor=new eCSStractor(); + } + + public function testLibxmlOptions() + { + $this->_eCSStractor->setLibxmlOptions(1025); + $this->assertSame(1025, $this->_eCSStractor->getLibxmlOptions()); + } + + /** + * @dataProvider providerExtract + * @covers \SpazzMarticus\eCSStractor\eCSStractor::extract + */ + public function testExtract($html, $cssFormat) + { + $this->assertStringMatchesFormat($cssFormat, $this->_eCSStractor->extract($html)); + } + + public function providerExtract() + { + $path=__DIR__.'/../fixtures/'; + return [ + ['plaintext', ''], + [123.2123, ''], + [file_get_contents($path.'01.html'), $this->loadFormat($path.'01.css')], + [file_get_contents($path.'02.html'), $this->loadFormat($path.'02.css')], + [file_get_contents($path.'03.html'), $this->loadFormat($path.'03.css')], + [file_get_contents($path.'04.html'), $this->loadFormat($path.'04.css')], + ]; + } + + public function loadFormat($file) + { + $format=file_get_contents($file); + if (!$format) + { + return false; + } + /** + * @see https://phpunit.readthedocs.io/en/8.1/assertions.html#assertstringmatchesformat + * Replacing % by %% to work properly (e.g. width: 100%) , replacing whitespace by %w + */ + return '%w'.preg_replace('/\s+/', '%w', preg_replace('/%/', '%%', $format)).'%w'; + } +} From 9ba4bcc3603c548fa0c354bc65c951c8bccba0cc Mon Sep 17 00:00:00 2001 From: SpazzMarticus Date: Fri, 31 May 2019 10:11:45 +0100 Subject: [PATCH 3/5] Removed phpdocumentor --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index a54deee..4fdab59 100644 --- a/composer.json +++ b/composer.json @@ -22,11 +22,9 @@ "php": ">=5.4.0" }, "require-dev": { - "phpdocumentor/phpdocumentor": "*", "phpunit/phpunit": "^8.1" }, "scripts": { - "test": "phpunit -c build/phpunitconfig.xml", - "doc": "phpdoc -c build/phpdocumentor.xml --template=\"xml\" --template=\"clean\"" + "test": "phpunit -c build/phpunitconfig.xml" } } From 00510ca59ad3cb4393218831f234c527a76dd5be Mon Sep 17 00:00:00 2001 From: SpazzMarticus Date: Fri, 31 May 2019 10:13:13 +0100 Subject: [PATCH 4/5] Requirement forPHP7.2 added --- .travis.yml | 5 ----- composer.json | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 46d6088..a437564 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,5 @@ language: php php: - - 5.4 - - 5.5 - - 5.6 - - hhvm - - nightly - 7.0 - 7.1 - 7.2 diff --git a/composer.json b/composer.json index 4fdab59..74dc85e 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ ] }, "require": { - "php": ">=5.4.0" + "php": "^7.2" }, "require-dev": { "phpunit/phpunit": "^8.1" From f4fa3ae2c0564160233edb0ca8137f22e3ae7f7f Mon Sep 17 00:00:00 2001 From: SpazzMarticus Date: Fri, 31 May 2019 10:21:40 +0100 Subject: [PATCH 5/5] Travis configured for PHP7.2 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a437564..b21efbc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: php php: - - 7.0 - - 7.1 - 7.2 - 7.3