Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Fix bug arraying errors
Browse files Browse the repository at this point in the history
  • Loading branch information
VGirol committed Sep 27, 2019
1 parent c64c819 commit e8ac0f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/Factory/DocumentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public function toArray(): array
$json[Members::LINKS] = $this->links;
}
if (isset($this->errors)) {
$json[Members::ERRORS] = $this->errors;
$json[Members::ERRORS] = array_map(
function ($error) {
return $error->toArray();
},
$this->errors
);
}
if ($this->dataHasBeenSet()) {
$json[Members::DATA] = ($this->data === null) ? null : $this->data->toArray();
Expand Down
9 changes: 4 additions & 5 deletions tests/Factory/DocumentFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\Assert as PHPUnit;
use VGirol\JsonApiFaker\Factory\DocumentFactory;
use VGirol\JsonApiFaker\Factory\ErrorFactory;
use VGirol\JsonApiFaker\Factory\JsonapiFactory;
use VGirol\JsonApiFaker\Factory\RelationshipFactory;
use VGirol\JsonApiFaker\Factory\ResourceIdentifierFactory;
Expand Down Expand Up @@ -63,11 +64,9 @@ public function toArrayWithErrors()
'self' => 'url'
];
$jsonapi = (new JsonapiFactory)->setVersion('test');
$error = (new ErrorFactory)->setId('errorId')->set('code', 'secret');
$errors = [
[
'id' => 'errorId',
'code' => 'secret'
]
$error->toArray()
];

$expected = [
Expand All @@ -83,7 +82,7 @@ public function toArrayWithErrors()
$factory->setMeta($meta)
->setLinks($links)
->setJsonapi($jsonapi)
->setErrors($errors);
->addError($error);

$result = $factory->toArray();

Expand Down

0 comments on commit e8ac0f2

Please sign in to comment.