<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
thomasweinert / phpunit-xpath-assertions example snippets
use PHPUnit\Framework\TestCase;
use PHPUnit\Xpath\Assert as XpathAssertions;
class MyProjectExampleTest extends TestCase
{
use XpathAssertions;
public function testChildElementExistsInDocument()
{
$document = new \DOMDocument();
$document->loadXML('<root><child>TEXT</child></root>');
self::assertXpathMatch('//child', $document);
}
public function testCompareChildElementFromDocument()
{
$document = new \DOMDocument();
$document->loadXML('<root><child>TEXT</child></root>');
self::assertXpathEquals('<child>TEXT</child>', '//child', $document);
}
}
use PHPUnit\Xpath\Assert as XpathAssertions;
use PHPUnit\Xpath\Constraint as XpathConstraints;
class MyProjectExampleTest extends \PHPUnit\Framework\TestCase
{
use XpathAssertions;
use XpathConstraints;
}
function matchesXpathExpression(string $expression, array|\ArrayAccess $namespaces = [])
public function testChildElementExistsInDocument()
{
$document = new \DOMDocument();
$document->loadXML('<root><child>TEXT</child></root>');
self::assertThat(
$document,
self::matchesXpathExpression('//child')
);
}
function matchesXpathResultCount(
int $expectedCount, string $expression, array|\ArrayAccess $namespaces = array()
)
public function testChildElementExistsOnTimeInDocument()
{
$document = new \DOMDocument();
$document->loadXML('<root><child>TEXT</child></root>');
self::assertThat(
$document,
self::matchesXpathResultCount(1, '//child')
);
}