From fe4e0f04ce0d867008bdfccfdd36f20f46a27068 Mon Sep 17 00:00:00 2001 From: Daniel Wehner Date: Wed, 18 Nov 2015 09:21:04 +0100 Subject: [PATCH 1/2] Fix call to undefined function json_last_error_message --- .../Serializer/Encoder/JsonDecode.php | 2 +- .../Serializer/Encoder/JsonEncode.php | 2 +- .../Tests/Encoder/JsonDecodeTest.php | 44 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Component/Serializer/Tests/Encoder/JsonDecodeTest.php diff --git a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php index d4070c23040db..8925ec36f7f99 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php @@ -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; diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php index aa7d64530e14d..454c0d6a11470 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php @@ -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; diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/JsonDecodeTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/JsonDecodeTest.php new file mode 100644 index 0000000000000..9180f532d0a96 --- /dev/null +++ b/src/Symfony/Component/Serializer/Tests/Encoder/JsonDecodeTest.php @@ -0,0 +1,44 @@ + + * + * 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 \UnexpectedValueException + */ + public function testDecodeWithInvalidData() + { + $result = $this->decoder->decode('kaboom!', 'json'); + } +} From 989d1974c628d0cd0d73b7c761a9296e796c425f Mon Sep 17 00:00:00 2001 From: Daniel Wehner Date: Wed, 18 Nov 2015 10:52:26 +0100 Subject: [PATCH 2/2] fixed review points --- .../Component/Serializer/Tests/Encoder/JsonDecodeTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/JsonDecodeTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/JsonDecodeTest.php index 9180f532d0a96..03f2187b5576f 100644 --- a/src/Symfony/Component/Serializer/Tests/Encoder/JsonDecodeTest.php +++ b/src/Symfony/Component/Serializer/Tests/Encoder/JsonDecodeTest.php @@ -20,7 +20,7 @@ class JsonDecodeTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->decoder = new JsonDecode(TRUE); + $this->decoder = new JsonDecode(true); } public function testDecodeWithValidData() @@ -35,7 +35,7 @@ public function testDecodeWithValidData() } /** - * @expectedException \UnexpectedValueException + * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException */ public function testDecodeWithInvalidData() { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy