spiderling-php/phpunit-matches-selector

PHPUnit 扩展,用于断言 DOM 元素是否匹配给定的 CSS 选择器

0.2.0 2015-09-18 07:22 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:52:49 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version

PHPUnit 扩展,用于断言 DOM 元素是否匹配给定的 CSS 选择器

安装

通过 composer 安装

composer require --dev spiderling-php/phpunit-matches-selector

由于它旨在作为测试的扩展,所有要求都在 require-dev 中。PHPUnit 的要求没有明确声明,因为它假设您仍然需要它来进行测试。

用法

此扩展允许检查 DOMElement 是否匹配特定的 CSS 选择器

use SP\PhpunitDomConstraints\DomConstraintsTrait;
use PHPUnit_Framework_TestCase;

class TestCaseTest extends PHPUnit_Framework_TestCase
{
    use DomConstraintsTrait;

    public function testTest()
    {
        $document = new DOMDocument();
        $document->load('Some file');

        $element = $document->getElementById('some id');

        // Here is the test you can now perform
        $this->assertMatchesSelector('div.some-class', $element, 'This should match');

        // You can do even more complex selects
        $this->assertMatchesSelector('ul li > #test.some-class[disabled]', $element, 'This should match');
    }
}

许可证

版权(c)2015,Clippings Ltd。由 Ivan Kerin 开发

在 BSD-3-Clause 许可下,阅读 LICENSE 文件。