PHP code example of jroszkiewicz / phpunit-xpath-assertions
1. Go to this page and download the library: Download jroszkiewicz/phpunit-xpath-assertions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jroszkiewicz / 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')
);
}