Add TOON validation API and test coverage#2
Open
nikkyandrei wants to merge 5 commits intoHelgeSverre:mainfrom
Open
Add TOON validation API and test coverage#2nikkyandrei wants to merge 5 commits intoHelgeSverre:mainfrom
nikkyandrei wants to merge 5 commits intoHelgeSverre:mainfrom
Conversation
Expand test coverage for the new validation path. What changed: - add focused ValidationTest coverage for the validation API - add ValidationParityTest to verify validate() stays aligned with decode() across valid, invalid, strict, and lenient inputs - extend HelpersTest to cover toon_validate(), toon_validate_lenient(), and the documented lenient-only helper scenarios Why: - validate() is implemented as a separate execution path, so parity tests are needed to guard against drift from decode() - focused API tests keep the intended validation behavior easy to understand - helper tests ensure the public helper surface matches the documented lenient behavior and that strict validation fails where lenient validation succeeds
Added README examples for strict and lenient validation using both `Toon::validate` and helper functions `toon_validate`/`toon_validate_lenient`.
Author
|
Forgot to update Readme |
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.
This PR adds a validation path for TOON documents, along with helper functions and test coverage for the new API.
The work is split across these commits:
Add validation utilities for TOON syntax checking without decoding into PHP values:
81b07aeAdd
toon_validateandtoon_validate_lenienthelper functions for TOON validation:5cc5108Add validation API coverage and decode parity checks:
41c0c63What is included:
src/Decoder/Validator.phpToon::validate()insrc/Toon.phptoon_validate()andtoon_validate_lenient()insrc/helpers.phptests/ValidationTest.phptests/ValidationParityTest.phptests/HelpersTest.phpThe main goal here is to make
validate()a real API, not just a thin wrapper arounddecode(), while still keeping confidence that both paths stay aligned.The tests are split on purpose:
ValidationTestcovers the validation API directlyValidationParityTestchecks thatvalidate()anddecode()agree on a broader set of inputsHelpersTestmakes sure the helper layer behaves the same way, including lenient handlingImportant note
If new
decode()edge cases are added later, the validation coverage should be updated alongside them so the two paths do not drift.Right now the parity coverage gives a good safety net, but it still depends on keeping validation tests updated when decoder behavior grows.
Optional follow-up
If this gets merged and maintainers want even stricter enforcement later, a follow-up could move more
decode()andvalidate()cases into shared fixtures or shared data providers.Moving more of those cases into shared fixtures or shared data providers would make that easier to maintain over time.
Verification:
vendor/bin/phpunit --no-coveragevendor/bin/phpstan analyseCurrent result:
625 tests,1156 assertions