Skip to content
This repository was archived by the owner on Jun 18, 2020. It is now read-only.

Commit 881be00

Browse files
Vpack::fromArray() now supports PHPs null
1 parent 151cf5f commit 881be00

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/vpackImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ namespace arangodb { namespace fuerte { namespace php {
4949
case IS_FALSE:
5050
b->add(vpackKey, arangodb::velocypack::Value(false));
5151
break;
52+
case IS_NULL:
53+
b->add(vpackKey, arangodb::velocypack::Value(arangodb::velocypack::ValueType::Null));
54+
break;
5255
case IS_ARRAY:
5356
if(HT_IS_PACKED(Z_ARRVAL_P(data)) && HT_IS_WITHOUT_HOLES(Z_ARRVAL_P(data))) {
5457
b->add(vpackKey, arangodb::velocypack::Value(arangodb::velocypack::ValueType::Array));
@@ -92,6 +95,9 @@ namespace arangodb { namespace fuerte { namespace php {
9295
case IS_FALSE:
9396
b->add(arangodb::velocypack::Value(false));
9497
break;
98+
case IS_NULL:
99+
b->add(arangodb::velocypack::Value(arangodb::velocypack::ValueType::Null));
100+
break;
95101
case IS_ARRAY:
96102
if(HT_IS_PACKED(Z_ARRVAL_P(data)) && HT_IS_WITHOUT_HOLES(Z_ARRVAL_P(data))) {
97103
b->add(arangodb::velocypack::Value(arangodb::velocypack::ValueType::Array));

tests/VpackTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ public function it_produces_a_proper_vpack(): void
9191
111
9292
],
9393
[23, 58, 10],
94-
[0 => 10, 1 => 20, 3 => 30]
94+
[0 => 10, 1 => 20, 3 => 30],
95+
"null" => null
9596
];
9697

9798
$vpackFromArray = Vpack::fromArray($arr);
9899

99100
$this->assertEquals(
100-
"{\"0\":10,\"1\":20,\"2\":[23,58,10],\"3\":{\"0\":10,\"1\":20,\"3\":30},\"a\":\"111\",\"arr\":{\"0\":111,\"a\":\"b\"},\"b\":222,\"c\":true,\"d\":false,\"e\":3.2}",
101+
"{\"0\":10,\"1\":20,\"2\":[23,58,10],\"3\":{\"0\":10,\"1\":20,\"3\":30},\"a\":\"111\",\"arr\":{\"0\":111,\"a\":\"b\"},\"b\":222,\"c\":true,\"d\":false,\"e\":3.2,\"null\":null}",
101102
$vpackFromArray->toJson()
102103
);
103104
}

0 commit comments

Comments
 (0)