Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: modify replaceBindings logic to fit current laravel implementation. #35

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
4 changes: 2 additions & 2 deletions src/Objects/Concerns/ReplacesBindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function replaceBindings($sql, array $bindings)
$generalRegex = $this->getRegex();

foreach ($this->formatBindings($bindings) as $key => $binding) {
$regex = is_numeric($key) ? $generalRegex : $this->getNamedParameterRegex($key);
$regex = is_int($key) ? $generalRegex : $this->getNamedParameterRegex($key);
$sql = preg_replace($regex, $this->value($binding), $sql, 1);
}

Expand All @@ -43,7 +43,7 @@ protected function value($value)
return (int) $value;
}

return is_numeric($value) ? $value : "'" . $value . "'";
return is_int($value) ? $value : "'" . $value . "'";
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Objects/SqlQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function it_returns_valid_query_with_replaced_bindings()

$expectedSql = <<<EOF
SELECT * FROM tests WHERE a = '\'test' AND CONCAT('{$bindings[1]->toDateTimeString()}', '%'
, '{$bindings[2]->format('Y-m-d H:i:s')}') = 453 AND column = 67.23
, '{$bindings[2]->format('Y-m-d H:i:s')}') = 453 AND column = '67.23'
EOF;

$this->assertSame($expectedSql, $query->get());
Expand All @@ -72,7 +72,7 @@ public function it_returns_valid_query_with_replaced_bindings_for_immutable_date

$expectedSql = <<<EOF
SELECT * FROM tests WHERE a = '\'test' AND CONCAT('{$bindings[1]->toDateTimeString()}', '%'
, '{$bindings[2]->format('Y-m-d H:i:s')}') = 453 AND column = 67.23
, '{$bindings[2]->format('Y-m-d H:i:s')}') = 453 AND column = '67.23'
EOF;

$this->assertSame($expectedSql, $query->get());
Expand Down