Skip to content

Commit 0f1d729

Browse files
Fixed empty arrays being seen as associative instead of numeric/list-arrays as is the json_encode standard.
1 parent 132c359 commit 0f1d729

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/Traits/ValidatesExpressions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function isBindParameter(string $bindParameter): bool
165165
public function isAssociativeArray(array $array): bool
166166
{
167167
if (empty($array)) {
168-
return true;
168+
return false;
169169
}
170170

171171
return !ctype_digit(implode('', array_keys($array)));

tests/Unit/AQL/QueryClausesTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public function testForClauseInExpression()
7474
)
7575
)
7676
->get();
77-
self::assertEquals('LET x = [1,2,3,4] FOR u IN (1 > 0) ? x : {}', $aqb->query);
77+
78+
self::assertEquals('LET x = [1,2,3,4] FOR u IN (1 > 0) ? x : []', $aqb->query);
7879
}
7980

8081
public function testFilterClause()

tests/Unit/AQL/StatementClausesTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ public function testInsertStatement()
7878

7979
public function testInsertEmptyArrayStatement()
8080
{
81-
$result = (new QueryBuilder())->insert('{
82-
"traits": []
83-
}', 'Characters')->get();
81+
$characterData = [
82+
"tags" => []
83+
];
84+
85+
$result = (new QueryBuilder())->insert($characterData, 'Characters')->get();
8486

85-
self::assertEquals('{
86-
"traits": []
87-
}', $result->binds[$result->getQueryId() . '_1']);
87+
self::assertEquals(
88+
'INSERT {"tags":[]} IN Characters',
89+
$result->query
90+
);
8891
}
8992

9093

tests/Unit/GrammarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public function testIsAssociativeArray()
405405
];
406406

407407
$result = $this->grammar->isAssociativeArray($emptyArray);
408-
self::assertTrue($result);
408+
self::assertFalse($result);
409409

410410
$result = $this->grammar->isAssociativeArray($associativeArray);
411411
self::assertTrue($result);

0 commit comments

Comments
 (0)