bootpress / htmlunit
Enables you to thoroughly test the HTML output of your code.
Installs: 1 469
Dependents: 8
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.4
- phpunit/phpunit: ^4.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-11-18 07:50:44 UTC
README
Extends PHPUnit and combines the assertEquals
and assertRegExp
assertions into one assertEqualsRegExp
method that enables you to thoroughly test the HTML output of your code.
Installation
Add the following to your composer.json
file.
{ "require-dev": { "bootpress/htmlunit": "^1.0" } }
Example Usage
<?php class MyTest extends \BootPress\HTMLUnit\Component { public function testOutput() { $html = <<<'EOT' <!doctype html> <html lang="en-us"> <head><meta charset="UTF-8"> <title>Title</title></head> <body> <p>Content</p> </body> </html> EOT; $this->assertEqualsRegExp(array( '<!doctype {{ [^>]+ }}>', '<html lang="{{ [a-z-]+ }}">', '<head>', '<meta charset="{{ [A-Z0-9-]+ }}">', '<title>Title</title>', '</head>', '<body>', '<p>Content</p>', '</body>', '</html>', ), $html); } }
Notice that all of the whitespace surrounding the array values are ignored. Regular expressions are enclosed Twig style {{ ... }}
with two curly braces and a space on both ends. Internally the regex is wrapped like so: /^...$/
.
License
The MIT License (MIT). Please see License File for more information.