Skip to content

Commit

Permalink
Fix call to undefined function json_last_error_message
Browse files Browse the repository at this point in the history
  • Loading branch information
dawehner authored and fabpot committed Nov 18, 2015
1 parent 1760838 commit 15f9cf2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Serializer/Encoder/JsonDecode.php
Expand Up @@ -108,7 +108,7 @@ public function decode($data, $format, array $context = array())
}

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;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Serializer/Encoder/JsonEncode.php
Expand Up @@ -56,7 +56,7 @@ public function encode($data, $format, array $context = array())
$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;
Expand Down
44 changes: 44 additions & 0 deletions src/Symfony/Component/Serializer/Tests/Encoder/JsonDecodeTest.php
@@ -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');
}
}

0 comments on commit 15f9cf2

Please sign in to comment.