baxtian/dom-assert

Assert library for PHPUnit for testing DOM trees.

0.3.2 2025-04-03 00:44 UTC

This package is auto-updated.

Last update: 2025-04-03 00:45:04 UTC


README

This is an Assert library for PHPUnit for testing DOM trees.

Usage:

<?php
namespace Tests;

use PHPUnit\Framework\TestCase;
use Baxtian\DOMAssert;

class DomTest extends TestCase
{
	public function testShortcode(): void
	{
		$html = "<div><p class='answer black'>All good!</p><p id='greetings' data-greetings='Hi!'>Second paragraph</p></div>";
		
		DOMAssert::assertNodeText($html, 'p.answer', 'All good!');
		DOMAssert::assertNodeHasClass($html, 'p.answer', 'black');
		DOMAssert::assertNodeCount($html, 'p', 2);
		DOMAssert::assertNodeHasAttribute($html, 'p#greetings', 'data-greetings', 'Hi!');
	}
}

Mantainers

Juan Sebastián Echeverry baxtian.echeverry@gmail.com

Changelog

0.3.2

  • First stable release