Skip to content

Commit

Permalink
Merge pull request #25 from microsoft/dev
Browse files Browse the repository at this point in the history
v0.4.3
  • Loading branch information
SilasKenneth authored Apr 13, 2023
2 parents 99b72e8 + c2172fb commit 9f30b6f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PHP Serialization JSON
name: PHP Serialization JSON

on:
workflow_dispatch:
Expand All @@ -15,7 +15,7 @@ jobs:
php-versions: ['7.4', '8.0', '8.1', '8.2']
steps:
- name: Checkout
uses: actions/checkout@v2.4.0
uses: actions/checkout@v3.5.1
- name: Setup PHP and Xdebug for Code Coverage report
uses: shivammathur/setup-php@v2
with:
Expand Down
7 changes: 6 additions & 1 deletion src/JsonParseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ public function getDateIntervalValue(): ?DateInterval{
}

public function getBinaryContent(): ?StreamInterface {
return ($this->jsonNode !== null) ? Utils::streamFor(strval($this->jsonNode)) : null;
if (is_null($this->jsonNode)) {
return null;
} elseif (is_array($this->jsonNode)) {
return Utils::streamFor(json_encode($this->jsonNode));
}
return Utils::streamFor(strval($this->jsonNode));
}
}
13 changes: 12 additions & 1 deletion tests/JsonParseNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class JsonParseNodeTest extends TestCase
private StreamInterface $stream;

protected function setUp(): void {
$this->stream = Utils::streamFor('{"@odata.type":"Missing", "name": "Silas Kenneth", "age": 98, "height": 123.122, "maritalStatus": "complicated,single", "address": {"city": "Nairobi", "street": "Luthuli"}}');
$this->stream = Utils::streamFor('{"@odata.type":"Missing","name":"Silas Kenneth","age":98,"height":123.122,"maritalStatus":"complicated,single","address":{"city":"Nairobi","street":"Luthuli"}}');
}

public function testGetIntegerValue(): void {
Expand Down Expand Up @@ -175,4 +175,15 @@ public function testCallbacksAreCalled(): void {
$person = $this->parseNode->getObjectValue([Person::class, 'createFromDiscriminatorValue']);
$this->assertTrue($assigned);
}

public function testGetBinaryContent(): void {
$this->parseNode = new JsonParseNode(100);
$this->assertEquals("100", $this->parseNode->getBinaryContent()->getContents());
}

public function testGetBinaryContentFromArray(): void {
$this->parseNode = new JsonParseNode(json_decode($this->stream->getContents(), true));
$this->stream->rewind();
$this->assertEquals($this->stream->getContents(), $this->parseNode->getBinaryContent()->getContents());
}
}

0 comments on commit 9f30b6f

Please sign in to comment.