Skip to content

Commit

Permalink
Set same code with self link response
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Apr 5, 2024
1 parent f6d131a commit dd77b62
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/EmbedInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use function array_shift;
use function assert;
use function is_array;
use function is_string;
use function uri_template;

final class EmbedInterceptor implements MethodInterceptor
Expand Down Expand Up @@ -113,8 +114,14 @@ private function getArgsByInvocation(MethodInvocation $invocation): array
public function linkSelf(Request $request, ResourceObject $ro): void
{
$result = $request();
foreach ($result as $key => $value) {
$ro->body[$key] = $value;
assert(is_array($result->body));
/** @var mixed $value */
foreach ($result->body as $key => $value) {
assert(is_string($key));
/** @psalm-suppress MixedArrayAssignment */
$ro->body[$key] = $value; // @phpstan-ignore-line
}

$ro->code = $result->code;
}
}
1 change: 1 addition & 0 deletions tests/EmbedInterceptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function testSelfLink(): void
$embeded = $this->resource->uri('app://self/bird/child')(['id' => 1]);
$result = $this->resource->uri('app://self/bird/self-link')(['id' => 1]);
$this->assertSame($result->body, $embeded->body);
$this->assertSame($result->code, $embeded->code);
}

public function testInvokeRelativePath(): BirdsRel
Expand Down
2 changes: 2 additions & 0 deletions tests/Fake/FakeVendor/Sandbox/Resource/App/Bird/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class Child extends ResourceObject
{
public $code = 100;

public function onGet(string $id)
{
$this->body = [
Expand Down

0 comments on commit dd77b62

Please sign in to comment.