From 3108ccdfeb41f9e2318cbf0e09e41baa212b988e Mon Sep 17 00:00:00 2001 From: Sven Hagemann Date: Wed, 16 Dec 2020 14:44:25 +0100 Subject: [PATCH 1/4] Update minimum PHP requirements to version 7.3 In order to prepare for PHP8 I upgraded PHPUnit from version 5 to version 9. However PHPUnit has dropped PHP5 support. And I would argue that maybe we should too. I personally dont think that PHP 7.3 is a bad minimum requirement, if that means that we can support PHP8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4f538ab..2886c9f 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "issues": "https://github.com/caxy/php-htmldiff/issues" }, "require": { - "php": ">=5.3.3", + "php": ">=7.3", "ezyang/htmlpurifier": "^4.7", "kub-at/php-simple-html-dom-parser": "^1.7" }, From 4fe069fa544f626f2233b5d933a7ce905ed24ae0 Mon Sep 17 00:00:00 2001 From: Sven Hagemann Date: Wed, 16 Dec 2020 11:18:31 +0100 Subject: [PATCH 2/4] Update PHPUnit to version 9 In order to prepare PHP8 compatibility we should use the recent version of PHPUnit --- composer.json | 2 +- phpunit.xml.dist | 48 ++++++++----------- tests/Caxy/Tests/AbstractTest.php | 6 ++- .../Functional/HTMLPurifierConfigTest.php | 4 +- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/composer.json b/composer.json index 2886c9f..1a297d3 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "kub-at/php-simple-html-dom-parser": "^1.7" }, "require-dev": { - "phpunit/phpunit": "~5.0", + "phpunit/phpunit": "~9.0", "doctrine/cache": "~1.0" }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 002c13b..72a9506 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,32 +1,22 @@ - - - - - performance - - - - - - ./tests/Caxy/Tests/HtmlDiff - - - - - - ./lib - - - + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> + + + ./lib + + + + + performance + + + + + ./tests/Caxy/Tests/HtmlDiff + + diff --git a/tests/Caxy/Tests/AbstractTest.php b/tests/Caxy/Tests/AbstractTest.php index d82eaf5..7f108b2 100644 --- a/tests/Caxy/Tests/AbstractTest.php +++ b/tests/Caxy/Tests/AbstractTest.php @@ -2,7 +2,9 @@ namespace Caxy\Tests; -abstract class AbstractTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +abstract class AbstractTest extends TestCase { protected function stripExtraWhitespaceAndNewLines($text) { @@ -14,4 +16,4 @@ protected function stripExtraWhitespaceAndNewLines($text) ) ); } -} \ No newline at end of file +} diff --git a/tests/Caxy/Tests/HtmlDiff/Functional/HTMLPurifierConfigTest.php b/tests/Caxy/Tests/HtmlDiff/Functional/HTMLPurifierConfigTest.php index 89aec8d..daacb30 100644 --- a/tests/Caxy/Tests/HtmlDiff/Functional/HTMLPurifierConfigTest.php +++ b/tests/Caxy/Tests/HtmlDiff/Functional/HTMLPurifierConfigTest.php @@ -13,7 +13,7 @@ class HTMLPurifierConfigTest extends AbstractTest */ protected $config; - public function setUp() + public function setUp() : void { $config = \HTMLPurifier_Config::createDefault(); @@ -73,4 +73,4 @@ public function testHtmlDiffConfigStatic() $diff->setHTMLPurifierConfig($this->config); $diff->build(); } -} \ No newline at end of file +} From 7a7a96787c90604b92a06fbc2f79a771fe0bce20 Mon Sep 17 00:00:00 2001 From: Sven Hagemann Date: Thu, 17 Dec 2020 15:53:42 +0100 Subject: [PATCH 3/4] Fix PHP8 classname incompatibility (Match) Match is a keyword in PHP8 that is used to do RegExp operations. This causes htmldiff to not function on PHP8 since one its classnames (Match) collides with the new keyword. I renamed it to MatchingBlock, this is less ambigous, and fixes the PHP incompatibility in the process. --- lib/Caxy/HtmlDiff/HtmlDiff.php | 8 +++---- lib/Caxy/HtmlDiff/Match.php | 31 ------------------------- lib/Caxy/HtmlDiff/MatchingBlock.php | 35 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 35 deletions(-) delete mode 100644 lib/Caxy/HtmlDiff/Match.php create mode 100644 lib/Caxy/HtmlDiff/MatchingBlock.php diff --git a/lib/Caxy/HtmlDiff/HtmlDiff.php b/lib/Caxy/HtmlDiff/HtmlDiff.php index 7177a6d..57462ac 100644 --- a/lib/Caxy/HtmlDiff/HtmlDiff.php +++ b/lib/Caxy/HtmlDiff/HtmlDiff.php @@ -696,7 +696,7 @@ protected function operations() $operations = array(); $matches = $this->matchingBlocks(); - $matches[] = new Match(count($this->oldWords), count($this->newWords), 0); + $matches[] = new MatchingBlock(count($this->oldWords), count($this->newWords), 0); foreach ($matches as $match) { $matchStartsAtCurrentPositionInOld = ($positionInOld === $match->startInOld); @@ -728,7 +728,7 @@ protected function operations() } /** - * @return Match[] + * @return MatchingBlock[] */ protected function matchingBlocks() { @@ -784,7 +784,7 @@ protected function stripTagAttributes($word) * @param int $startInNew * @param int $endInNew * - * @return Match|null + * @return MatchingBlock|null */ protected function findMatch($startInOld, $endInOld, $startInNew, $endInNew) { @@ -837,7 +837,7 @@ protected function findMatch($startInOld, $endInOld, $startInNew, $endInNew) !$this->isOnlyWhitespace($this->array_slice_cached($this->oldWords, $bestMatchInOld, $bestMatchSize)) ) ) { - return new Match($bestMatchInOld, $bestMatchInNew, $bestMatchSize); + return new MatchingBlock($bestMatchInOld, $bestMatchInNew, $bestMatchSize); } return null; diff --git a/lib/Caxy/HtmlDiff/Match.php b/lib/Caxy/HtmlDiff/Match.php deleted file mode 100644 index 621e5dc..0000000 --- a/lib/Caxy/HtmlDiff/Match.php +++ /dev/null @@ -1,31 +0,0 @@ -startInOld = $startInOld; - $this->startInNew = $startInNew; - $this->size = $size; - } - - public function endInOld() - { - return $this->startInOld + $this->size; - } - - public function endInNew() - { - return $this->startInNew + $this->size; - } - - public function count() { - return (int)$this->size; - } -} diff --git a/lib/Caxy/HtmlDiff/MatchingBlock.php b/lib/Caxy/HtmlDiff/MatchingBlock.php new file mode 100644 index 0000000..347f1f9 --- /dev/null +++ b/lib/Caxy/HtmlDiff/MatchingBlock.php @@ -0,0 +1,35 @@ +startInOld = $startInOld; + $this->startInNew = $startInNew; + $this->size = $size; + } + + public function endInOld() : int + { + return ($this->startInOld + $this->size); + } + + public function endInNew() : int + { + return ($this->startInNew + $this->size); + } + + public function count() : int + { + return (int)$this->size; + } +} From 1fbc0ca083a2944d726c42388a640fe1e1d80c1d Mon Sep 17 00:00:00 2001 From: Sven Hagemann Date: Thu, 17 Dec 2020 17:21:01 +0100 Subject: [PATCH 4/4] Scrutinizer: Upgrade phpcs fixer php_cs_fixer is deprecated by scrutinizer. After upgrading to PHP 7.3 this configuration is broken, due to Scrutinizer installing an older version. I upgraded the config, this makes scrutinizer always checkout the latest version of php-cs-fixer --- .scrutinizer.yml | 27 ++++++++++++++++----------- phpcs.xml | 6 ++++++ 2 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 phpcs.xml diff --git a/.scrutinizer.yml b/.scrutinizer.yml index fa2a078..04a587e 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -3,17 +3,22 @@ imports: tools: js_hint: true php_code_sniffer: true - php_cs_fixer: - config: { level: psr2 } - enabled: true + build: - tests: - override: - - - command: 'vendor/bin/phpunit --coverage-clover=code-coverage-file' - coverage: - file: 'code-coverage-file' - format: 'php-clover' + nodes: + analysis: + tests: + override: + - phpcs-run + tests: + tests: + override: + - + command: 'vendor/bin/phpunit --coverage-clover=code-coverage-file' + coverage: + file: 'code-coverage-file' + format: 'php-clover' + filter: excluded_paths: - tests/* @@ -130,4 +135,4 @@ checks: no_underscore_prefix_in_properties: true no_underscore_prefix_in_methods: true blank_line_after_namespace_declaration: true - verify_argument_usable_as_reference: true \ No newline at end of file + verify_argument_usable_as_reference: true diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..0f24ab8 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,6 @@ + + + ./lib + ./tests + +