Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated for PHP7.2 #1

Merged
merged 5 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
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:
- 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
58 changes: 28 additions & 30 deletions build/phpunitconfig.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestSize="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
checkForUnintentionallyCoveredCode="true"
bootstrap="../vendor/autoload.php"
processIsolation="false"
>
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">../tests/unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">../src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="coverage/" higlight="true" showUncoveredFiles="true"></log>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" showOnlySummary="true"></log>
</logging>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
bootstrap="../vendor/autoload.php"
processIsolation="false"
>
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">../tests/unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">../src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="coverage/" showUncoveredFiles="true"></log>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" showOnlySummary="true"></log>
</logging>
</phpunit>
62 changes: 30 additions & 32 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
{
"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": "^7.2"
},
"require-dev": {
"phpunit/phpunit": "^8.1"
},
"scripts": {
"test": "phpunit -c build/phpunitconfig.xml"
}
}
10 changes: 7 additions & 3 deletions src/eCSStractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
*/
class eCSStractor
{
/**
* Libxml-Option-Setting
* @var int
*/
protected $_libxmlOptions=0;

/**
* Returns the Libxml-Option-Setting used when parsing the HTML string
* @return int
*/
public function getLibxmlOptions()
public function getLibxmlOptions(): int
{
return $this->_libxmlOptions;
}
Expand All @@ -31,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;
Expand All @@ -42,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);

Expand Down
106 changes: 58 additions & 48 deletions tests/unit/eCSStractorTest.php
Original file line number Diff line number Diff line change
@@ -1,48 +1,58 @@
<?php

namespace SpazzMarticus\eCSStractor;

/**
* @uses \SpazzMarticus\eCSStractor\eCSStractor
*/
class eCSStractorTest extends \PHPUnit_Framework_TestCase
{
protected $_eCSStractor;

protected function setUp()
{
$this->_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');
}
}
<?php

namespace SpazzMarticus\eCSStractor;

/**
* @uses \SpazzMarticus\eCSStractor\eCSStractor
*/
class eCSStractorTest extends \PHPUnit\Framework\TestCase
{
protected $_eCSStractor;

protected function setUp(): void
{
$this->_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';
}
}