I am developing a PHP-powered application component which exports some data to an XML file which must follow a scheme defined by XSD file. I know how to validate the file manually, but it would be very handy if this could be done within unit tests.
Is there any library or framework available which can me help doing that?
One possibility would be to use
DOMDocument::schemaValidateSource. Since either of those two methods returns a boolean value, you could then assert that the returned value is
This PHPUnit XSD validation lib defines a custom
The advantage is that it gives a useful error when the validation fails, rather than just saying that 'false is not true'.
$constraint = new Jasny\PHPUnit\Constraint\XSDValidation("myschema.xsd"); $xml = $this->object->doSomething(); $this->assertThat($xml, $constraint);
Note: This is a shameless plug of my own open source library.