This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/lib/vendor/lime/LimeAssertionFailedException.php
2010-01-04 15:26:20 +01:00

62 lines
1.3 KiB
PHP

<?php
/*
* This file is part of the Lime framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
class LimeAssertionFailedException extends Exception
{
private
$actual = '',
$expected = '';
public function __construct($actual, $expected)
{
parent::__construct(sprintf('Got: %s, Expected: %s', $actual, $expected));
$this->actual = (string)$actual;
$this->expected = (string)$expected;
}
public function getActual($indentation = 0)
{
if ($indentation > 0)
{
return $this->indent($this->actual, $indentation);
}
else
{
return $this->actual;
}
}
public function getExpected($indentation = 0)
{
if ($indentation > 0)
{
return $this->indent($this->expected, $indentation);
}
else
{
return $this->expected;
}
}
protected function indent($lines, $indentation = 2)
{
$lines = explode("\n", $lines);
foreach ($lines as $key => $line)
{
$lines[$key] = str_repeat(' ', $indentation).$line;
}
return trim(implode("\n", $lines));
}
}