Skip to content

Commit f2097c6

Browse files
committed
Update dependencies and tests for PHP 8.1 compatibility.
Bumps minimum PHP version to 7.4.7.
1 parent ff6c667 commit f2097c6

24 files changed

+291
-306
lines changed

composer.json

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,39 @@
1010
"name": "Gilles Paquette",
1111
"email": "[email protected]",
1212
"homepage": "http://gillespaquette.ca"
13+
},
14+
{
15+
"name": "Ere Maijala",
16+
"email": "[email protected]",
17+
"homepage": "http://nationallibrary.fi"
1318
}
1419
],
1520
"require": {
16-
"php": ">=7.2",
21+
"php": ">=7.4",
1722
"ext-mbstring": "*",
1823
"ext-zlib": "*",
1924
"ext-curl": "*",
2025
"paquettg/string-encode": "~1.0.0",
21-
"php-http/httplug": "^2.1",
22-
"guzzlehttp/guzzle": "^7.0",
23-
"guzzlehttp/psr7": "^1.6",
24-
"myclabs/php-enum": "^1.7"
26+
"php-http/httplug": "^2.3.0",
27+
"guzzlehttp/guzzle": "^7.5.0",
28+
"guzzlehttp/psr7": "^2.4.1",
29+
"myclabs/php-enum": "^1.8.4"
2530
},
2631
"require-dev": {
27-
"phpunit/phpunit": "^7.5.1",
32+
"phpunit/phpunit": "^9.5.25",
2833
"mockery/mockery": "^1.2",
29-
"infection/infection": "^0.13.4",
30-
"phan/phan": "^2.4",
31-
"friendsofphp/php-cs-fixer": "^2.16"
34+
"infection/infection": "^0.26.6",
35+
"phan/phan": "^5.4.1",
36+
"friendsofphp/php-cs-fixer": "^3.11.0"
3237
},
3338
"autoload": {
34-
"psr-4": {
39+
"psr-4": {
3540
"PHPHtmlParser\\": "src/PHPHtmlParser"
3641
}
42+
},
43+
"config": {
44+
"allow-plugins": {
45+
"infection/extension-installer": false
46+
}
3747
}
3848
}

src/PHPHtmlParser/DTO/Tag/AttributeDTO.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public function htmlspecialcharsDecode(): void
5555
*/
5656
public function encodeValue(Encode $encode)
5757
{
58-
$this->value = $encode->convert($this->value);
58+
if (null !== $this->value) {
59+
$this->value = $encode->convert($this->value);
60+
}
5961
}
6062
}

tests/CollectionTest.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class CollectionTest extends TestCase
1313
{
14-
public function testEach()
14+
public function testEach(): void
1515
{
1616
$root = new HtmlNode(new Tag('root'));
1717
$parent = new HtmlNode(new Tag('div'));
@@ -32,23 +32,21 @@ public function testEach()
3232
$this->assertEquals(2, $count);
3333
}
3434

35-
/**
36-
* @expectedException \PHPHtmlParser\Exceptions\EmptyCollectionException
37-
*/
38-
public function testCallNoNodes()
35+
public function testCallNoNodes(): void
3936
{
4037
$collection = new Collection();
38+
$this->expectException(\PHPHtmlParser\Exceptions\EmptyCollectionException::class);
4139
$collection->innerHtml();
4240
}
4341

44-
public function testNoNodeString()
42+
public function testNoNodeString(): void
4543
{
4644
$collection = new Collection();
4745
$string = (string) $collection;
4846
$this->assertEmpty($string);
4947
}
5048

51-
public function testCallMagic()
49+
public function testCallMagic(): void
5250
{
5351
$root = new HtmlNode(new Tag('root'));
5452
$parent = new HtmlNode(new Tag('div'));
@@ -64,7 +62,7 @@ public function testCallMagic()
6462
$this->assertEquals($child3->id(), $selector->find($root)->id());
6563
}
6664

67-
public function testGetMagic()
65+
public function testGetMagic(): void
6866
{
6967
$root = new HtmlNode(new Tag('root'));
7068
$parent = new HtmlNode(new Tag('div'));
@@ -80,16 +78,14 @@ public function testGetMagic()
8078
$this->assertEquals($child3->innerHtml, $selector->find($root)->innerHtml);
8179
}
8280

83-
/**
84-
* @expectedException \PHPHtmlParser\Exceptions\EmptyCollectionException
85-
*/
86-
public function testGetNoNodes()
81+
public function testGetNoNodes(): void
8782
{
8883
$collection = new Collection();
84+
$this->expectException(\PHPHtmlParser\Exceptions\EmptyCollectionException::class);
8985
$collection->innerHtml;
9086
}
9187

92-
public function testToStringMagic()
88+
public function testToStringMagic(): void
9389
{
9490
$root = new HtmlNode(new Tag('root'));
9591
$parent = new HtmlNode(new Tag('div'));
@@ -105,7 +101,7 @@ public function testToStringMagic()
105101
$this->assertEquals((string) $child3, (string) $selector->find($root));
106102
}
107103

108-
public function testToArray()
104+
public function testToArray(): void
109105
{
110106
$root = new HtmlNode(new Tag('root'));
111107
$parent = new HtmlNode(new Tag('div'));
@@ -124,21 +120,21 @@ public function testToArray()
124120
$this->assertEquals($child3->id(), $lastA->id());
125121
}
126122

127-
public function testGetIterator()
123+
public function testGetIterator(): void
128124
{
129125
$collection = new Collection();
130126
$iterator = $collection->getIterator();
131127
$this->assertTrue($iterator instanceof \ArrayIterator);
132128
}
133129

134-
public function testOffsetSet()
130+
public function testOffsetSet(): void
135131
{
136132
$collection = new Collection();
137133
$collection->offsetSet(7, true);
138134
$this->assertTrue($collection->offsetGet(7));
139135
}
140136

141-
public function testOffsetUnset()
137+
public function testOffsetUnset(): void
142138
{
143139
$collection = new Collection();
144140
$collection->offsetSet(7, true);

tests/ContentTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,86 +8,86 @@
88

99
class ContentTest extends TestCase
1010
{
11-
public function testChar()
11+
public function testChar(): void
1212
{
1313
$content = new Content('abcde');
1414
$this->assertEquals('a', $content->char());
1515
}
1616

17-
public function testCharSelection()
17+
public function testCharSelection(): void
1818
{
1919
$content = new Content('abcde');
2020
$this->assertEquals('d', $content->char(3));
2121
}
2222

23-
public function testFastForward()
23+
public function testFastForward(): void
2424
{
2525
$content = new Content('abcde');
2626
$content->fastForward(2);
2727
$this->assertEquals('c', $content->char());
2828
}
2929

30-
public function testRewind()
30+
public function testRewind(): void
3131
{
3232
$content = new Content('abcde');
3333
$content->fastForward(2)
3434
->rewind(1);
3535
$this->assertEquals('b', $content->char());
3636
}
3737

38-
public function testRewindNegative()
38+
public function testRewindNegative(): void
3939
{
4040
$content = new Content('abcde');
4141
$content->fastForward(2)
4242
->rewind(100);
4343
$this->assertEquals('a', $content->char());
4444
}
4545

46-
public function testCopyUntil()
46+
public function testCopyUntil(): void
4747
{
4848
$content = new Content('abcdeedcba');
4949
$this->assertEquals('abcde', $content->copyUntil('ed'));
5050
}
5151

52-
public function testCopyUntilChar()
52+
public function testCopyUntilChar(): void
5353
{
5454
$content = new Content('abcdeedcba');
5555
$this->assertEquals('ab', $content->copyUntil('edc', true));
5656
}
5757

58-
public function testCopyUntilEscape()
58+
public function testCopyUntilEscape(): void
5959
{
6060
$content = new Content('foo\"bar"bax');
6161
$this->assertEquals('foo\"bar', $content->copyUntil('"', false, true));
6262
}
6363

64-
public function testCopyUntilNotFound()
64+
public function testCopyUntilNotFound(): void
6565
{
6666
$content = new Content('foo\"bar"bax');
6767
$this->assertEquals('foo\"bar"bax', $content->copyUntil('baz'));
6868
}
6969

70-
public function testCopyByToken()
70+
public function testCopyByToken(): void
7171
{
7272
$content = new Content('<a href="google.com">');
7373
$content->fastForward(3);
7474
$this->assertEquals('href="google.com"', $content->copyByToken(StringToken::ATTR(), true));
7575
}
7676

77-
public function testSkip()
77+
public function testSkip(): void
7878
{
7979
$content = new Content('abcdefghijkl');
8080
$content->skip('abcd');
8181
$this->assertEquals('e', $content->char());
8282
}
8383

84-
public function testSkipCopy()
84+
public function testSkipCopy(): void
8585
{
8686
$content = new Content('abcdefghijkl');
8787
$this->assertEquals('abcd', $content->skip('abcd', true));
8888
}
8989

90-
public function testSkipByToken()
90+
public function testSkipByToken(): void
9191
{
9292
$content = new Content(' b c');
9393
$content->fastForward(1);

tests/Dom/CleanerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class CleanerTest extends TestCase
1010
{
11-
public function testCleanEregiFailureFile()
11+
public function testCleanEregiFailureFile(): void
1212
{
1313
$cleaner = new Cleaner();
1414
$string = $cleaner->clean(\file_get_contents('tests/data/files/mvEregiReplaceFailure.html'), new Options(), 'utf-8');

tests/Dom/CommentTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CommentTest extends TestCase
1313
*/
1414
private $dom;
1515

16-
public function setUp()
16+
public function setUp(): void
1717
{
1818
$dom = new Dom();
1919
$options = new Options();
@@ -22,12 +22,12 @@ public function setUp()
2222
$this->dom = $dom;
2323
}
2424

25-
public function tearDown()
25+
public function tearDown(): void
2626
{
2727
Mockery::close();
2828
}
2929

30-
public function testLoadCommentInnerHtml()
30+
public function testLoadCommentInnerHtml(): void
3131
{
3232
$this->assertEquals('<!-- test comment with number 2 -->', $this->dom->innerHtml);
3333
}

tests/Dom/LoadTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,83 +12,83 @@ class LoadTest extends TestCase
1212
*/
1313
private $dom;
1414

15-
public function setUp()
15+
public function setUp(): void
1616
{
1717
$dom = new Dom();
1818
$dom->loadStr('<div class="all"><br><p>Hey bro, <a href="google.com" id="78" data-quote="\"">click here</a></br></div><br class="both" />');
1919
$this->dom = $dom;
2020
}
2121

22-
public function tearDown()
22+
public function tearDown(): void
2323
{
2424
Mockery::close();
2525
}
2626

27-
public function testLoadEscapeQuotes()
27+
public function testLoadEscapeQuotes(): void
2828
{
2929
$a = $this->dom->find('a', 0);
3030
$this->assertEquals('<a href="google.com" id="78" data-quote="\"">click here</a>', $a->outerHtml);
3131
}
3232

33-
public function testLoadNoClosingTag()
33+
public function testLoadNoClosingTag(): void
3434
{
3535
$p = $this->dom->find('p', 0);
3636
$this->assertEquals('Hey bro, <a href="google.com" id="78" data-quote="\"">click here</a>', $p->innerHtml);
3737
}
3838

39-
public function testLoadClosingTagOnSelfClosing()
39+
public function testLoadClosingTagOnSelfClosing(): void
4040
{
4141
$this->assertCount(2, $this->dom->find('br'));
4242
}
4343

44-
public function testIncorrectAccess()
44+
public function testIncorrectAccess(): void
4545
{
4646
$div = $this->dom->find('div', 0);
4747
$this->assertEquals(null, $div->foo);
4848
}
4949

50-
public function testLoadAttributeOnSelfClosing()
50+
public function testLoadAttributeOnSelfClosing(): void
5151
{
5252
$br = $this->dom->find('br', 1);
5353
$this->assertEquals('both', $br->getAttribute('class'));
5454
}
5555

56-
public function testToStringMagic()
56+
public function testToStringMagic(): void
5757
{
5858
$this->assertEquals('<div class="all"><br /><p>Hey bro, <a href="google.com" id="78" data-quote="\"">click here</a></p></div><br class="both" />', (string) $this->dom);
5959
}
6060

61-
public function testGetMagic()
61+
public function testGetMagic(): void
6262
{
6363
$this->assertEquals('<div class="all"><br /><p>Hey bro, <a href="google.com" id="78" data-quote="\"">click here</a></p></div><br class="both" />', $this->dom->innerHtml);
6464
}
6565

66-
public function testFirstChild()
66+
public function testFirstChild(): void
6767
{
6868
$this->assertEquals('<div class="all"><br /><p>Hey bro, <a href="google.com" id="78" data-quote="\"">click here</a></p></div>', $this->dom->firstChild()->outerHtml);
6969
}
7070

71-
public function testLastChild()
71+
public function testLastChild(): void
7272
{
7373
$this->assertEquals('<br class="both" />', $this->dom->lastChild()->outerHtml);
7474
}
7575

76-
public function testGetElementById()
76+
public function testGetElementById(): void
7777
{
7878
$this->assertEquals('<a href="google.com" id="78" data-quote="\"">click here</a>', $this->dom->getElementById('78')->outerHtml);
7979
}
8080

81-
public function testGetElementsByTag()
81+
public function testGetElementsByTag(): void
8282
{
8383
$this->assertEquals('<p>Hey bro, <a href="google.com" id="78" data-quote="\"">click here</a></p>', $this->dom->getElementsByTag('p')[0]->outerHtml);
8484
}
8585

86-
public function testGetElementsByClass()
86+
public function testGetElementsByClass(): void
8787
{
8888
$this->assertEquals('<br /><p>Hey bro, <a href="google.com" id="78" data-quote="\"">click here</a></p>', $this->dom->getElementsByClass('all')[0]->innerHtml);
8989
}
9090

91-
public function testDeleteNode()
91+
public function testDeleteNode(): void
9292
{
9393
$a = $this->dom->find('a')[0];
9494
$a->delete();

0 commit comments

Comments
 (0)