Skip to content

Commit

Permalink
Merge 4072430 into 87df37a
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Su committed Jul 21, 2019
2 parents 87df37a + 4072430 commit 38a7a8a
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.idea
/.DS_Store
/composer.lock
/build
/vendor
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ install:

script:
- vendor/bin/phpcs -n --standard=PSR12 --ignore=./vendor/ --extensions=php ./
- mkdir -p build/logs
- vendor/bin/phpunit

after_success:
- travis_retry php vendor/bin/php-coveralls -v
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# html-query

[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
[![Build Status](https://api.travis-ci.org/xinningsu/html-query.svg?branch=master)](https://travis-ci.org/xinningsu/html-query)

A jQuery-like html processor written in PHP

# Quick Start
Expand Down Expand Up @@ -35,6 +39,32 @@ echo $hq('.content')->text();
//this is content...
```

### Set contents
```php
<?php
$html = '
<html>
<head>
<title>Html Query</title>
</head>
<body>
<h1 class="title">this is title</h1>
<div class="content">this is <b>content</b>...</div>
</body>
</html>
';
$hq = HQ::html($html);

echo $hq('.title')->html('this is new title')->html();
//this is new title

echo $hq('.content')->html('this is <b>new content</b>...');
//this is <b>new content</b>...

echo $hq('.content')->text('this is new content...')->html();
//this is new content...
```

### Get attributes
```php
<?php
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
},
"require-dev": {
"phpunit/phpunit": "~7.5",
"squizlabs/php_codesniffer": "3.*"
"squizlabs/php_codesniffer": "3.*",
"php-coveralls/php-coveralls": "^2.1"
},
"autoload": {
"psr-4": {
Expand All @@ -29,4 +30,4 @@
"tests/"
]
}
}
}
8 changes: 8 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
38 changes: 34 additions & 4 deletions tests/ExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class ExampleTest extends TestCase
{
public function testExample1()
public function testGetContents()
{
$html = '
<html>
Expand Down Expand Up @@ -38,7 +38,37 @@ public function testExample1()
);
}

public function testExample2()
public function testSetContents()
{
$html = '
<html>
<head>
<title>Html Query</title>
</head>
<body>
<h1 class="title">this is title</h1>
<div class="content">this is <b>content</b>...</div>
</body>
</html>
';
$hq = HQ::html($html);

$this->assertEquals(
'this is new title',
$hq('.title')->html('this is new title')->html()
);
$this->assertEquals(
'this is <b>new content</b>...',
$hq('.content')->html('this is <b>new content</b>...')->html()
);

$this->assertEquals(
'this is new content...',
$hq('.content')->text('this is new content...')->html()
);
}

public function testGetAttributes()
{
$html = '
<div class="container">
Expand Down Expand Up @@ -75,7 +105,7 @@ public function testExample2()
);
}

public function testExample3()
public function testChangeAttributes()
{
$html = '
<div class="container">
Expand Down Expand Up @@ -136,7 +166,7 @@ public function testExample3()
);
}

public function testExample4()
public function testChangeStructure()
{
$html = '
<div class="container">
Expand Down

0 comments on commit 38a7a8a

Please sign in to comment.