Skip to content

Add TOON validation API and test coverage#2

Open
nikkyandrei wants to merge 5 commits intoHelgeSverre:mainfrom
nikkyandrei:main
Open

Add TOON validation API and test coverage#2
nikkyandrei wants to merge 5 commits intoHelgeSverre:mainfrom
nikkyandrei:main

Conversation

@nikkyandrei
Copy link
Copy Markdown

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:

  1. Add validation utilities for TOON syntax checking without decoding into PHP values: 81b07ae

  2. Add toon_validate and toon_validate_lenient helper functions for TOON validation: 5cc5108

  3. Add validation API coverage and decode parity checks: 41c0c63

What is included:

  • a dedicated validator in src/Decoder/Validator.php
  • Toon::validate() in src/Toon.php
  • toon_validate() and toon_validate_lenient() in src/helpers.php
  • focused tests in tests/ValidationTest.php
  • broader parity coverage in tests/ValidationParityTest.php
  • helper coverage updates in tests/HelpersTest.php

The main goal here is to make validate() a real API, not just a thin wrapper around decode(), while still keeping confidence that both paths stay aligned.

The tests are split on purpose:

  • ValidationTest covers the validation API directly
  • ValidationParityTest checks that validate() and decode() agree on a broader set of inputs
  • HelpersTest makes sure the helper layer behaves the same way, including lenient handling

Important 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() and validate() 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-coverage
  • vendor/bin/phpstan analyse

Current result:

  • PHPUnit: 625 tests, 1156 assertions
  • PHPStan: clean

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`.
@nikkyandrei
Copy link
Copy Markdown
Author

Forgot to update Readme

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.

1 participant