phpunit/phpunit-dom-assertions

v2.0.1 2017-02-19 12:24 UTC

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() and assertNotTag().
  • 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

Build Status

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.