4 * This file is part of the Behat Testwork.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Testwork\Exception\Stringer;
16 * Strings PHPUnit assertion exceptions.
18 * @see ExceptionPresenter
20 * @author Konstantin Kudryashov <ever.zet@gmail.com>
22 final class PHPUnitExceptionStringer implements ExceptionStringer
27 public function supportsException(Exception $exception)
29 return $exception instanceof \PHPUnit_Framework_Exception
30 || $exception instanceof \PHPUnit\Framework\Exception;
36 public function stringException(Exception $exception, $verbosity)
38 if (!class_exists('PHPUnit\\Framework\\TestFailure')) {
39 return trim(\PHPUnit_Framework_TestFailure::exceptionToString($exception));
42 // PHPUnit assertion exceptions do not include expected / observed info in their
43 // messages, but expect the test listeners to format that info like the following
44 // (see e.g. PHPUnit_TextUI_ResultPrinter::printDefectTrace)
45 return trim(\PHPUnit\Framework\TestFailure::exceptionToString($exception));