Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a problem with HalRenderer when the body is null #230

Merged
merged 4 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Hypermedia framework for object as a service

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/bearsunday/BEAR.Resource/badges/quality-score.png?b=1.x)](https://scrutinizer-ci.com/g/bearsunday/BEAR.Resource/?branch=1.x)
[![codecov](https://codecov.io/gh/bearsunday/BEAR.Resource/branch/1.x/graph/badge.svg?token=eh3c9AF4Mr)](undefined)
[![codecov](https://codecov.io/gh/bearsunday/BEAR.Resource/branch/1.x/graph/badge.svg?token=eh3c9AF4Mr)](https://codecov.io/gh/koriym/BEAR.Resource)
[![Type Coverage](https://shepherd.dev/github/bearsunday/BEAR.Resource/coverage.svg)](https://shepherd.dev/github/bearsunday/BEAR.Resource)
[![Build Status](https://travis-ci.org/bearsunday/BEAR.Resource.svg?branch=1.x)](https://travis-ci.org/bearsunday/BEAR.Resource)
[![Build Status](https://scrutinizer-ci.com/g/bearsunday/BEAR.Resource/badges/build.png?b=1.x)](https://scrutinizer-ci.com/g/bearsunday/BEAR.Resource/build-status/1.x)
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<file name="src/OptionsMethods.php"/>
<file name="src/OptionsMethodRequest.php"/>
<directory name="vendor" />
<directory name="tests" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
Expand Down
4 changes: 4 additions & 0 deletions src/HalRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ private function valuate(ResourceObject $ro): array
$ro->body = ['value' => $ro->body];
}

if ($ro->body === null) {
$ro->body = [];
}

// evaluate all request in body.
$this->valuateElements($ro);
assert(is_array($ro->body));
Expand Down
20 changes: 20 additions & 0 deletions tests/Renderer/HalRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ public function testNonArrayBody(): void
}
}

EOT;
$this->assertSame($expected, $actual);
}

public function testRenderNullBody(): void
{
$this->ro->body = null;
$actual = (string) $this->ro;
$expected = <<<'EOT'
{
"_links": {
"self": {
"href": "/dummy"
},
"profile": {
"href": "/profile"
}
}
}

EOT;
$this->assertSame($expected, $actual);
}
Expand Down