Eloquent\Phony\Assertion\Exception\AssertionException::trim PHP Method

trim() public static method

Also replaces the file path and line number.
public static trim ( Exception $exception )
$exception Exception The exception.
    public static function trim(Exception $exception)
    {
        $reflector = new ReflectionClass('Exception');
        $traceProperty = $reflector->getProperty('trace');
        $traceProperty->setAccessible(true);
        $fileProperty = $reflector->getProperty('file');
        $fileProperty->setAccessible(true);
        $lineProperty = $reflector->getProperty('line');
        $lineProperty->setAccessible(true);
        $call = static::tracePhonyCall($traceProperty->getValue($exception));
        if ($call) {
            $traceProperty->setValue($exception, array($call));
            $fileProperty->setValue($exception, isset($call['file']) ? $call['file'] : null);
            $lineProperty->setValue($exception, isset($call['line']) ? $call['line'] : null);
        } else {
            $traceProperty->setValue($exception, array());
            $fileProperty->setValue($exception, null);
            $lineProperty->setValue($exception, null);
        }
    }

Usage Example

 /**
  * Construct a new PHPUnit assertion exception.
  *
  * @param string $description The failure description.
  */
 public function __construct($description)
 {
     AssertionException::trim($this);
     parent::__construct($description);
 }