Skip to content

Commit

Permalink
Merge branch 'fix/json-error-exception' into 7.7
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Apr 30, 2020
2 parents 4a76480 + 0ad4671 commit 49a6c10
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Class JsonErrorException
*
* @category Elasticsearch
* @package Elasticsearch\Common\Exceptions\Curl
* @package Elasticsearch\Common\Exceptions\Serializer
* @author Bez Hermoso <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elastic.co
Expand Down
2 changes: 1 addition & 1 deletion src/Elasticsearch/Serializers/SmartSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private function decode(?string $data): array
return $result;
} catch (\JsonException $e) {
$result = $result ?? [];
throw new JsonErrorException($e->getMessage(), $data, $result);
throw new JsonErrorException($e->getCode(), $data, $result);
}
}

Expand Down
35 changes: 35 additions & 0 deletions tests/Elasticsearch/Tests/Serializers/SmartSerializerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests\Serializers;

use Elasticsearch\Common\Exceptions\Serializer\JsonErrorException;
use Elasticsearch\Serializers\SmartSerializer;
use Mockery as m;
use PHPUnit\Framework\TestCase;

/**
* Class SmartSerializerTest
*
* @package Elasticsearch\Tests\Serializers
*/
class SmartSerializerTest extends TestCase
{
public function setUp(): void
{
$this->serializer = new SmartSerializer();
}

/**
* @requires PHP 7.3
* @see https://github.com/elastic/elasticsearch-php/issues/1012
*/
public function testThrowJsonErrorException()
{
$this->expectException(JsonErrorException::class);
$this->expectExceptionCode(JSON_ERROR_SYNTAX);

$result = $this->serializer->deserialize('{ "foo" : bar" }', []);
}
}

0 comments on commit 49a6c10

Please sign in to comment.