From ff6c667cadb446d3748d364e5b1976925d23ff25 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Mon, 10 Oct 2022 13:47:48 +0300 Subject: [PATCH 01/15] Fix PHP 8.1 compatibility of Collection::offsetGet. --- src/PHPHtmlParser/Dom/Node/Collection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PHPHtmlParser/Dom/Node/Collection.php b/src/PHPHtmlParser/Dom/Node/Collection.php index ff447259..543b7eca 100644 --- a/src/PHPHtmlParser/Dom/Node/Collection.php +++ b/src/PHPHtmlParser/Dom/Node/Collection.php @@ -130,6 +130,7 @@ public function offsetUnset($offset): void * * @return mixed */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->collection[$offset] ?? null; From f2097c64d22612c2db01d542d1510a71c7b77fec Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Mon, 10 Oct 2022 13:54:10 +0300 Subject: [PATCH 02/15] Update dependencies and tests for PHP 8.1 compatibility. Bumps minimum PHP version to 7.4.7. --- composer.json | 30 +++-- src/PHPHtmlParser/DTO/Tag/AttributeDTO.php | 4 +- tests/CollectionTest.php | 30 +++-- tests/ContentTest.php | 26 ++--- tests/Dom/CleanerTest.php | 2 +- tests/Dom/CommentTest.php | 6 +- tests/Dom/LoadTest.php | 30 ++--- tests/Dom/NotLoadedTest.php | 6 +- tests/DomTest.php | 122 ++++++++++----------- tests/Node/ChildrenTest.php | 38 +++---- tests/Node/HtmlTest.php | 69 ++++++------ tests/Node/ParentTest.php | 66 +++++------ tests/Node/TagTest.php | 40 ++++--- tests/Node/TextTest.php | 18 +-- tests/Options/CleanupTest.php | 16 +-- tests/Options/NoSlashTest.php | 6 +- tests/Options/PreserveLineBreaks.php | 4 +- tests/Options/SelfClosingTest.php | 8 +- tests/Options/StrictTest.php | 8 +- tests/Options/WhitespaceTextNodeTest.php | 4 +- tests/OptionsTest.php | 8 +- tests/Selector/SeekerTest.php | 2 +- tests/Selector/SelectorTest.php | 32 +++--- tests/StaticDomTest.php | 22 ++-- 24 files changed, 291 insertions(+), 306 deletions(-) diff --git a/composer.json b/composer.json index 166886f7..16775751 100755 --- a/composer.json +++ b/composer.json @@ -10,29 +10,39 @@ "name": "Gilles Paquette", "email": "paquettg@gmail.com", "homepage": "http://gillespaquette.ca" + }, + { + "name": "Ere Maijala", + "email": "ere.maijala@helsinki.fi", + "homepage": "http://nationallibrary.fi" } ], "require": { - "php": ">=7.2", + "php": ">=7.4", "ext-mbstring": "*", "ext-zlib": "*", "ext-curl": "*", "paquettg/string-encode": "~1.0.0", - "php-http/httplug": "^2.1", - "guzzlehttp/guzzle": "^7.0", - "guzzlehttp/psr7": "^1.6", - "myclabs/php-enum": "^1.7" + "php-http/httplug": "^2.3.0", + "guzzlehttp/guzzle": "^7.5.0", + "guzzlehttp/psr7": "^2.4.1", + "myclabs/php-enum": "^1.8.4" }, "require-dev": { - "phpunit/phpunit": "^7.5.1", + "phpunit/phpunit": "^9.5.25", "mockery/mockery": "^1.2", - "infection/infection": "^0.13.4", - "phan/phan": "^2.4", - "friendsofphp/php-cs-fixer": "^2.16" + "infection/infection": "^0.26.6", + "phan/phan": "^5.4.1", + "friendsofphp/php-cs-fixer": "^3.11.0" }, "autoload": { - "psr-4": { + "psr-4": { "PHPHtmlParser\\": "src/PHPHtmlParser" } + }, + "config": { + "allow-plugins": { + "infection/extension-installer": false + } } } diff --git a/src/PHPHtmlParser/DTO/Tag/AttributeDTO.php b/src/PHPHtmlParser/DTO/Tag/AttributeDTO.php index 3e7e1824..773d7795 100755 --- a/src/PHPHtmlParser/DTO/Tag/AttributeDTO.php +++ b/src/PHPHtmlParser/DTO/Tag/AttributeDTO.php @@ -55,6 +55,8 @@ public function htmlspecialcharsDecode(): void */ public function encodeValue(Encode $encode) { - $this->value = $encode->convert($this->value); + if (null !== $this->value) { + $this->value = $encode->convert($this->value); + } } } diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index c11c667c..a628c9b9 100755 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -11,7 +11,7 @@ class CollectionTest extends TestCase { - public function testEach() + public function testEach(): void { $root = new HtmlNode(new Tag('root')); $parent = new HtmlNode(new Tag('div')); @@ -32,23 +32,21 @@ public function testEach() $this->assertEquals(2, $count); } - /** - * @expectedException \PHPHtmlParser\Exceptions\EmptyCollectionException - */ - public function testCallNoNodes() + public function testCallNoNodes(): void { $collection = new Collection(); + $this->expectException(\PHPHtmlParser\Exceptions\EmptyCollectionException::class); $collection->innerHtml(); } - public function testNoNodeString() + public function testNoNodeString(): void { $collection = new Collection(); $string = (string) $collection; $this->assertEmpty($string); } - public function testCallMagic() + public function testCallMagic(): void { $root = new HtmlNode(new Tag('root')); $parent = new HtmlNode(new Tag('div')); @@ -64,7 +62,7 @@ public function testCallMagic() $this->assertEquals($child3->id(), $selector->find($root)->id()); } - public function testGetMagic() + public function testGetMagic(): void { $root = new HtmlNode(new Tag('root')); $parent = new HtmlNode(new Tag('div')); @@ -80,16 +78,14 @@ public function testGetMagic() $this->assertEquals($child3->innerHtml, $selector->find($root)->innerHtml); } - /** - * @expectedException \PHPHtmlParser\Exceptions\EmptyCollectionException - */ - public function testGetNoNodes() + public function testGetNoNodes(): void { $collection = new Collection(); + $this->expectException(\PHPHtmlParser\Exceptions\EmptyCollectionException::class); $collection->innerHtml; } - public function testToStringMagic() + public function testToStringMagic(): void { $root = new HtmlNode(new Tag('root')); $parent = new HtmlNode(new Tag('div')); @@ -105,7 +101,7 @@ public function testToStringMagic() $this->assertEquals((string) $child3, (string) $selector->find($root)); } - public function testToArray() + public function testToArray(): void { $root = new HtmlNode(new Tag('root')); $parent = new HtmlNode(new Tag('div')); @@ -124,21 +120,21 @@ public function testToArray() $this->assertEquals($child3->id(), $lastA->id()); } - public function testGetIterator() + public function testGetIterator(): void { $collection = new Collection(); $iterator = $collection->getIterator(); $this->assertTrue($iterator instanceof \ArrayIterator); } - public function testOffsetSet() + public function testOffsetSet(): void { $collection = new Collection(); $collection->offsetSet(7, true); $this->assertTrue($collection->offsetGet(7)); } - public function testOffsetUnset() + public function testOffsetUnset(): void { $collection = new Collection(); $collection->offsetSet(7, true); diff --git a/tests/ContentTest.php b/tests/ContentTest.php index c6d25edb..3942b9f7 100755 --- a/tests/ContentTest.php +++ b/tests/ContentTest.php @@ -8,26 +8,26 @@ class ContentTest extends TestCase { - public function testChar() + public function testChar(): void { $content = new Content('abcde'); $this->assertEquals('a', $content->char()); } - public function testCharSelection() + public function testCharSelection(): void { $content = new Content('abcde'); $this->assertEquals('d', $content->char(3)); } - public function testFastForward() + public function testFastForward(): void { $content = new Content('abcde'); $content->fastForward(2); $this->assertEquals('c', $content->char()); } - public function testRewind() + public function testRewind(): void { $content = new Content('abcde'); $content->fastForward(2) @@ -35,7 +35,7 @@ public function testRewind() $this->assertEquals('b', $content->char()); } - public function testRewindNegative() + public function testRewindNegative(): void { $content = new Content('abcde'); $content->fastForward(2) @@ -43,51 +43,51 @@ public function testRewindNegative() $this->assertEquals('a', $content->char()); } - public function testCopyUntil() + public function testCopyUntil(): void { $content = new Content('abcdeedcba'); $this->assertEquals('abcde', $content->copyUntil('ed')); } - public function testCopyUntilChar() + public function testCopyUntilChar(): void { $content = new Content('abcdeedcba'); $this->assertEquals('ab', $content->copyUntil('edc', true)); } - public function testCopyUntilEscape() + public function testCopyUntilEscape(): void { $content = new Content('foo\"bar"bax'); $this->assertEquals('foo\"bar', $content->copyUntil('"', false, true)); } - public function testCopyUntilNotFound() + public function testCopyUntilNotFound(): void { $content = new Content('foo\"bar"bax'); $this->assertEquals('foo\"bar"bax', $content->copyUntil('baz')); } - public function testCopyByToken() + public function testCopyByToken(): void { $content = new Content(''); $content->fastForward(3); $this->assertEquals('href="google.com"', $content->copyByToken(StringToken::ATTR(), true)); } - public function testSkip() + public function testSkip(): void { $content = new Content('abcdefghijkl'); $content->skip('abcd'); $this->assertEquals('e', $content->char()); } - public function testSkipCopy() + public function testSkipCopy(): void { $content = new Content('abcdefghijkl'); $this->assertEquals('abcd', $content->skip('abcd', true)); } - public function testSkipByToken() + public function testSkipByToken(): void { $content = new Content(' b c'); $content->fastForward(1); diff --git a/tests/Dom/CleanerTest.php b/tests/Dom/CleanerTest.php index 3ff32506..d3e2fe02 100644 --- a/tests/Dom/CleanerTest.php +++ b/tests/Dom/CleanerTest.php @@ -8,7 +8,7 @@ class CleanerTest extends TestCase { - public function testCleanEregiFailureFile() + public function testCleanEregiFailureFile(): void { $cleaner = new Cleaner(); $string = $cleaner->clean(\file_get_contents('tests/data/files/mvEregiReplaceFailure.html'), new Options(), 'utf-8'); diff --git a/tests/Dom/CommentTest.php b/tests/Dom/CommentTest.php index 3f10696e..a26a3098 100644 --- a/tests/Dom/CommentTest.php +++ b/tests/Dom/CommentTest.php @@ -13,7 +13,7 @@ class CommentTest extends TestCase */ private $dom; - public function setUp() + public function setUp(): void { $dom = new Dom(); $options = new Options(); @@ -22,12 +22,12 @@ public function setUp() $this->dom = $dom; } - public function tearDown() + public function tearDown(): void { Mockery::close(); } - public function testLoadCommentInnerHtml() + public function testLoadCommentInnerHtml(): void { $this->assertEquals('', $this->dom->innerHtml); } diff --git a/tests/Dom/LoadTest.php b/tests/Dom/LoadTest.php index 456afb88..e7ac5dc6 100644 --- a/tests/Dom/LoadTest.php +++ b/tests/Dom/LoadTest.php @@ -12,83 +12,83 @@ class LoadTest extends TestCase */ private $dom; - public function setUp() + public function setUp(): void { $dom = new Dom(); $dom->loadStr('
'); $this->dom = $dom; } - public function tearDown() + public function tearDown(): void { Mockery::close(); } - public function testLoadEscapeQuotes() + public function testLoadEscapeQuotes(): void { $a = $this->dom->find('a', 0); $this->assertEquals('click here', $a->outerHtml); } - public function testLoadNoClosingTag() + public function testLoadNoClosingTag(): void { $p = $this->dom->find('p', 0); $this->assertEquals('Hey bro, click here', $p->innerHtml); } - public function testLoadClosingTagOnSelfClosing() + public function testLoadClosingTagOnSelfClosing(): void { $this->assertCount(2, $this->dom->find('br')); } - public function testIncorrectAccess() + public function testIncorrectAccess(): void { $div = $this->dom->find('div', 0); $this->assertEquals(null, $div->foo); } - public function testLoadAttributeOnSelfClosing() + public function testLoadAttributeOnSelfClosing(): void { $br = $this->dom->find('br', 1); $this->assertEquals('both', $br->getAttribute('class')); } - public function testToStringMagic() + public function testToStringMagic(): void { $this->assertEquals('

Hey bro, click here


', (string) $this->dom); } - public function testGetMagic() + public function testGetMagic(): void { $this->assertEquals('

Hey bro, click here


', $this->dom->innerHtml); } - public function testFirstChild() + public function testFirstChild(): void { $this->assertEquals('

Hey bro, click here

', $this->dom->firstChild()->outerHtml); } - public function testLastChild() + public function testLastChild(): void { $this->assertEquals('
', $this->dom->lastChild()->outerHtml); } - public function testGetElementById() + public function testGetElementById(): void { $this->assertEquals('click here', $this->dom->getElementById('78')->outerHtml); } - public function testGetElementsByTag() + public function testGetElementsByTag(): void { $this->assertEquals('

Hey bro, click here

', $this->dom->getElementsByTag('p')[0]->outerHtml); } - public function testGetElementsByClass() + public function testGetElementsByClass(): void { $this->assertEquals('

Hey bro, click here

', $this->dom->getElementsByClass('all')[0]->innerHtml); } - public function testDeleteNode() + public function testDeleteNode(): void { $a = $this->dom->find('a')[0]; $a->delete(); diff --git a/tests/Dom/NotLoadedTest.php b/tests/Dom/NotLoadedTest.php index 7c1f0674..01d931f4 100644 --- a/tests/Dom/NotLoadedTest.php +++ b/tests/Dom/NotLoadedTest.php @@ -13,18 +13,18 @@ class NotLoadedTest extends TestCase */ private $dom; - public function setUp() + public function setUp(): void { $dom = new Dom(); $this->dom = $dom; } - public function tearDown() + public function tearDown(): void { Mockery::close(); } - public function testNotLoaded() + public function testNotLoaded(): void { $this->expectException(NotLoadedException::class); $div = $this->dom->find('div', 0); diff --git a/tests/DomTest.php b/tests/DomTest.php index 519d5594..260b751d 100755 --- a/tests/DomTest.php +++ b/tests/DomTest.php @@ -8,7 +8,7 @@ class DomTest extends TestCase { - public function tearDown() + public function tearDown(): void { Mockery::close(); } @@ -16,7 +16,7 @@ public function tearDown() /** * /* */"; $dom = new Dom(); @@ -25,7 +25,7 @@ public function testParsingCData() $this->assertSame($html, $dom->root->outerHtml()); } - public function testLoadSelfclosingAttr() + public function testLoadSelfclosingAttr(): void { $dom = new Dom(); $dom->loadStr("

baz
"); @@ -33,7 +33,7 @@ public function testLoadSelfclosingAttr() $this->assertEquals('
', $br->outerHtml); } - public function testLoadSelfclosingAttrToString() + public function testLoadSelfclosingAttrToString(): void { $dom = new Dom(); $dom->loadStr("

baz
"); @@ -41,77 +41,77 @@ public function testLoadSelfclosingAttrToString() $this->assertEquals('
', (string) $br); } - public function testLoadNoOpeningTag() + public function testLoadNoOpeningTag(): void { $dom = new Dom(); $dom->loadStr('
PR Manager
content
'); $this->assertEquals('content', $dom->find('.content', 0)->text); } - public function testLoadNoValueAttribute() + public function testLoadNoValueAttribute(): void { $dom = new Dom(); $dom->loadStr('
Main content here
'); $this->assertEquals('
Main content here
', $dom->innerHtml); } - public function testLoadBackslashAttributeValue() + public function testLoadBackslashAttributeValue(): void { $dom = new Dom(); $dom->loadStr('
Main content here
'); $this->assertEquals('
Main content here
', $dom->innerHtml); } - public function testLoadNoValueAttributeBefore() + public function testLoadNoValueAttributeBefore(): void { $dom = new Dom(); $dom->loadStr('
Main content here
'); $this->assertEquals('
Main content here
', $dom->innerHtml); } - public function testLoadUpperCase() + public function testLoadUpperCase(): void { $dom = new Dom(); $dom->loadStr('

hEY BRO, CLICK HERE

'); $this->assertEquals('

hEY BRO, CLICK HERE

', $dom->find('div', 0)->innerHtml); } - public function testLoadWithFile() + public function testLoadWithFile(): void { $dom = new Dom(); $dom->loadFromFile('tests/data/files/small.html'); $this->assertEquals('VonBurgermeister', $dom->find('.post-user font', 0)->text); } - public function testLoadFromFile() + public function testLoadFromFile(): void { $dom = new Dom(); $dom->loadFromFile('tests/data/files/small.html'); $this->assertEquals('VonBurgermeister', $dom->find('.post-user font', 0)->text); } - public function testLoadFromFileFind() + public function testLoadFromFileFind(): void { $dom = new Dom(); $dom->loadFromFile('tests/data/files/small.html'); $this->assertEquals('VonBurgermeister', $dom->find('.post-row div .post-user font', 0)->text); } - public function testLoadFromFileNotFound() + public function testLoadFromFileNotFound(): void { $dom = new Dom(); $this->expectException(\PHPHtmlParser\Exceptions\LogicalException::class); $dom->loadFromFile('tests/data/files/unkowne.html'); } - public function testLoadUtf8() + public function testLoadUtf8(): void { $dom = new Dom(); $dom->loadStr('

Dzień

'); $this->assertEquals('Dzień', $dom->find('p', 0)->text); } - public function testLoadFileWhitespace() + public function testLoadFileWhitespace(): void { $dom = new Dom(); $dom->setOptions((new Options())->setCleanupInput(false)); @@ -120,14 +120,14 @@ public function testLoadFileWhitespace() $this->assertEquals('', (string) $dom); } - public function testLoadFileBig() + public function testLoadFileBig(): void { $dom = new Dom(); $dom->loadFromFile('tests/data/files/big.html'); $this->assertEquals(20, \count($dom->find('.content-border'))); } - public function testLoadFileBigTwice() + public function testLoadFileBigTwice(): void { $dom = new Dom(); $dom->loadFromFile('tests/data/files/big.html'); @@ -135,7 +135,7 @@ public function testLoadFileBigTwice() $this->assertEquals('

Журчанье воды
Черно-белые тени
Вновь на фонтане

', $post->find('.post-message', 0)->innerHtml); } - public function testLoadFileBigTwicePreserveOption() + public function testLoadFileBigTwicePreserveOption(): void { $dom = new Dom(); $dom->loadFromFile('tests/data/files/big.html', @@ -147,7 +147,7 @@ public function testLoadFileBigTwicePreserveOption() ); } - public function testLoadFromUrl() + public function testLoadFromUrl(): void { $streamMock = Mockery::mock(\Psr\Http\Message\StreamInterface::class); $streamMock->shouldReceive('getContents') @@ -167,77 +167,77 @@ public function testLoadFromUrl() $this->assertEquals('VonBurgermeister', $dom->find('.post-row div .post-user font', 0)->text); } - public function testScriptCleanerScriptTag() + public function testScriptCleanerScriptTag(): void { $dom = new Dom(); $dom->loadStr('

.....

....

'); $this->assertEquals('....', $dom->getElementsByTag('p')[1]->innerHtml); } - public function testClosingSpan() + public function testClosingSpan(): void { $dom = new Dom(); $dom->loadStr("
sometext
"); $this->assertEquals('sometext', $dom->getElementsByTag('div')[0]->innerHtml); } - public function testMultipleDoubleQuotes() + public function testMultipleDoubleQuotes(): void { $dom = new Dom(); $dom->loadStr('Hello'); $this->assertEquals('This is a "test" of double quotes', $dom->getElementsByTag('a')[0]->title); } - public function testMultipleSingleQuotes() + public function testMultipleSingleQuotes(): void { $dom = new Dom(); $dom->loadStr("Hello"); $this->assertEquals("Ain't this the best", $dom->getElementsByTag('a')[0]->title); } - public function testBeforeClosingTag() + public function testBeforeClosingTag(): void { $dom = new Dom(); $dom->loadStr('
'); $this->assertEquals('
', (string) $dom); } - public function testCodeTag() + public function testCodeTag(): void { $dom = new Dom(); $dom->loadStr('hello$foo = "bar";'); $this->assertEquals('hello$foo = "bar";', (string) $dom); } - public function testCountChildren() + public function testCountChildren(): void { $dom = new Dom(); $dom->loadStr('hello$foo = "bar";'); $this->assertEquals(2, $dom->countChildren()); } - public function testGetChildrenArray() + public function testGetChildrenArray(): void { $dom = new Dom(); $dom->loadStr('hello$foo = "bar";'); - $this->assertInternalType('array', $dom->getChildren()); + $this->assertIsArray($dom->getChildren()); } - public function testHasChildren() + public function testHasChildren(): void { $dom = new Dom(); $dom->loadStr('hello$foo = "bar";'); $this->assertTrue($dom->hasChildren()); } - public function testWhitespaceInText() + public function testWhitespaceInText(): void { $dom = new Dom(); $dom->setOptions((new Options())->setRemoveDoubleSpace(false)); @@ -245,7 +245,7 @@ public function testWhitespaceInText() $this->assertEquals('
    Hello world
', (string) $dom); } - public function testGetComplexAttribute() + public function testGetComplexAttribute(): void { $dom = new Dom(); $dom->loadStr('Next >'); @@ -253,7 +253,7 @@ public function testGetComplexAttribute() $this->assertEquals('?search=Fort+William&session_type=face&distance=100&uqs=119846&page=4', $href); } - public function testGetComplexAttributeHtmlSpecialCharsDecode() + public function testGetComplexAttributeHtmlSpecialCharsDecode(): void { $dom = new Dom(); $dom->setOptions((new Options())->setHtmlSpecialCharsDecode(true)); @@ -264,7 +264,7 @@ public function testGetComplexAttributeHtmlSpecialCharsDecode() $this->assertEquals('?search=Fort+William&session_type=face&distance=100&uqs=119846&page=4', $href); } - public function testGetChildrenNoChildren() + public function testGetChildrenNoChildren(): void { $dom = new Dom(); $dom->loadStr('
Test
'); @@ -274,7 +274,7 @@ public function testGetChildrenNoChildren() $this->assertTrue(\count($children) === 0); } - public function testInfiniteLoopNotHappening() + public function testInfiniteLoopNotHappening(): void { $dom = new Dom(); $dom->loadStr(' @@ -290,7 +290,7 @@ public function testInfiniteLoopNotHappening() $this->assertEquals(4, \count($metaNodes)); } - public function testFindOrder() + public function testFindOrder(): void { $str = '

'; $dom = new Dom(); @@ -300,7 +300,7 @@ public function testFindOrder() $this->assertEquals('', (string) $images[0]); } - public function testCaseInSensitivity() + public function testCaseInSensitivity(): void { $str = "blah"; $dom = new Dom(); @@ -310,7 +310,7 @@ public function testCaseInSensitivity() $this->assertEquals('asdf', $FooBar->getAttribute('attribute')); } - public function testCaseSensitivity() + public function testCaseSensitivity(): void { $str = "blah"; $dom = new Dom(); @@ -320,7 +320,7 @@ public function testCaseSensitivity() $this->assertEquals('asdf', $FooBar->Attribute); } - public function testEmptyAttribute() + public function testEmptyAttribute(): void { $str = '
  • blah
  • what
'; $dom = new Dom(); @@ -330,7 +330,7 @@ public function testEmptyAttribute() $this->assertEquals(1, \count($items)); } - public function testInnerText() + public function testInnerText(): void { $html = <<123456789101112 @@ -340,7 +340,7 @@ public function testInnerText() $this->assertEquals($dom->innerText, '123456789101112'); } - public function testMultipleSquareSelector() + public function testMultipleSquareSelector(): void { $dom = new Dom(); $dom->loadStr(''); @@ -349,7 +349,7 @@ public function testMultipleSquareSelector() $this->assertEquals(1, \count($items)); } - public function testNotSquareSelector() + public function testNotSquareSelector(): void { $dom = new Dom(); $dom->loadStr(''); @@ -358,7 +358,7 @@ public function testNotSquareSelector() $this->assertEquals(1, \count($items)); } - public function testStartSquareSelector() + public function testStartSquareSelector(): void { $dom = new Dom(); $dom->loadStr(''); @@ -367,7 +367,7 @@ public function testStartSquareSelector() $this->assertEquals(1, \count($items)); } - public function testEndSquareSelector() + public function testEndSquareSelector(): void { $dom = new Dom(); $dom->loadStr(''); @@ -376,7 +376,7 @@ public function testEndSquareSelector() $this->assertEquals(1, \count($items)); } - public function testStarSquareSelector() + public function testStarSquareSelector(): void { $dom = new Dom(); $dom->loadStr(''); @@ -385,7 +385,7 @@ public function testStarSquareSelector() $this->assertEquals(1, \count($items)); } - public function testStarFullRegexSquareSelector() + public function testStarFullRegexSquareSelector(): void { $dom = new Dom(); $dom->loadStr(''); @@ -394,7 +394,7 @@ public function testStarFullRegexSquareSelector() $this->assertEquals(1, \count($items)); } - public function testFailedSquareSelector() + public function testFailedSquareSelector(): void { $dom = new Dom(); $dom->loadStr(''); @@ -403,7 +403,7 @@ public function testFailedSquareSelector() $this->assertEquals(1, \count($items)); } - public function testLoadGetAttributeWithBackslash() + public function testLoadGetAttributeWithBackslash(): void { $dom = new Dom(); $dom->loadStr('
\
demo
'); @@ -411,7 +411,7 @@ public function testLoadGetAttributeWithBackslash() $this->assertEquals('/img/test.png', $imgs->getAttribute('src')); } - public function test25ChildrenFound() + public function test25ChildrenFound(): void { $dom = new Dom(); $dom->setOptions((new Options())->setWhitespaceTextNode(false)); @@ -420,7 +420,7 @@ public function test25ChildrenFound() $this->assertEquals(25, \count($children)); } - public function testHtml5PageloadStr() + public function testHtml5PageloadStr(): void { $dom = new Dom(); $dom->loadFromFile('tests/data/files/html5.html'); @@ -430,7 +430,7 @@ public function testHtml5PageloadStr() $this->assertEquals('max-width: 29px', $div->getAttribute('style')); } - public function testFindAttributeInBothParentAndChild() + public function testFindAttributeInBothParentAndChild(): void { $dom = new Dom(); $dom->loadStr(' @@ -442,7 +442,7 @@ public function testFindAttributeInBothParentAndChild() $this->assertCount(2, $nodes); } - public function testLessThanCharacterInJavascript() + public function testLessThanCharacterInJavascript(): void { $results = (new Dom())->loadStr('
', (new Options())->setCleanupInput(false) ->setRemoveScripts(false) - )->find('body'); + )->find('body'); $this->assertCount(1, $results); } diff --git a/tests/Node/TextTest.php b/tests/Node/TextTest.php index dae77b48..2289bcd5 100755 --- a/tests/Node/TextTest.php +++ b/tests/Node/TextTest.php @@ -4,7 +4,6 @@ use PHPHtmlParser\Dom; use PHPHtmlParser\Dom\Node\TextNode; -use PHPHtmlParser\Options; use PHPUnit\Framework\TestCase; use stringEncode\Encode; diff --git a/tests/Options/CleanupTest.php b/tests/Options/CleanupTest.php index 576541a7..af74ad39 100755 --- a/tests/Options/CleanupTest.php +++ b/tests/Options/CleanupTest.php @@ -40,8 +40,10 @@ public function testRemoveStylesFalse(): void $dom->setOptions((new Options())->setRemoveStyles(false)); $dom->loadFromFile('tests/data/files/big.html'); $this->assertEquals(1, \count($dom->find('style'))); - $this->assertEquals('text/css', - $dom->find('style')->getAttribute('type')); + $this->assertEquals( + 'text/css', + $dom->find('style')->getAttribute('type') + ); } public function testRemoveScriptsTrue(): void @@ -58,8 +60,10 @@ public function testRemoveScriptsFalse(): void $dom->setOptions((new Options())->setRemoveScripts(false)); $dom->loadFromFile('tests/data/files/big.html'); $this->assertEquals(22, \count($dom->find('script'))); - $this->assertEquals('text/javascript', - $dom->find('script')->getAttribute('type')); + $this->assertEquals( + 'text/javascript', + $dom->find('script')->getAttribute('type') + ); } public function testSmartyScripts(): void From f756e8f473716084f3e57349ac8136d2461c5345 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Mon, 10 Oct 2022 15:09:37 +0300 Subject: [PATCH 13/15] Include php-cs-fixer in CI. --- .github/workflows/ci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4058be1f..9c426a32 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,3 +40,6 @@ jobs: - name: Run tests run: vendor/bin/phpunit + + - name: Run php-cs-fixer + run: vendor/bin/php-cs-fixer fix --dry-run -v --diff From bf66dc20dc9d93e85249a4a7fe21a48b503becb4 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Mon, 10 Oct 2022 15:12:55 +0300 Subject: [PATCH 14/15] Updating CONTRIBUTING. --- CONTRIBUTING.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index df0ac285..2e805244 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,8 +7,9 @@ This page contains guidelines for contributing to the PHPHtmlParser package. Ple We follow the [PSR-4](https://www.php-fig.org/psr/psr-4/) autoloading standard and follow the [PSR-12](https://www.php-fig.org/psr/psr-12/) coding style guide. To make it easy to comply with the coding standard we use php-cs-fixer to manage the style of the code base. Before pushing your code please ensure you run the following on your changes. ```bash +./vendor/bin/phpunit ./vendor/bin/php-cs-fixer fix ``` -Please ensure you comply to these standards when creating a PR to make it easy to review and merge. +Please ensure you comply to these standards when creating a PR to make it easy to review and merge. Thank you. From 54c47c23ef6803b4ed9a5494ec6b001c41ab48dd Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Mon, 10 Oct 2022 16:58:54 +0300 Subject: [PATCH 15/15] Relax the PHP version requirement to allow any version from 7.4 up. --- CHANGELOG.md | 5 +++++ composer.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e62a2b7..e681bdbd 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 4.0.1 + +### Changed +- Relaxed the PHP version requirement to allow anything from 7.4 up. + ## 4.0.0 ### Added diff --git a/composer.json b/composer.json index b19143a6..14dc7d21 100755 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "php": ">=7.4.7", + "php": ">=7.4", "ext-mbstring": "*", "ext-zlib": "*", "ext-curl": "*",