Skip to content

Fix failing PHP code tests #389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 27, 2025

Conversation

JohnathonKoster
Copy link
Contributor

@JohnathonKoster JohnathonKoster commented May 26, 2025

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 when app.debug is true, 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 🙂

@JohnathonKoster JohnathonKoster marked this pull request as draft May 26, 2025 22:03
@JohnathonKoster JohnathonKoster marked this pull request as ready for review May 26, 2025 22:18
@JohnathonKoster JohnathonKoster changed the title Fix Tests: Test obfuscated PHP by watching logs instead Fix failing PHP code tests May 26, 2025
@jesseleite jesseleite merged commit fd9e6ca into statamic:master May 27, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants