Skip to content

Conversation

@NanoSector
Copy link
Contributor

@NanoSector NanoSector commented Jun 6, 2025

This helps with debugging MappingErrors thrown during test execution. Sometimes these can be annoying to debug because Valinor only shows "A total of 2 errors were thrown".

The extension works by overriding the TestCase transformException method through a trait, which means this is an opt-in feature for tests. It collects them in a singleton class and then uses the PHPUnit extension to display them in a formatted table at the end of the test run.

image

Implementing it is a matter of using the CollectValinorMappingErrors trait in your TestCase class and registering the
PrettyPrintMappingErrorsExtension extension class in the phpunit configuration file. A PR to update the documentation will be made separately.

This does require symfony/console for its table printing capabilities, copying that logic into the library seemed excessive. In order to not have a hard dependency on it, it is put in the suggest array in composer.json and we are using a class_exists check to see if it is installed.

Developed by: Social Deal (@socialdeal)

@NanoSector
Copy link
Contributor Author

NanoSector commented Jun 6, 2025

PHPStan is (rightfully) complaining that the CollectValinorMappingErrors trait is unused. I could throw it in some random test or suppress it as the 'static analysis' tests cover its usage; what is wanted here?

edit: I was also under the assumption the separate Valinor-Documentation repository was leading for the docs, but it seems to be generated from this repository. I'll add a follow-up commit to add the documentation here.

@NanoSector NanoSector force-pushed the feature/phpunit-extension branch from 698dc6c to a8e570e Compare June 28, 2025 19:26
@romm
Copy link
Member

romm commented Jun 28, 2025

Hi @NanoSector just wanted to say that I did not forget you. Most efforts lately have been done towards the 2.0 release. I do not have much personal time to work on Valinor lately but I'll take a look at this PR ASAP. 😊

Thanks!

This helps with debugging MappingErrors thrown during test execution.
Sometimes these can be annoying to debug because Valinor only shows "A
total of 2 errors were thrown".

The extension works by overriding the TestCase `transformException`
method through a trait, which means this is an opt-in feature for tests.
It collects them in a singleton class and then uses the PHPUnit
extension to display them in a formatted table at the end of the test
run.

Implementing it is a matter of using the `CollectValinorMappingErrors`
trait in your TestCase class and registering the
`PrettyPrintMappingErrorsExtension` extension class in the phpunit
configuration file. A PR to update the documentation will be made
separately.

This does require symfony/console for its table printing capabilities,
copying that logic into the library seemed excessive. In order to not
have a hard dependency on it, it is put in the suggest array in
composer.json and we are using a class_exists check to see if it is
installed.

Developed by: Social Deal (@socialdeal)

Signed-off-by: NanoSector <[email protected]>
@NanoSector NanoSector force-pushed the feature/phpunit-extension branch from a8e570e to 25af27e Compare November 1, 2025 18:51
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