Fix call to undefined function json_last_error_message
This commit is contained in:
parent
17608389f1
commit
15f9cf2740
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user