Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

fix empty array in nested array not being translated to empty json co… #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 5 additions & 8 deletions src/HttpDriver/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function prepareRequest(Pipeline $pipeline)
$body = json_encode([
'statements' => $statements,
]);

$headers = [
[
'X-Stream' => true,
Expand All @@ -205,15 +206,11 @@ public function prepareRequest(Pipeline $pipeline)

private function formatParams(array $params)
{
foreach ($params as $key => $v) {
if (is_array($v)) {
if (empty($v)) {
$params[$key] = new \stdClass();
} else {
$params[$key] = $this->formatParams($params[$key]);
}
array_walk_recursive($params, function(&$v, $k) {
if (is_array($v) && count($v) === 0) {
$v = new \stdClass();
}
}
});

return $params;
}
Expand Down
24 changes: 24 additions & 0 deletions tests/Issues/Issue99Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace GraphAware\Neo4j\Client\Tests\Issues;

use GraphAware\Neo4j\Client\Tests\Integration\IntegrationTestCase;

/**
* Class Issue99Test
* @package GraphAware\Neo4j\Client\Tests\Issues
*
* @group issue-99
*/
class Issue99Test extends IntegrationTestCase
{
public function testEmptyArrayCanBePassedAsParameter()
{
$q = 'CREATE (n:Person) SET n += {props} RETURN id(n)';
$params = ['props' => ['id' => 123, 'some' => []]];

$result = $this->client->run($q, $params);

$this->assertEquals(1, $result->size());
}
}