Skip to content

Commit 4b713a9

Browse files
committed
Fix for #1012
1 parent e48a8e8 commit 4b713a9

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/Elasticsearch/Common/Exceptions/Serializer/JsonErrorException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Class JsonErrorException
1111
*
1212
* @category Elasticsearch
13-
* @package Elasticsearch\Common\Exceptions\Curl
13+
* @package Elasticsearch\Common\Exceptions\Serializer
1414
* @author Bez Hermoso <[email protected]>
1515
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
1616
* @link http://elastic.co

src/Elasticsearch/Serializers/SmartSerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private function decode(?string $data): array
8181
return $result;
8282
} catch (\JsonException $e) {
8383
$result = $result ?? [];
84-
throw new JsonErrorException($e->getMessage(), $data, $result);
84+
throw new JsonErrorException($e->getCode(), $data, $result);
8585
}
8686
}
8787

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Elasticsearch\Tests\Serializers;
6+
7+
use Elasticsearch\Common\Exceptions\Serializer\JsonErrorException;
8+
use Elasticsearch\Serializers\SmartSerializer;
9+
use Mockery as m;
10+
use PHPUnit\Framework\TestCase;
11+
12+
/**
13+
* Class SmartSerializerTest
14+
*
15+
* @package Elasticsearch\Tests\Serializers
16+
*/
17+
class SmartSerializerTest extends TestCase
18+
{
19+
public function setUp(): void
20+
{
21+
$this->serializer = new SmartSerializer();
22+
}
23+
24+
/**
25+
* @requires PHP 7.3
26+
* @see https://github.com/elastic/elasticsearch-php/issues/1012
27+
*/
28+
public function testThrowJsonErrorException()
29+
{
30+
$this->expectException(JsonErrorException::class);
31+
$this->expectExceptionCode(JSON_ERROR_SYNTAX);
32+
33+
$result = $this->serializer->deserialize('{ "foo" : bar" }', []);
34+
}
35+
}

0 commit comments

Comments
 (0)