Skip to content

Commit 5015391

Browse files
dawehnerfabpot
authored andcommitted
Fix call to undefined function json_last_error_message
1 parent 8f4052a commit 5015391

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

Encoder/JsonDecode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function decode($data, $format, array $context = array())
108108
}
109109

110110
if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) {
111-
throw new UnexpectedValueException(json_last_error_message());
111+
throw new UnexpectedValueException(json_last_error_msg());
112112
}
113113

114114
return $decodedData;

Encoder/JsonEncode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function encode($data, $format, array $context = array())
5656
$encodedJson = json_encode($data, $context['json_encode_options']);
5757

5858
if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) {
59-
throw new UnexpectedValueException(json_last_error_message());
59+
throw new UnexpectedValueException(json_last_error_msg());
6060
}
6161

6262
return $encodedJson;

Tests/Encoder/JsonDecodeTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Encoder;
13+
14+
use Symfony\Component\Serializer\Encoder\JsonDecode;
15+
16+
class JsonDecodeTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/** @var \Symfony\Component\Serializer\Encoder\JsonDecode */
19+
private $decoder;
20+
21+
protected function setUp()
22+
{
23+
$this->decoder = new JsonDecode(true);
24+
}
25+
26+
public function testDecodeWithValidData()
27+
{
28+
$json = json_encode(array(
29+
'hello' => 'world',
30+
));
31+
$result = $this->decoder->decode($json, 'json');
32+
$this->assertEquals(array(
33+
'hello' => 'world',
34+
), $result);
35+
}
36+
37+
/**
38+
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
39+
*/
40+
public function testDecodeWithInvalidData()
41+
{
42+
$result = $this->decoder->decode('kaboom!', 'json');
43+
}
44+
}

0 commit comments

Comments
 (0)