Skip to content

Commit 808a66e

Browse files
committed
Merge branch 'release/1.1.1'
2 parents 04a1956 + fa3326b commit 808a66e

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
}
2626
],
2727
"require": {
28-
"php": "^7.1"
28+
"php": "^7.1",
29+
"ext-json": "*"
2930
},
3031
"require-dev": {
3132
"orchestra/testbench": "~3.6.0",
32-
"phpunit/phpunit": "^7.3"
33+
"phpunit/phpunit": "^7.3",
34+
"mockery/mockery": "^1.2"
3335
},
3436
"autoload": {
3537
"psr-4": {

src/Body.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function toJson($options = 0): string
148148
$json = json_encode($this->toArray(), $options);
149149

150150
if (JSON_ERROR_NONE !== json_last_error()) {
151-
throw JsonEncodingException::forModel($this, json_last_error_msg());
151+
throw new JsonEncodingException;
152152
}
153153

154154
return $json;

tests/BodyTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public function provider()
1515
];
1616
}
1717

18-
1918
/**
2019
* @dataProvider provider
2120
*/
@@ -38,7 +37,6 @@ public function testAddMessageToBody()
3837
$this->assertEquals(['Hello World'], $body->getMessages());
3938
}
4039

41-
4240
/**
4341
* @dataProvider provider
4442
*/
@@ -49,4 +47,16 @@ public function testBodyConvertedToJson($status, $data, $messages, $meta)
4947

5048
$this->assertJson($body->toJson());
5149
}
50+
51+
public function testInvalidJsonThrowsError()
52+
{
53+
$this->expectException(JsonEncodingException::class);
54+
55+
$body = \Mockery::mock(Body::class)->makePartial();
56+
57+
$body->shouldReceive('toArray')
58+
->andReturn([NAN]);
59+
60+
$body->toJson();
61+
}
5262
}

0 commit comments

Comments
 (0)