Skip to content

Commit befe386

Browse files
committed
Merge branch 'hotfix/1'
Close #1
2 parents e611d2c + 1be8e94 commit befe386

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ All notable changes to this project will be documented in this file, in reverse
2222

2323
### Fixed
2424

25-
- Nothing.
25+
- [#1](https://github.com/laminas/laminas-json-server/pull/1) Allows optional `data` field in Error object to be omitted
26+
2627

2728
## 3.2.0 - 2019-10-17
2829

src/Response.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public function setOptions(array $options)
6464
// re-produce error state
6565
if (isset($options['error']) && is_array($options['error'])) {
6666
$error = $options['error'];
67-
$options['error'] = new Error($error['message'], $error['code'], $error['data']);
67+
$errorData = isset($error['data']) ? $error['data'] : null;
68+
$options['error'] = new Error($error['message'], $error['code'], $errorData);
6869
}
6970

7071
$methods = get_class_methods($this);

test/ResponseTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
class ResponseTest extends TestCase
1818
{
19+
private $response;
1920
/**
2021
* Sets up the fixture, for example, open a network connection.
2122
* This method is called before a test is executed.
@@ -212,4 +213,22 @@ public function testValueOfZeroForOptionsKeyShouldNotBeInterpretedAsVersionKey()
212213
]);
213214
$this->assertNull($this->response->getVersion());
214215
}
216+
217+
/**
218+
* Assert that error data can be omitted
219+
* @see https://www.jsonrpc.org/specification#response_object
220+
*/
221+
public function testSetOptionsAcceptsErrorWithEmptyDate()
222+
{
223+
$this->response->setOptions([
224+
'error' => [
225+
'code' => 0,
226+
'message' => 'Lorem Ipsum',
227+
],
228+
]);
229+
$this->assertInstanceOf(Error::class, $this->response->getError());
230+
$this->assertEquals(-32000, $this->response->getError()->getCode());
231+
$this->assertEquals('Lorem Ipsum', $this->response->getError()->getMessage());
232+
$this->assertEquals(null, $this->response->getError()->getData());
233+
}
215234
}

0 commit comments

Comments
 (0)