Skip to content

Commit f652d28

Browse files
committed
Fix bug in abstract decoder.
1 parent 1320479 commit f652d28

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/Decoders/AbstractDecoder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
abstract class AbstractDecoder implements DecoderInterface
2929
{
3030

31-
const ERROR_INVALID_JSON = 'invalid-json';
32-
3331
/**
3432
* @param $content
3533
* @param bool|false $assoc
@@ -45,7 +43,7 @@ public function parseJson($content, $assoc = false, $depth = 512, $options = 0)
4543
throw new ThrowableError([
4644
ThrowableError::TITLE => 'Invalid JSON',
4745
ThrowableError::DETAIL => 'Request body content could not be parsed as JSON: ' . json_last_error_msg(),
48-
], 400, static::ERROR_INVALID_JSON);
46+
], 400);
4947
}
5048

5149
return $parsed;

src/Error/ThrowableError.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class ThrowableError extends RuntimeException implements ErrorInterface
6969

7070
/**
7171
* @param string $titleOrArray
72+
* @param int|null $status
7273
* @param null $code
7374
* @param Exception|null $previous
7475
*/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace CloudCreativity\JsonApi\Decoders;
4+
5+
use CloudCreativity\JsonApi\Error\ThrowableError;
6+
7+
class DocumentDecoderTest extends \PHPUnit_Framework_TestCase
8+
{
9+
10+
public function testInvalidJson()
11+
{
12+
$content = <<<EOL
13+
{
14+
"data": {
15+
"type": "foo"
16+
}
17+
EOL;
18+
19+
$decoder = new DocumentDecoder();
20+
21+
$this->setExpectedException(ThrowableError::class);
22+
$decoder->decode($content);
23+
}
24+
}

0 commit comments

Comments
 (0)