Fix failing PHP code tests #389
Merged
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.
This PR corrects some failing tests by forcing the runtime to throw exceptions when PHP nodes are encountered within user-supplied content.
The fix in statamic/cms#11800 corrected an undefined property error. When an exception was thrown previously, it was being swallowed by this catch block: https://github.com/statamic/cms/blob/5.x/src/View/Antlers/Language/Runtime/ModifierManager.php#L132, allowing the original text to the modifier to be returned when the application was not in debug mode. For the currently failing test, it would have been the dynamically constructed PHP block.
The ideal way to test this would be to assert a log being created, but that would cause failing tests when using
--prefer-lowest
. This refactored test is relying on the fact SEO Pro returns the original text if an exception is thrown, which will be consistent across all Statamic versions whenapp.debug
istrue
, and throwing exceptions when PHP nodes are encountered is enabled. Note: these settings are not important to actually prevent execution of PHP code (that is handled by the runtime), but just a way to observe it from SEO Pro across multiple Statamic versions 🙂