[#670] Added XML schema and feed validation to 'XmlTrait'.#680
Conversation
Added steps to validate the XML response against XSD, DTD and RelaxNG schemas (inline or from a file) and to assert that a response is a structurally valid RSS 2.0 or Atom feed. Schema and feed validation use native libxml, with no new runtime dependency. Claude-Session: https://claude.ai/code/session_01VetNPTaUe3wyaCR3k9rw7p
DTD validation treats namespace declarations as ordinary attributes, so a namespaced response must declare its 'xmlns' attributes in the DTD. This matches native DTD validation semantics. Claude-Session: https://claude.ai/code/session_01VetNPTaUe3wyaCR3k9rw7p
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
WalkthroughAdds XSD, DTD, and RelaxNG schema validation steps plus RSS 2.0 and Atom feed validation steps to ChangesXML schema and feed validation
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Scenario
participant XmlTrait
participant libxml
Scenario->>XmlTrait: xmlAssertMatchesXsd / Dtd / RelaxNg
XmlTrait->>XmlTrait: xmlReadFile(filename) (if file-based)
XmlTrait->>libxml: validate document against schema
libxml-->>XmlTrait: errors or success
XmlTrait-->>Scenario: pass or throw ExpectationException
Scenario->>XmlTrait: xmlAssertValidRssFeed / xmlAssertValidAtomFeed
XmlTrait->>XmlTrait: xmlDirectChildElements(node, name)
XmlTrait-->>Scenario: pass or throw ExpectationException
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 PHPStan (2.2.2)Composer install failed: the lock file is not up to date with the latest changes in composer.json. Run Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #680 +/- ##
==========================================
+ Coverage 96.95% 97.01% +0.05%
==========================================
Files 47 47
Lines 3946 4020 +74
==========================================
+ Hits 3826 3900 +74
Misses 120 120 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closes #670
Summary
Extends
XmlTraitwith whole-document schema validation (XSD, DTD, and RelaxNG, each usable inline via a PyString or loaded from a fixture file) and structural validity assertions for RSS 2.0 and Atom feeds, so a response body can be checked against a formal schema or a feed's required elements instead of only individual elements, attributes, or namespaces. All validation runs through native libxml/DOM APIs (DOMDocument::schemaValidateSource(),relaxNGValidateSource(), andLIBXML_DTDVALID), so no new Composer dependency is introduced.Changes
src/XmlTrait.php:xmlAssertMatchesXsd/xmlAssertMatchesXsdFromFilefor XSD,xmlAssertMatchesDtd/xmlAssertMatchesDtdFromFilefor DTD, andxmlAssertMatchesRelaxNg/xmlAssertMatchesRelaxNgFromFilefor RelaxNG, plusxmlAssertValidRssFeedandxmlAssertValidAtomFeedfor feed structure.xmlValidateXsdandxmlValidateRelaxNgdelegate toDOMDocument::schemaValidateSource()/relaxNGValidateSource();xmlValidateDtdembeds the DTD as an internal subset and reloads the document withLIBXML_DTDVALIDso a file-based and an inline DTD share one code path;xmlValidateRssFeedandxmlValidateAtomFeedwalk the DOM to check the required elements for each feed format;xmlDirectChildElementsis a namespace-aware direct-child lookup shared by both feed validators.xmlReadFile()from the existingxmlSetResponseContentFromFilestep so the new "from file" schema assertions reuse the same fixture-reading logic.xmlValidateDtdand the DTD step definitions, that DTDs are namespace-unaware: a namespaced response must declare itsxmlnsattributes and prefixed element names directly in the DTD.tests/behat/fixtures/xml_schema.xsd,xml_schema.dtd, andxml_schema.rngdescribing the same "library of books" shape, plusrss_valid.xmlandatom_valid.xmlas valid feed samples.tests/behat/features/xml.featurecovering positive matches and negative/error paths (invalid documents, missing schema files, malformed feed structure) for every new assertion.STEPS.mdto document the eight new step definitions.Before / After
Added full-document XML validation to
XmlTrait, including native XSD, DTD, and Relax NG checks from either inline schema text or fixture files.Also added structural assertions for valid RSS 2.0 and Atom feeds, with clearer validation failures surfaced from the first libxml/DOM error.
Documentation and coverage were updated accordingly:
STEPS.mdXmlTraitNo CONTRIBUTING.md step-definition rule violations were identified.