Skip to content

Commit

Permalink
Updated errors accessor bug
Browse files Browse the repository at this point in the history
  • Loading branch information
elb98rm committed Oct 6, 2020
1 parent 688742e commit 571c4d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
7 changes: 6 additions & 1 deletion src/Models/JsonApiFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ public function setErrors(array $errors): JsonApiFormatter
*/
public function addErrors(array $extra_errors): JsonApiFormatter
{
$this->setErrors(array_merge($this->getErrors() ?? [], $extra_errors));
$errors = $this->getErrors() ?? [];
foreach($extra_errors as $error) {
$errors[] = $error;
}

$this->setErrors($errors);
return $this;
}

Expand Down
22 changes: 5 additions & 17 deletions tests/Unit/JsonApiFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,30 +348,18 @@ public function testErrorResponse()

$test_errors = [$error, $error2];

// make 2 maually checked correct arrays:
// make 2 manually checked correct arrays:
$validated_array = [
'errors' => [
(object)[
'status' => '400',
'title' => 'Bad request',
'detail' => 'The request was not formed well'
],
(object)[
'status' => '400',
'title' => 'Bad request 2',
'detail' => 'The request was not formed well either'
]
$error,
$error2
],
'meta' => (object)['status' => null],
'jsonapi' => (object)['version' => '1.0']
];
$validated_array2 = [
'errors' => [
(object)[
'status' => '400',
'title' => 'Bad request',
'detail' => 'The request was not formed well'
]
$error2
],
'meta' => (object)['status' => null],
'jsonapi' => (object)['version' => '1.0']
Expand All @@ -387,7 +375,7 @@ public function testErrorResponse()
$this->assertEquals($validated_json, $response);

$json_api_formatter = new JsonApiFormatter();
$response = $json_api_formatter->errorResponse([$error]);
$response = $json_api_formatter->errorResponse([$error2]);
$this->assertEquals($validated_json2, $response);
}

Expand Down

0 comments on commit 571c4d1

Please sign in to comment.