Skip to content

Commit

Permalink
Refactor and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
imanghafoori1 committed Dec 13, 2022
1 parent 7830418 commit 7610883
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/FakeConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ protected function getDefaultQueryGrammar()

public function statement($query, $bindings = [])
{
if (is_string($query)) {
return parent::statement($query);
}

return $this->run($query['sql'], $bindings, function () use ($query) {
return (bool) FakeDB::insertGetId($query['value'], $query['builder']->from);
});
Expand All @@ -51,14 +55,14 @@ public function select($query, $bindings = [], $useReadPdo = true)

public function affectingStatement($query, $bindings = [])
{
if ('insertOrIgnore' === ($query['type'] ?? '')) {
$type = $query['type'];
if ('insertOrIgnore' === $type) {
$this->insert($query, $bindings);
$values = $query['value'];

return Arr::isAssoc($values) ? 1 : count($values);
return Arr::isAssoc($query['value']) ? 1 : count($query['value']);
}

if (in_array($query['type'] ?? '', ['update', 'delete'])) {
if (in_array($type, ['update', 'delete'])) {
return $this->run($query['sql'], $bindings, function () use ($query) {
return FakeDb::exec($query);
});
Expand All @@ -70,7 +74,5 @@ public function affectingStatement($query, $bindings = [])
$values = $query['values'];
$uniqueBy = $query['uniqueBy'];
}

parent::affectingStatement($query, $bindings);
}
}

0 comments on commit 7610883

Please sign in to comment.