Fix failing test tests/fixtures-twig/tests/defined_for_macros.twig#3
Open
NoNoNo wants to merge 1 commit into
Open
Fix failing test tests/fixtures-twig/tests/defined_for_macros.twig#3NoNoNo wants to merge 1 commit into
tests/fixtures-twig/tests/defined_for_macros.twig#3NoNoNo wants to merge 1 commit into
Conversation
tests/fixtures-twig/tests/defined_for_macros.twig
Failed: '...sts($macros[__internal_b0042e2994606d17953b10bae1bd357c2317845d7972...' should match
... '...sts($macros[__internal_c2d9f9a9e8b868d6b479e868d58395d8cbc54944fb9a...'
diff tests/output/TwigTest.expected tests/output/TwigTest.actual
in latte-tools/tests/TwigTest.php(19) Assert::match($expected, $res);
The TwigTest was failing because the `__internal_*` hash values generated in
`Parser.php` are non-deterministic. The hash is generated using a combination of
method name, source code, and a salt counter that varies between runs/environments.
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.
Normalize
__internal_*hashes in TwigTest comparisonsSummary
The TwigTest was failing because the
__internal_*hash values generated inParser.phpare non-deterministic. The hash is generated using a combination of method name, source code, and a salt counter that varies between runs/environments.Running
composer tester:Root Cause
In
src/Twiggy/Parser.php:55:This produces different 64-character SHA256 hashes on each run, causing test failures when comparing against expected output files.
Fix
Modified
tests/TwigTest.phpto normalize__internal_*hashes by replacing them with a consistent__internal_*placeholder before comparison using regex.This approach is commonly used for non-deterministic values (similar to handling timestamps or random values) and makes tests resilient to environment changes while still validating the conversion logic.