8000 Merge branch 'develop' into async-with-cn · CodingSeo/laravel-json-api@76c7db3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 76c7db3

Browse files
committed
Merge branch 'develop' into async-with-cn
2 parents c37129c + c083d16 commit 76c7db3

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

docs/fetching/filtering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ If your resource does not support filtering, you should reject any request that
6060
parameter. You can do this by disallowing filtering parameters on your [Validators](../basics/validators.md)
6161
class as follows:
6262

63-
```php****
63+
```php
6464
class Validators extends AbstractValidators
6565
{
6666
// ...

src/Document/ResourceObject.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,10 @@ private function putAttr(string $field, $value): self
683683

684684
/**
685685
* @param string $field
686-
* @param array $value
686+
* @param array|null $value
687687
* @return ResourceObject
688688
*/
689-
private function putRelation(string $field, array $value): self
689+
private function putRelation(string $field, ?array $value): self
690690
{
691691
$copy = clone $this;
692692
$copy->relationships[$field] = $copy->relationships[$field] ?? [];

tests/lib/Unit/Document/ResourceObjectTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,29 @@ public function testReplaceAttribute(): void
288288
$this->assertSame($expected, $actual->toArray());
289289
}
290290

291-
public function testReplaceRelationship(): void
291+
public function testReplaceToOne(): void
292+
{
293+
$author = ['type' => 'users', 'id' => '999'];
294+
295+
$expected = $this->values;
296+
$expected['relationships']['author']['data'] = $author;
297+
298+
$this->assertNotSame($this->resource, $actual = $this->resource->replace('author', $author));
299+
$this->assertSame($this->values, $this->resource->toArray(), 'original resource is not modified');
300+
$this->assertSame($expected, $actual->toArray());
301+
}
302+
303+
public function testReplaceToOneNull(): void
304+
{
305+
$expected = $this->values;
306+
$expected['relationships']['author']['data'] = null;
307+
308+
$this->assertNotSame($this->resource, $actual = $this->resource->replace('author', null));
309+
$this->assertSame($this->values, $this->resource->toArray(), 'original resource is not modified');
310+
$this->assertSame($expected, $actual->toArray());
311+
}
312+
313+
public function testReplaceToMany(): void
292314
{
293315
$comments = [
294316
['type' => 'comments', 'id' => '123456'],

0 commit comments

Comments
 (0)
0