Skip to content

Commit

Permalink
Fixed empty arrays being seen as associative instead of numeric/list-…
Browse files Browse the repository at this point in the history
…arrays as is the json_encode standard.
  • Loading branch information
LaravelFreelancerNL committed Apr 9, 2022
1 parent 132c359 commit 0f1d729
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Traits/ValidatesExpressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function isBindParameter(string $bindParameter): bool
public function isAssociativeArray(array $array): bool
{
if (empty($array)) {
return true;
return false;
}

return !ctype_digit(implode('', array_keys($array)));
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/AQL/QueryClausesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public function testForClauseInExpression()
)
)
->get();
self::assertEquals('LET x = [1,2,3,4] FOR u IN (1 > 0) ? x : {}', $aqb->query);

self::assertEquals('LET x = [1,2,3,4] FOR u IN (1 > 0) ? x : []', $aqb->query);
}

public function testFilterClause()
Expand Down
15 changes: 9 additions & 6 deletions tests/Unit/AQL/StatementClausesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@ public function testInsertStatement()

public function testInsertEmptyArrayStatement()
{
$result = (new QueryBuilder())->insert('{
"traits": []
}', 'Characters')->get();
$characterData = [
"tags" => []
];

$result = (new QueryBuilder())->insert($characterData, 'Characters')->get();

self::assertEquals('{
"traits": []
}', $result->binds[$result->getQueryId() . '_1']);
self::assertEquals(
'INSERT {"tags":[]} IN Characters',
$result->query
);
}


Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/GrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public function testIsAssociativeArray()
];

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

$result = $this->grammar->isAssociativeArray($associativeArray);
self::assertTrue($result);
Expand Down

0 comments on commit 0f1d729

Please sign in to comment.