mikeerickson / phpunit-pretty-result-printer

PHPUnit Pretty Result Printer -- make your PHPUnit tests look pretty!
MIT License
1.2k stars 71 forks source link

Fix potential fatal error from sprintf not getting enough arguments when formatting exception message #135

Closed HWesterlund closed 5 years ago

HWesterlund commented 5 years ago

Fixes a potential fatal error from sprintf not getting enough arguments when formatting exception message in ResultPrinter71::formatExceptionMsg. This occurred when the failing assertions had custom messages.

Additionally the fix prevents the same from occurring if an exception message contains %'s.

Other than that thank you for making our test output bearable to look at, as well as more informative.

Example output from it happening on circleci:

Warning: sprintf(): Too few arguments in /home/circleci/project/vendor/codedungeon/phpunit-result-printer/src/ResultPrinter71.php on line 77

Call Stack: 0.0001 417616 1. {main}() /home/circleci/project/vendor/phpunit/phpunit/phpunit:0 0.0463 3507608 2. PHPUnit\TextUI\Command::main() /home/circleci/project/vendor/phpunit/phpunit/phpunit:61 0.0463 3507720 3. PHPUnit\TextUI\Command->run() /home/circleci/project/vendor/phpunit/phpunit/src/TextUI/Command.php:162 0.3840 29197288 4. PHPUnit\TextUI\TestRunner->doRun() /home/circleci/project/vendor/phpunit/phpunit/src/TextUI/Command.php:206 1106.6737 35645352 5. Codedungeon\PHPUnitPrettyResultPrinter\Printer->printResult() /home/circleci/project/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:633 1106.6738 35645328 6. Codedungeon\PHPUnitPrettyResultPrinter\Printer->printFailures() /home/circleci/project/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php:186 1106.6738 35645328 7. Codedungeon\PHPUnitPrettyResultPrinter\Printer->printDefects() /home/circleci/project/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php:385 1106.6738 35646744 8. Codedungeon\PHPUnitPrettyResultPrinter\Printer->printDefect() /home/circleci/project/vendor/codedungeon/phpunit-result-printer/src/ResultPrinter71.php:126 1106.6738 35646744 9. Codedungeon\PHPUnitPrettyResultPrinter\Printer->printDefectTrace() /home/circleci/project/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php:354 1106.6738 35646904 10. Codedungeon\PHPUnitPrettyResultPrinter\Printer->formatExceptionMsg() /home/circleci/project/vendor/codedungeon/phpunit-result-printer/src/ResultPrinter71.php:84 1106.6740 35646936 11. sprintf() /home/circleci/project/vendor/codedungeon/phpunit-result-printer/src/ResultPrinter71.php:77