Skip to content

Commit b6fcc15

Browse files
committed
update tests
1 parent 91b486d commit b6fcc15

File tree

9 files changed

+181
-8
lines changed

9 files changed

+181
-8
lines changed

.gitignore

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
### Composer template
21
composer.phar
2+
composer.lock
33
/vendor/
44
.idea/
5-
6-
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
7-
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
8-
composer.lock
9-
5+
build

.scrutinizer.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
build:
2+
3+
environment:
4+
php:
5+
version: 7.1
6+
7+
nodes:
8+
analysis:
9+
project_setup:
10+
override: true
11+
tests:
12+
override:
13+
- php-scrutinizer-run
14+
-
15+
command: 'vendor/bin/phpunit --coverage-clover=some-file'
16+
coverage:
17+
file: 'some-file'
18+
format: 'clover'
19+
20+
filter:
21+
excluded_paths: [demo/*, tests/*, docs/*]
22+
23+
checks:
24+
25+
php:
26+
remove_extra_empty_lines: true
27+
remove_php_closing_tag: true
28+
remove_trailing_whitespace: true
29+
30+
fix_use_statements:
31+
remove_unused: true
32+
preserve_multiple: false
33+
preserve_blanklines: true
34+
order_alphabetically: true
35+
36+
fix_php_opening_tag: true
37+
fix_linefeed: true
38+
fix_line_ending: true
39+
fix_identation_4spaces: true
40+
fix_doc_comments: true

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: php
2+
php:
3+
- '7.1'
4+
- '7.2'
5+
- nightly
6+
7+
before_script:
8+
- "composer install"

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@
1616
"php": "^7.1",
1717
"ext-xml": "*"
1818
},
19+
"require-dev": {
20+
"bavix/tests": "^1.0"
21+
},
1922
"autoload": {
2023
"files": [
2124
"helpers/functions.php"
2225
],
2326
"psr-4": {
2427
"Bavix\\": "src/"
2528
}
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"Tests\\": "tests/"
33+
}
2634
}
2735
}

phpunit.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<phpunit bootstrap="vendor/autoload.php">
2+
3+
<testsuites>
4+
<testsuite name="bavix">
5+
<directory suffix=".php">tests/AdvancedHtmlDom</directory>
6+
</testsuite>
7+
</testsuites>
8+
9+
<filter>
10+
<whitelist
11+
addUncoveredFilesFromWhitelist="true"
12+
processUncoveredFilesFromWhitelist="true">
13+
14+
<directory suffix=".php">./src/</directory>
15+
</whitelist>
16+
</filter>
17+
18+
<logging>
19+
<log type="coverage-html" target="./build/html/"/>
20+
<log type="coverage-clover" target="./build/logs/clover.xml"/>
21+
</logging>
22+
23+
</phpunit>

src/AdvancedHtmlDom/AdvancedHtmlDom.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public function load($html, $is_xml = false)
6969
$this->dom = new \DOMDocument();
7070
if ($is_xml)
7171
{
72-
@$this->dom->loadXML(\preg_replace('/xmlns=".*?"/ ', '', $html));
72+
$this->dom->loadXML(\preg_replace('/xmlns=".*?"/ ', '', $html));
7373
}
7474
else
7575
{
76-
@$this->dom->loadHTML($html);
76+
$this->dom->loadHTML($html);
7777
}
7878
$this->xpath = new \DOMXPath($this->dom);
7979
//$this->root = new AHTMLNode($this->dom->documentElement, $this->doc);

tests/AdvancedHtmlDom/BaseTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Tests\AdvancedHtmlDom;
4+
5+
use Tests\Unit;
6+
7+
class BaseTest extends Unit
8+
{
9+
10+
public function testSimple()
11+
{
12+
$this->dom->loadFile(
13+
$this->partial('base.simple')
14+
);
15+
16+
preg_match('~<h1.*>(.+)</h1>~', $this->dom->html(), $outs);
17+
18+
$this->assertSame(
19+
$outs[0],
20+
(string)$this->dom->find('.hello:contains(\'' . $outs[1] . '\')')
21+
);
22+
23+
$this->assertSame(
24+
$outs[0],
25+
$this->dom->find('h1')->html()
26+
);
27+
28+
$this->assertSame(
29+
$outs[1],
30+
$this->dom->find('h1')->text()
31+
);
32+
}
33+
34+
public function testId()
35+
{
36+
$this->dom->loadFile(
37+
$this->partial('base.simple')
38+
);
39+
40+
$this->assertSame(
41+
$this->dom->find('#id')->tag,
42+
'body'
43+
);
44+
45+
$this->assertSame(
46+
$this->dom->find('#id')->id,
47+
'id'
48+
);
49+
50+
$this->assertSame(
51+
(string)$this->dom->find('.hello'),
52+
(string)$this->dom->find('.world')
53+
);
54+
}
55+
56+
}

tests/Unit.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Bavix\AdvancedHtmlDom\AdvancedHtmlDom;
6+
7+
class Unit extends \Bavix\Tests\Unit
8+
{
9+
10+
/**
11+
* @var AdvancedHtmlDom
12+
*/
13+
protected $dom;
14+
15+
public function setUp()
16+
{
17+
parent::setUp();
18+
19+
$this->dom = new AdvancedHtmlDom();
20+
}
21+
22+
/**
23+
* @param string $path
24+
*
25+
* @return string
26+
*/
27+
public function partial(string $path): string
28+
{
29+
return __DIR__ . '/data/' . \str_replace('.', '/', $path) . '.html';
30+
}
31+
32+
}

tests/data/base/simple.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Simple</title>
6+
</head>
7+
<body id="id">
8+
<h1 class="hello world">Hello World</h1>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)