From da44651dc092a31c734e05d2cb94b47666f9f0cc Mon Sep 17 00:00:00 2001 From: Nikita Konstantinov Date: Sat, 31 Aug 2013 03:32:21 +0400 Subject: [PATCH] [Yaml] Fixed filename in the ParseException message --- .../Yaml/Exception/ParseException.php | 6 ++-- .../Yaml/Tests/ParseExceptionTest.php | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 src/Symfony/Component/Yaml/Tests/ParseExceptionTest.php diff --git a/src/Symfony/Component/Yaml/Exception/ParseException.php b/src/Symfony/Component/Yaml/Exception/ParseException.php index a27a005e6f55..7efa15114002 100644 --- a/src/Symfony/Component/Yaml/Exception/ParseException.php +++ b/src/Symfony/Component/Yaml/Exception/ParseException.php @@ -32,9 +32,9 @@ class ParseException extends RuntimeException * @param integer $parsedLine The line where the error occurred * @param integer $snippet The snippet of code near the problem * @param string $parsedFile The file name where the error occurred - * @param Exception $previous The previous exception + * @param \Exception $previous The previous exception */ - public function __construct($message, $parsedLine = -1, $snippet = null, $parsedFile = null, Exception $previous = null) + public function __construct($message, $parsedLine = -1, $snippet = null, $parsedFile = null, \Exception $previous = null) { $this->parsedFile = $parsedFile; $this->parsedLine = $parsedLine; @@ -125,7 +125,7 @@ private function updateRepr() } if (null !== $this->parsedFile) { - $this->message .= sprintf(' in %s', json_encode($this->parsedFile)); + $this->message .= sprintf(' in "%s"', $this->parsedFile); } if ($this->parsedLine >= 0) { diff --git a/src/Symfony/Component/Yaml/Tests/ParseExceptionTest.php b/src/Symfony/Component/Yaml/Tests/ParseExceptionTest.php new file mode 100644 index 000000000000..7d0dea837ca6 --- /dev/null +++ b/src/Symfony/Component/Yaml/Tests/ParseExceptionTest.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Yaml\Tests; + +use Symfony\Component\Yaml\Exception\ParseException; +use Symfony\Component\Yaml\Yaml; + +class ParseExceptionTest extends \PHPUnit_Framework_TestCase +{ + public function testGetMessage() + { + $exception = new ParseException( + 'Error message', 42, 'foo: bar', '/var/www/app/config.yml' + ); + + $this->assertEquals( + 'Error message in "/var/www/app/config.yml" at line 42 (near "foo: bar")', + $exception->getMessage() + ); + } +}