Skip to content

Commit 54a8e70

Browse files
authored
Merge pull request #3 from thesoftwarefanatics/update-supported-versions
Update supported PHP versions
2 parents fbd2cb8 + cf75e1a commit 54a8e70

20 files changed

+112
-97
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
language: php
22

33
php:
4-
- 5.6
5-
- 7.0
6-
- hhvm
4+
- 7.1
5+
- 7.2
6+
- nightly
77

88
install:
99
- composer self-update
1010
- composer install --dev --no-interaction
1111

12+
allowed_failures:
13+
- nightly
14+
1215
script:
1316
- vendor/bin/phpunit
1417

composer.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
}
1919
],
2020
"require": {
21-
"php": "^5.6 || ^7.0",
22-
"paquettg/string-encode": "~0.1.0"
21+
"php": "^7.1",
22+
"paquettg/string-encode": "^0.1.1"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "~5.3.0",
26-
"satooshi/php-coveralls": "~1.0.0",
27-
"mockery/mockery": "~0.9.0"
25+
"phpunit/phpunit": "^6.5",
26+
"php-coveralls/php-coveralls": "^2.0",
27+
"mockery/mockery": "^1.0"
2828
},
2929
"replace": {
3030
"paquettg/php-html-parser": "self.version"
@@ -34,5 +34,9 @@
3434
"PHPHtmlParser": "src/"
3535
}
3636
},
37-
"prefer-stable": true
37+
"extra": {
38+
"branch-alias": {
39+
"dev-master": "1.8.x-dev"
40+
}
41+
}
3842
}

src/PHPHtmlParser/Dom.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ protected function clean($str)
359359
}
360360

361361
// remove white space before closing tags
362-
$str = mb_eregi_replace("'\s+>", "'>", $str);
363-
$str = mb_eregi_replace('"\s+>', '">', $str);
362+
$str = preg_replace("#'\s+>#i", "'>", $str);
363+
$str = preg_replace('#"\s+>#i', '">', $str);
364364

365365
// clean out the \n\r
366366
$replace = ' ';
@@ -370,31 +370,31 @@ protected function clean($str)
370370
$str = str_replace(["\r\n", "\r", "\n"], $replace, $str);
371371

372372
// strip the doctype
373-
$str = mb_eregi_replace("<!doctype(.*?)>", '', $str);
373+
$str = preg_replace("#<!doctype(.*?)>#i", '', $str);
374374

375375
// strip out comments
376-
$str = mb_eregi_replace("<!--(.*?)-->", '', $str);
376+
$str = preg_replace("#<!--(.*?)-->#i", '', $str);
377377

378378
// strip out cdata
379-
$str = mb_eregi_replace("<!\[CDATA\[(.*?)\]\]>", '', $str);
379+
$str = preg_replace("#<!\[CDATA\[(.*?)\]\]>#i", '', $str);
380380

381381
// strip out <script> tags
382382
if ($this->options->get('removeScripts') == true) {
383-
$str = mb_eregi_replace("<\s*script[^>]*[^/]>(.*?)<\s*/\s*script\s*>", '', $str);
384-
$str = mb_eregi_replace("<\s*script\s*>(.*?)<\s*/\s*script\s*>", '', $str);
383+
$str = preg_replace("#<\s*script[^>]*[^/]>(.*?)<\s*/\s*script\s*>#i", '', $str);
384+
$str = preg_replace("#<\s*script\s*>(.*?)<\s*/\s*script\s*>#i", '', $str);
385385
}
386386

387387
// strip out <style> tags
388388
if ($this->options->get('removeStyles') == true) {
389-
$str = mb_eregi_replace("<\s*style[^>]*[^/]>(.*?)<\s*/\s*style\s*>", '', $str);
390-
$str = mb_eregi_replace("<\s*style\s*>(.*?)<\s*/\s*style\s*>", '', $str);
389+
$str = preg_replace("#<\s*style[^>]*[^/]>(.*?)<\s*/\s*style\s*>#", '', $str);
390+
$str = preg_replace("#<\s*style\s*>(.*?)<\s*/\s*style\s*>#", '', $str);
391391
}
392392

393393
// strip out server side scripts
394-
$str = mb_eregi_replace("(<\?)(.*?)(\?>)", '', $str);
394+
$str = preg_replace("#(<\?)(.*?)(\?>)#i", '', $str);
395395

396396
// strip smarty scripts
397-
$str = mb_eregi_replace("(\{\w)(.*?)(\})", '', $str);
397+
$str = preg_replace("#(\{\w)(.*?)(\})#i", '', $str);
398398

399399
return $str;
400400
}

src/PHPHtmlParser/Dom/TextNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class TextNode extends LeafNode
3838
public function __construct($text)
3939
{
4040
// remove double spaces
41-
$text = mb_ereg_replace('\s+', ' ', $text);
41+
$text = preg_replace('#\s+#', ' ', $text);
4242

4343
// restore line breaks
4444
$text = str_replace('&#10;', "\n", $text);

src/PHPHtmlParser/Selector.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ protected function parseSelectorString($selector)
168168
protected function seek(array $nodes, array $rule, array $options)
169169
{
170170
// XPath index
171-
if (count($rule['tag']) > 0 &&
172-
count($rule['key']) > 0 &&
171+
if (!empty($rule['tag']) &&
173172
is_numeric($rule['key'])
174173
) {
175174
$count = 0;

tests/CollectionTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
use PHPHtmlParser\Dom\HtmlNode;
55
use PHPHtmlParser\Dom\Tag;
66
use PHPHtmlParser\Dom\Collection;
7+
use PHPUnit\Framework\TestCase;
78

8-
class CollectionTest extends PHPUnit_Framework_TestCase {
9+
class CollectionTest extends TestCase {
910

1011
public function testEach()
1112
{
@@ -29,10 +30,10 @@ public function testEach()
2930
}
3031

3132
/**
32-
* @expectedException PHPHtmlParser\Exceptions\EmptyCollectionException
3333
*/
3434
public function testCallNoNodes()
3535
{
36+
$this->expectException('PHPHtmlParser\Exceptions\EmptyCollectionException');
3637
$collection = new Collection();
3738
$collection->innerHtml();
3839
}
@@ -70,10 +71,10 @@ public function testGetMagic()
7071
}
7172

7273
/**
73-
* @expectedException PHPHtmlParser\Exceptions\EmptyCollectionException
7474
*/
7575
public function testGetNoNodes()
7676
{
77+
$this->expectException('PHPHtmlParser\Exceptions\EmptyCollectionException');
7778
$collection = new Collection();
7879
$collection->innerHtml;
7980
}

tests/ContentTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

33
use PHPHtmlParser\Content;
4+
use PHPUnit\Framework\TestCase;
45

5-
class ContentTest extends PHPUnit_Framework_TestCase {
6+
class ContentTest extends TestCase {
67

78
public function testChar()
89
{

tests/DomTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

33
use PHPHtmlParser\Dom;
4+
use PHPHtmlParser\Exceptions\NotLoadedException;
5+
use PHPUnit\Framework\TestCase;
46

5-
class DomTest extends PHPUnit_Framework_TestCase {
7+
class DomTest extends TestCase {
68

79
public function tearDown()
810
{
@@ -17,11 +19,9 @@ public function testLoad()
1719
$this->assertEquals('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>', $div->outerHtml);
1820
}
1921

20-
/**
21-
* @expectedException PHPHtmlParser\Exceptions\NotLoadedException
22-
*/
2322
public function testNotLoaded()
2423
{
24+
$this->expectException(NotLoadedException::class);
2525
$dom = new Dom;
2626
$div = $dom->find('div', 0);
2727
}
@@ -147,21 +147,21 @@ public function testLoadUpperCase()
147147
public function testLoadWithFile()
148148
{
149149
$dom = new Dom;
150-
$dom->loadFromFile('tests/files/small.html');
150+
$dom->loadFromFile(__DIR__ . '/files/small.html');
151151
$this->assertEquals('VonBurgermeister', $dom->find('.post-user font', 0)->text);
152152
}
153153

154154
public function testLoadFromFile()
155155
{
156156
$dom = new Dom;
157-
$dom->loadFromFile('tests/files/small.html');
157+
$dom->loadFromFile(__DIR__ . '/files/small.html');
158158
$this->assertEquals('VonBurgermeister', $dom->find('.post-user font', 0)->text);
159159
}
160160

161161
public function testLoadFromFileFind()
162162
{
163163
$dom = new Dom;
164-
$dom->loadFromFile('tests/files/small.html');
164+
$dom->loadFromFile(__DIR__ . '/files/small.html');
165165
$this->assertEquals('VonBurgermeister', $dom->find('.post-row div .post-user font', 0)->text);
166166
}
167167

@@ -175,22 +175,22 @@ public function testLoadUtf8()
175175
public function testLoadFileBig()
176176
{
177177
$dom = new Dom;
178-
$dom->loadFromFile('tests/files/big.html');
178+
$dom->loadFromFile(__DIR__ . '/files/big.html');
179179
$this->assertEquals(10, count($dom->find('.content-border')));
180180
}
181181

182182
public function testLoadFileBigTwice()
183183
{
184184
$dom = new Dom;
185-
$dom->loadFromFile('tests/files/big.html');
185+
$dom->loadFromFile(__DIR__ . '/files/big.html');
186186
$post = $dom->find('.post-row', 0);
187187
$this->assertEquals(' <p>Журчанье воды<br /> Черно-белые тени<br /> Вновь на фонтане</p> ', $post->find('.post-message', 0)->innerHtml);
188188
}
189189

190190
public function testLoadFileBigTwicePreserveOption()
191191
{
192192
$dom = new Dom;
193-
$dom->loadFromFile('tests/files/big.html', ['preserveLineBreaks' => true]);
193+
$dom->loadFromFile(__DIR__ . '/files/big.html', ['preserveLineBreaks' => true]);
194194
$post = $dom->find('.post-row', 0);
195195
$this->assertEquals('<p>Журчанье воды<br />
196196
Черно-белые тени<br />
@@ -203,7 +203,7 @@ public function testLoadFromUrl()
203203
$curl->shouldReceive('get')
204204
->once()
205205
->with('http://google.com')
206-
->andReturn(file_get_contents('tests/files/small.html'));
206+
->andReturn(file_get_contents(__DIR__ . '/files/small.html'));
207207

208208
$dom = new Dom;
209209
$dom->loadFromUrl('http://google.com', [], $curl);
@@ -262,7 +262,7 @@ public function testGetElementsByClass()
262262
public function testEnforceEncoding()
263263
{
264264
$dom = new Dom;
265-
$dom->load('tests/files/horrible.html', [
265+
$dom->load(__DIR__ . '/files/horrible.html', [
266266
'enforceEncoding' => 'UTF-8',
267267
]);
268268
$this->assertNotEquals('<input type="submit" tabindex="0" name="submit" value="Информации" />', $dom->find('table input', 1)->outerHtml);

tests/Node/ChildrenTest.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
22

33
use PHPHtmlParser\Dom\MockNode as Node;
4+
use PHPHtmlParser\Exceptions\ChildNotFoundException;
5+
use PHPHtmlParser\Exceptions\ParentNotFoundException;
6+
use PHPUnit\Framework\TestCase;
47

5-
class NodeChildTest extends PHPUnit_Framework_TestCase {
8+
class NodeChildTest extends TestCase {
69

710
public function testGetParent()
811
{
@@ -32,22 +35,20 @@ public function testNextSibling()
3235
$this->assertEquals($child2->id(), $child->nextSibling()->id());
3336
}
3437

35-
/**
36-
* @expectedException PHPHtmlParser\Exceptions\ChildNotFoundException
37-
*/
3838
public function testNextSiblingNotFound()
3939
{
40+
$this->expectException(ChildNotFoundException::class);
41+
4042
$parent = new Node;
4143
$child = new Node;
4244
$child->setParent($parent);
4345
$child->nextSibling();
4446
}
4547

46-
/**
47-
* @expectedException PHPHtmlParser\Exceptions\ParentNotFoundException
48-
*/
4948
public function testNextSiblingNoParent()
5049
{
50+
$this->expectException(ParentNotFoundException::class);
51+
5152
$child = new Node;
5253
$child->nextSibling();
5354
}
@@ -62,22 +63,20 @@ public function testPreviousSibling()
6263
$this->assertEquals($child->id(), $child2->previousSibling()->id());
6364
}
6465

65-
/**
66-
* @expectedException PHPHtmlParser\Exceptions\ChildNotFoundException
67-
*/
6866
public function testPreviousSiblingNotFound()
6967
{
68+
$this->expectException(ChildNotFoundException::class);
69+
7070
$parent = new Node;
7171
$node = new Node;
7272
$node->setParent($parent);
7373
$node->previousSibling();
7474
}
7575

76-
/**
77-
* @expectedException PHPHtmlParser\Exceptions\ParentNotFoundException
78-
*/
7976
public function testPreviousSiblingNoParent()
8077
{
78+
$this->expectException(ParentNotFoundException::class);
79+
8180
$child = new Node;
8281
$child->previousSibling();
8382
}

tests/Node/HtmlTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
use PHPHtmlParser\Dom\TextNode;
66
use PHPHtmlParser\Dom\MockNode;
77
use PHPHtmlParser\Dom\Tag;
8+
use PHPHtmlParser\Exceptions\ParentNotFoundException;
9+
use PHPHtmlParser\Exceptions\UnknownChildTypeException;
10+
use PHPUnit\Framework\TestCase;
811

9-
class NodeHtmlTest extends PHPUnit_Framework_TestCase {
12+
class NodeHtmlTest extends TestCase {
1013

1114
public function testInnerHtml()
1215
{
@@ -65,11 +68,10 @@ public function testInnerHtmlTwice()
6568
$this->assertEquals($inner, $parent->innerHtml());
6669
}
6770

68-
/**
69-
* @expectedException PHPHtmlParser\Exceptions\UnknownChildTypeException
70-
*/
7171
public function testInnerHtmlUnkownChild()
7272
{
73+
$this->expectException(UnknownChildTypeException::class);
74+
7375
$div = new Tag('div');
7476
$div->setAttributes([
7577
'class' => [
@@ -447,11 +449,10 @@ public function testIterator()
447449
$this->assertEquals(2, $children);
448450
}
449451

450-
/**
451-
* @expectedException PHPHtmlParser\Exceptions\ParentNotFoundException
452-
*/
453452
public function testAncestorByTagFailure()
454453
{
454+
$this->expectException(ParentNotFoundException::class);
455+
455456
$a = new Tag('a');
456457
$node = new HtmlNode($a);
457458
$node->ancestorByTag('div');

0 commit comments

Comments
 (0)