Skip to content

Commit d8c44c4

Browse files
committed
fix: modify replaceBindings logic to fit current laravel implementation.
1 parent b7792f6 commit d8c44c4

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

.travis.yml

+33-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,47 @@
11
language: php
2+
23
php:
34
- 7.2
45
- 7.3
56
- 7.4
67
- 8.0
78
- 8.1
89

9-
# Commands to be run before your environment runs.
10-
before_script:
10+
laravel:
11+
- 10.*
12+
- 9.*
13+
- 8.*
14+
- 7.*
15+
- 6.*
16+
- 5.*
17+
18+
jobs:
19+
exclude:
20+
# Unsupported combinations
21+
- { laravel: 5.*, php: 8.0 }
22+
- { laravel: 5.*, php: 8.1 }
23+
- { laravel: 6.*, php: 8.1 }
24+
- { laravel: 7.*, php: 8.1 }
25+
- { laravel: 8.*, php: 7.2 }
26+
- { laravel: 9.*, php: 7.2 }
27+
- { laravel: 9.*, php: 7.3 }
28+
- { laravel: 9.*, php: 7.4 }
29+
- { laravel: 10.*, php: 7.2 }
30+
- { laravel: 10.*, php: 7.3 }
31+
- { laravel: 10.*, php: 7.4 }
32+
- { laravel: 10.*, php: 8.0 }
33+
34+
before_install:
1135
- composer self-update
1236
- rm composer.lock
13-
- composer install --no-interaction
37+
38+
install:
39+
- travis_retry composer require --dev "laravel/framework:${laravel}" --no-interaction
40+
- travis_retry composer install --no-interaction
1441

1542
script:
16-
- mkdir -p build/logs
17-
- php vendor/bin/phpunit --coverage-clover build/logs/clover.xml
43+
- mkdir -p build/logs
44+
- php vendor/bin/phpunit --coverage-clover build/logs/clover.xml
1845

1946
after_script:
20-
- php vendor/bin/php-coveralls -v
47+
- php vendor/bin/php-coveralls -v

src/Objects/Concerns/ReplacesBindings.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected function replaceBindings($sql, array $bindings)
1919
$generalRegex = $this->getRegex();
2020

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

@@ -43,7 +43,7 @@ protected function value($value)
4343
return (int) $value;
4444
}
4545

46-
return is_numeric($value) ? $value : "'" . $value . "'";
46+
return is_int($value) ? $value : "'" . $value . "'";
4747
}
4848

4949
/**

tests/Objects/SqlQueryTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function it_returns_valid_query_with_replaced_bindings()
5353

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

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

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

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

0 commit comments

Comments
 (0)