Repository navigation
Add wp bs blocks render to smoke-test blocks for PHP problems - #188
Merged
Merged
Conversation
Contributor
|
Released in Blockstudio 7.7.9. Thanks for the contribution. |
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.
A theme that wants to check its block templates against the installed Blockstudio has to write its own script today: build the block markup, run
do_blocks()and collect notices withset_error_handler(). Blockstudio haswp bs blocks validatefor stored content, but nothing that renders. We wrote such a script for our theme's CI, and it found templates that warned on repeater rows without a saved key, which a stubbed render could not see.This adds
wp bs blocks render [<name>...] [--attributes=<json>|@<file>] [--format=<table|json>]:do_blocks()from a block comment carryingblockstudio.attributes, the shape the editor stores and the path a page takes, without a queried post. Nothing is written to the database.example.attributesof the block.json (what the inserter preview uses); a block without an example renders with its field defaults and the output says so. Image placeholders that only exist for the inserter preview are skipped.--attributesreplaces the example for one block, as a JSON object of field values or@file, so CI can reach branches the example does not.@-silenced calls are ignored, and the error handler anderror_reportingare restored afterwards.--attributesand unknown formats are errors, in the style ofvalidate.Real output from a test theme in WordPress Playground:
The logic lives in a small
Render_Checkclass so it can be tested without WP-CLI (@since 7.7.9, adjust to the release). The command is documented indocs/docs/dev/cli.mdnext tovalidate, and the LLM bundle is rebuilt. WordPress raises its own deprecation notices only withWP_DEBUGon, so the docs suggest enabling it in CI.Tests:
tests/unit/cli/RenderCheckTest.php(example, defaults,--attributes, image placeholders, undefined key with file, line and de-duplication,@, deprecation, thrown error leaves no open buffer, handler restored): 9 tests pass in WordPress Playground (PHP 8.4, PHPUnit 11.5). The command was also run through real WP-CLI there for all blocks, named blocks,--attributesinline and from a file, both formats and the error paths. Lint, format, typecheck, docs, schemas, i18n, PHPCS and PHPStan pass locally; the full suite is left to CI.