feat(tests): migrate Peridot test suite to PHPUnit 11#73
Open
guillaumedelre wants to merge 7 commits into
Open
feat(tests): migrate Peridot test suite to PHPUnit 11#73guillaumedelre wants to merge 7 commits into
guillaumedelre wants to merge 7 commits into
Conversation
DOMElement::__construct does not escape & or < in its value argument, causing DOMException when user data contains XML special characters. Replace the value parameter with a createTextNode call after attachment, which handles escaping at the DOM level. Fixes downforcetech#14 Signed-off-by: Guillaume Delré <delre.guillaume@gmail.com>
xml() and save() now accept an $options integer bitmask forwarded to DOMDocument::saveXML(), enabling LIBXML_NOEMPTYTAG and other libxml flags. The same parameter propagates through FluidContext::xml(), FluidSaveTrait, and the FluidHelper serialization helpers. Closes downforcetech#15 Signed-off-by: Guillaume Delré <delre.guillaume@gmail.com>
The @ special key already sets text content in the concise array syntax. This extends it with typed variants: - @:text — explicit alias for @ - @:cdata — wraps content in a CDATA section - @:comment — inserts an XML comment Closes downforcetech#23 Signed-off-by: Guillaume Delré <delre.guillaume@gmail.com>
FluidXml::toArray() returns ['rootTag' => value] for the document. FluidContext::toArray() returns an array of ['tag' => value] entries for each selected node. Conversion rules: - Text-only element -> plain string value - Empty element -> null - Attributes -> '@name' keys - Text with siblings -> '@' key - CDATA content -> '@:cdata' key - Comment -> '@:comment' key - Repeated child tags -> indexed sub-arrays - Namespace decls -> '@xmlns' / '@xmlns:prefix' keys (only those introduced on the element, not inherited) The output mirrors the array syntax accepted by addChild(), enabling round-trip import/export. FluidXml::toObject() and FluidContext::toObject() return the same structure as stdClass instead of arrays, which integrates more naturally with JSON workflows and property-access code. Associative arrays become stdClass objects; indexed arrays (repeated siblings) remain PHP arrays. Namespace declarations are detected via the XPath namespace::* axis, comparing in-scope namespaces with the parent element to emit only the declarations local to each node. Closes downforcetech#28 Signed-off-by: Guillaume Delré <delre.guillaume@gmail.com>
DOMDocument::importNode() returns false for DOMDocumentType nodes, causing appendChild() to receive a boolean and throw a fatal error. This happens when loading or inserting XML that contains a <!DOCTYPE> declaration: the node list from childNodes includes the DOMDocumentType node alongside the root element. Skip DOMDocumentType entries in attachNodes() before attempting the import, so the document content is imported correctly and the DOCTYPE declaration is silently discarded. Fixes downforcetech#44 Fixes downforcetech#50 Signed-off-by: Guillaume Delré <delre.guillaume@gmail.com>
Large XML files (or files served over HTTP) can exceed libxml's default parser limits, causing load() to silently return empty data. Pass an optional $flags int to load() and forward it to DOMDocument::load(), which lets callers opt into LIBXML_PARSEHUGE, LIBXML_COMPACT, or any other libxml flag as needed. The implementation also switches from file_get_contents() + loadXML() to DOMDocument::load() directly, which avoids loading the whole file into a PHP string before parsing. Closes downforcetech#52 Signed-off-by: Guillaume Delré <delre.guillaume@gmail.com>
Replaces the Peridot BDD spec runner with PHPUnit 11. All 208 tests ported to 5 test files under tests/ covering FluidXml, FluidContext, FluidNamespace, FluidHelper and CssTranslator. Renames source/ to src/ to align with PHP/OSS convention. Removes specs/, support/ and their Peridot dependency. Updates all CI configs (CircleCI, Scrutinizer, Travis, Coveralls) to use composer install and phpunit directly, removes hardcoded GitHub access tokens. Upgrades rector to ^2.0 (required for compatibility with phpstan ^2.0 pulled by phpunit 11) and updates rector.php to the 2.x API. Updates README to reference tests/ instead of specs/. Adds vendor/, build/ and .phpunit.result.cache to .gitignore. Signed-off-by: Guillaume Delré <delre.guillaume@gmail.com>
Author
Author
|
Hey @daniele-orlando, gentle ping on this migration PR. Open to reworking if the approach doesn't fit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrate Peridot test suite to PHPUnit 11
Context
This PR consolidates all changes from issues #14, #15, #23, #28, #44 and #52 into a single
integration branch and replaces the legacy Peridot BDD spec runner with PHPUnit 11. The
specs/FluidXml.phpfile (3 276 lines of Peridot DSL) is fully ported to idiomatic PHPUnittest classes.
Test suite
208 tests across 5 files, run with PHP 8.2 on FrankenPHP:
tests/FluidXmlTest.phptests/FluidContextTest.phptests/FluidNamespaceTest.phptests/FluidHelperTest.phptests/CssTranslatorTest.phpA shared
FluidTestCasebase class providesassertEqualXml()andassertIsFluid()helpersused throughout.
Coverage of previously merged PRs
Each commit cherry-picked into this branch has dedicated regression tests:
#14 - XML special character escaping
fix: escape XML special characters in addChild text contenttestAddChildEscapesXmlSpecialCharsArgumentSyntaxtestAddChildEscapesXmlSpecialCharsArraySyntax#15 - libxml options for
xml()andsave()feat: add libxml options support to xml() and save()testXmlRendersEmptyElementsAsExplicitClosingTagsWithLibxmlNoemptytagtestXmlPassesLibxmlNoemptytagThroughWhenQueryingContexttestSaveStoresEntireXmlDocumentInFiletestSaveStoresFragmentOfXmlDocumentInFiletestSaveThrowsForNotWritableFile#23 -
@:text,@:cdata,@:commentin array syntaxfeat: add @:text, @:cdata, @:comment to array syntaxtestAddChildAddsTextContentUsingAtTextAliastestAddChildAddsCdataContentUsingAtCdataSyntaxtestAddChildAddsCommentContentUsingAtCommentSyntax#28 -
toArray()/toObject()with namespace supportfeat: add toArray() and toObject() with namespace supporttestToArrayExportsSimpleElementWithTextContenttestToArrayExportsAttributesUsingAtPrefixtestToArrayExportsNestedElementsAsNestedArraystestToArrayExportsRepeatedSiblingElementsAsIndexedArraystestToArrayExportsEmptyElementAsNulltestToArrayExportsQueriedNodesViaFluidContexttestToArrayExportsNamespaceDeclarationsUsingAtXmlnsPrefixtestToObjectReturnsstdClassMirroringToArraytestToObjectPreservesIndexedArraysForRepeatedSiblingstestToObjectReturnsArrayOfstdClassForFluidContext#44 - DOMDocumentType crash on XML with DOCTYPE
fix: skip DOMDocumentType when importing XML with DOCTYPE declarationtestLoadImportsXmlFileContainingDoctypetestAddChildDoesNotThrowWithDoctypeXmlString#52 - libxml flags for
load()feat: add libxml flags parameter to FluidXml::load()testLoadAcceptsLibxmlFlagsAdditional changes
source/renamed tosrc/Aligns with the PHP/OSS convention (
src/is the standard across Composer, Symfony and PSRprojects). All autoload paths in
composer.json,phpunit.xml,rector.phpand.scrutinizer.ymlupdated accordingly.Rector upgraded to
^2.0Rector 0.18 is incompatible with phpstan
^2.0, which is pulled in transitively byphpunit 11. Rector 2.x resolves the conflict. The
rector.phpconfig is updated to the 2.xAPI (
SetList::PHP_82replacingLevelSetList::UP_TO_PHP_82). Runningrector --dry-runon
src/andtests/produces no suggestions: the codebase is already fully PHP 8.2-compliant.CI/CD configs updated
All four CI configs now use
composer install --prefer-distandphp vendor/bin/phpunitdirectly, replacing the deleted
support/shell scripts. Hardcoded GitHub access tokensremoved from
circle.ymland.travis.yml.circle.ymlvendor/cache, token removed.scrutinizer.ymlbuild/logs/clover.xml,src/filter.travis.yml.coveralls.ymlsrc_dir, coverage file paths.gitignoreupdatedAdded
vendor/,build/and.phpunit.result.cache.README.mdupdatedThe link to the deleted
specs/FluidXml.phpnow points totests/FluidXmlTest.php.Removed
specs/(3 276 lines of Peridot DSL)support/(14 shell scripts:init,test,coverage,coveralls,speedtest,gendoc, ...)evenement/evenement,symfony/console3.x,symfony/debug,peridot-php/peridot-scope, ...)