PHPStan integration
What a milestone! We were finally able to help out our friends from PHPStan. They started integrating bashunit in their end-to-end tests, which ended up creating a new feature, adding new assertions and improving multiline string comparisons.
TL;DR: From now on, you can run bashunit assertions standalone (without a test context), a new assert_line_count function, and improved multiline-string comparison.
Earlier this week, PHPStan started integrating bashunit
in their e2e tests (PR).
However, they didn't want to use bashunit test runner, instead they were interested only in the assert functions standalone of the core library (Issue).
"Basically we want to use the nice assertions syntax of bashunit not to unit tests bash functions, but to end-to-end tests executables."
@ondrejmirtes
This wasn't something that bashunit supported (yet), so @staabm
created a custom script to allow this. That was the beginning of an intense couple of days discovering together how to implement bashunit in such a big existing system, and a motivation for us to support this feature natively from bashunit
- which means, an optimized script and feature from within the library.
Here is an example of the result of how they finally implemented bashunit:
- [ $(echo "$OUTPUT" | wc -l) -eq 1 ]
- grep 'Method TraitsCachingIssue\\TestClassUsingTrait::doBar() should return stdClass but returns Exception.' <<< "$OUTPUT"
+ ../bashunit -a line_count 1 "$OUTPUT"
+ ../bashunit -a contains 'Method TraitsCachingIssue\TestClassUsingTrait::doBar() should return stdClass but returns Exception.' "$OUTPUT"
./bashunit -a|--assert [...args]
allows you to call any assertion outside the test runner, which means you can run them standalone.
Additionally, we discovered that multiline string comparison didn't work as expected, so we fixed that. And @staabm
helped us adding a new assert function to check the number of lines within a string.
And now, all of these have been released from 0.13 onwards! Enjoy!