Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Mar 10, 2021
1 parent 46c780c commit 3177c90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ First thing you will need to do after creating a resource tests is filling the `
the resource properties. It's also not needed to map each property of the resource, just the ones that change or are required to be diferent.

```php
protected function remapResource($resource)
protected function remapResource($resource): array
{
return [
'location' => $resource->location_id,
Expand Down
17 changes: 7 additions & 10 deletions src/Traits/InteractsWithNovaResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function storeResource($data = []): TestResponse
$resource = $this->mergeData($data, true);

return $this->beDefaultUser()
->novaStore($this->resourceClass::uriKey(), $resource->toArray());
->novaStore($this->resourceClass::uriKey(), $resource);
}

/**
Expand All @@ -97,10 +97,7 @@ protected function updateResource($data = []): TestResponse
$resource = $this->mergeData($data);

return $this->beDefaultUser()
->novaUpdate(
$this->resourceClass::uriKey() . '/' . $resource['id'],
$resource->toArray()
);
->novaUpdate($this->resourceClass::uriKey() . '/' . $resource['id'], $resource);
}

/**
Expand All @@ -116,7 +113,7 @@ protected function deleteResource($data = []): TestResponse
$data = ['id' => $data];
}

$resource = Arr::only($this->mergeData($data)->toArray(), 'id');
$resource = Arr::only($this->mergeData($data), 'id');

return $this->beDefaultUser()
->novaDelete($this->resourceClass::uriKey(), $resource);
Expand Down Expand Up @@ -203,7 +200,7 @@ private function mapIndexToName($list): array
*
* @return \Illuminate\Database\Eloquent\Model
*/
private function mergeData($data = [], $isStoreRequest = false): Model
private function mergeData($data = [], $isStoreRequest = false): array
{
if (!is_array($data) && $data instanceof Model) {
$data = $data->toArray();
Expand All @@ -214,10 +211,10 @@ private function mergeData($data = [], $isStoreRequest = false): Model
? $factory->make($data)
: $factory->create($data);

return $resource
->makeVisible($resource->getHidden())
->forceFill($this->remapResource($resource))
$resource->makeVisible($resource->getHidden())
->forceFill($this->clearPrefilledData());

return array_merge($resource->toArray(), $this->remapResource($resource));
}

/**
Expand Down

0 comments on commit 3177c90

Please sign in to comment.