Skip to content

Commit

Permalink
[Yaml] Fixed filename in the ParseException message
Browse files Browse the repository at this point in the history
  • Loading branch information
unkind committed Aug 30, 2013
1 parent 7e06905 commit da44651
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Component/Yaml/Exception/ParseException.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
30 changes: 30 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParseExceptionTest.php
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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()
);
}
}

0 comments on commit da44651

Please sign in to comment.