Fix call to undefined function json_last_error_message

This commit is contained in:
Daniel Wehner 2015-11-18 09:21:04 +01:00 committed by Fabien Potencier
parent 17608389f1
commit 15f9cf2740
3 changed files with 46 additions and 2 deletions

View File

@ -108,7 +108,7 @@ class JsonDecode implements DecoderInterface
}
if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) {
throw new UnexpectedValueException(json_last_error_message());
throw new UnexpectedValueException(json_last_error_msg());
}
return $decodedData;

View File

@ -56,7 +56,7 @@ class JsonEncode implements EncoderInterface
$encodedJson = json_encode($data, $context['json_encode_options']);
if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) {
throw new UnexpectedValueException(json_last_error_message());
throw new UnexpectedValueException(json_last_error_msg());
}
return $encodedJson;

View File

@ -0,0 +1,44 @@
<?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\Serializer\Tests\Encoder;
use Symfony\Component\Serializer\Encoder\JsonDecode;
class JsonDecodeTest extends \PHPUnit_Framework_TestCase
{
/** @var \Symfony\Component\Serializer\Encoder\JsonDecode */
private $decoder;
protected function setUp()
{
$this->decoder = new JsonDecode(true);
}
public function testDecodeWithValidData()
{
$json = json_encode(array(
'hello' => 'world',
));
$result = $this->decoder->decode($json, 'json');
$this->assertEquals(array(
'hello' => 'world',
), $result);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
*/
public function testDecodeWithInvalidData()
{
$result = $this->decoder->decode('kaboom!', 'json');
}
}