phpunit / phpunit-dom-assertions
DOM assertions for PHPUnit
Installs: 191 223
Dependents: 9
Suggesters: 0
Security: 0
Stars: 27
Watchers: 6
Forks: 13
Open Issues: 2
Requires
- php: >=7.1
- ext-dom: *
- phpunit/phpunit: ^6.5.14 || ^7.5.20 || ^8.5.21 || ^9.5.10
- symfony/css-selector: ^4.4.27 || ^5.4.0 || ^6.0.0
- symfony/dom-crawler: ^4.4.30 || ^5.4.0 || ^6.0.0
Requires (Dev)
- phpstan/phpstan: ^1.2.0
- phpstan/phpstan-deprecation-rules: ^1.0.0
- phpstan/phpstan-phpunit: ^1.0.0
- symfony/phpunit-bridge: ^5.4.0 || ^6.0.0
README
A work in progress, drop-in replacement for the following deprecated PHPUnit assertions:
assertSelectCount()
assertSelectRegExp()
assertSelectEquals()
assertTag()
(not yet ported)assertNotTag()
(not yet ported)
TODO
- Port
assertTag()
andassertNotTag()
. - Improve tests.
- Improve error messages.
- Improve comments and documentation.
- Add XPath support.
Requirements
The PHPUnit DOM assertions require PHP 7.0 or later.
Installation
The recommended way to install the PHPUnit DOM assertions is
through composer. Just create a composer.json
file
and run the php composer.phar install
command to install it:
{ "require-dev": { "phpunit/phpunit-dom-assertions": "~2" } }
Usage
Extend PHPUnit\Framework\DOMTestCase
to use the DOM assertions:
namespace My\Tests; use PHPUnit\Framework\DOMTestCase; class DOMTest extends DOMTestCase { public function testSelectEquals() { $html = file_get_contents('test.html'); $selector = 'span.test_class'; $content = 'Test Class Text'; $this->assertSelectEquals($selector, $content, true, $html); } }
Tests
To run the test suite, you need composer.
$ php composer.phar install
$ vendor/bin/phpunit
License
The PHPUnit DOM assertions library is licensed under the BSD 3-Clause license.