php-cs-fixer/phpunit-constraint-xmlmatchesxsd
A small PHPUnit constraint used by PHP-CS-Fixer to assert that XML documents match a given XSD schema. Intended for internal PHP-CS-Fixer usage rather than general-purpose projects.
This package provides a custom PHPUnit constraint XmlMatchesXsd for validating XML against an XSD schema. It is exclusively designed for internal use by PHP-CS-Fixer’s test suite, as explicitly stated in the README: "This constraint is for PHP CS Fixer usage only."
To use it, install via Composer:
composer require --dev php-cs-fixer/phpunit-constraint-xmlmatchesxsd
Then, in a PHPUnit test, assert XML validity like this:
use PHPUnit\Framework\TestCase;
use PHP-CS-Fixer\PHPUnit\Constraint\XmlMatchesXsd;
class MyXmlTest extends TestCase
{
public function testXmlMatchesSchema(): void
{
$xml = '<root><item id="1"/></root>';
$xsd = __DIR__ . '/schema.xsd';
$this->assertThat($xml, new XmlMatchesXsd($xsd));
}
}
Start by reading the tests directory — they contain the canonical usage examples.
$this->loadXmlFixture('expected.xml')) and validate against a pre-approved XSD in the same way as above.$this->assertThat(...)->getMessage() or check PHPUnit output for diagnostics.'schema.xsd' works only if the test’s working directory is the repo root. Prefer absolute paths (__DIR__ . '/../../fixtures/schema.xsd') for reliability.XmlMatchesXsd::evaluate() temporarily or use var_dump($this->getActual()) in assertThat() to inspect the raw XML and libxml error log (via libxml_get_errors()).libxsd + custom constraint, or webmozart/path-util + domdocument manually.How can I help you explore Laravel packages today?