bootpress / htmlunit
使您能够彻底测试代码的HTML输出。
v1.0
2016-09-01 21:56 UTC
Requires
- php: >=5.4
- phpunit/phpunit: ^4.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-23 06:47:09 UTC
README
扩展PHPUnit,并将assertEquals
和assertRegExp
断言合并为单个assertEqualsRegExp
方法,使您能够彻底测试代码的HTML输出。
安装
将以下内容添加到您的composer.json
文件中。
{ "require-dev": { "bootpress/htmlunit": "^1.0" } }
示例用法
<?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); } }
请注意,数组值周围的全部空白都被忽略。正则表达式使用Twig样式{{ ... }}
包围,两端各有一个花括号和一个空格。内部正则表达式被这样包围:/^...$/
。
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。