Skip to content

Commit ace9725

Browse files
authored
Merge pull request #5 from ellgreen/laravel-6-support
Add support for Laravel 6 and 7
2 parents aa3cce0 + 1eb4fa3 commit ace9725

File tree

8 files changed

+61
-14
lines changed

8 files changed

+61
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ https://dev.mysql.com/doc/refman/8.0/en/insert-optimization.html
99

1010
## Installation
1111

12-
**Requires Laravel version > 8**
12+
**Requires Laravel 6 or above**
1313

1414
```bash
1515
composer require ellgreen/laravel-loadfile

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
},
2323
"require": {
2424
"php": "^7.4",
25-
"illuminate/database": "^8.28"
25+
"illuminate/database": "^6.0|^7.0|^8.0"
2626
},
2727
"require-dev": {
2828
"phpunit/phpunit": "^9",
29-
"orchestra/testbench": "^6.17",
29+
"orchestra/testbench": "^4.0|^5.0|^6.0",
3030
"squizlabs/php_codesniffer": "^3.6",
3131
"vimeo/psalm": "^4.7"
3232
},
@@ -35,15 +35,16 @@
3535
"test-unit-coverage": "php ./vendor/bin/phpunit tests/Unit --coverage-html .coverage/unit",
3636
"check": [
3737
"@docker-up",
38-
"@docker-test",
38+
"@docker-laravel-test",
3939
"@docker-cs",
4040
"@docker-static-analysis"
4141
],
4242
"docker-up": "docker compose up -d database",
4343
"docker-test": "docker compose run --rm app php ./vendor/bin/phpunit",
44+
"docker-laravel-test": "docker compose run --rm app php tests/laravel/laravel-version-test.php",
4445
"docker-test-coverage": "docker compose run --rm app php ./vendor/bin/phpunit --coverage-html .coverage/all",
45-
"docker-static-analysis": "docker compose run --rm app php ./vendor/bin/psalm",
46-
"docker-cs": "docker compose run --rm app php ./vendor/bin/phpcs --standard=PSR12 src/"
46+
"docker-cs": "docker compose run --rm app php ./vendor/bin/phpcs --standard=PSR12 src/",
47+
"docker-static-analysis": "docker compose run --rm app php ./vendor/bin/psalm"
4748
},
4849
"extra": {
4950
"laravel": {

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55
build: ./tests/docker
66
volumes:
77
- .:/app
8+
- $HOME/.composer/cache:/root/.composer/cache
89
working_dir: /app
910

1011
database:

src/Grammar.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public function compileLoadFile(Builder $query): CompiledQuery
2323
throw CompilationException::noFileOrTableSupplied();
2424
}
2525

26-
$querySegments->push(
26+
$querySegments->push([
2727
'load data' . ($query->isLocal() ? ' local' : ''),
2828
'infile ' . $this->quoteString($file),
29-
);
29+
]);
3030

3131
if ($query->isReplace()) {
3232
$querySegments->push('replace');
@@ -65,10 +65,13 @@ public function compileLoadFile(Builder $query): CompiledQuery
6565
$querySegments->push($this->compileSetColumns($set));
6666
/** @psalm-suppress MissingClosureParamType|InvalidArgument */
6767
$values = collect($set)->filter(fn($value) => ! $this->isExpression($value))->values();
68-
$bindings->push(...$values->toArray());
68+
$bindings->push($values->toArray());
6969
}
7070

71-
return new CompiledQuery($querySegments->filter()->implode(' '), $bindings->toArray());
71+
return new CompiledQuery(
72+
$querySegments->flatten()->filter()->implode(' '),
73+
$bindings->flatten()->toArray()
74+
);
7275
}
7376

7477
private function compileFields(

tests/docker/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
FROM php:7.4-cli
22

3+
RUN apt-get update && apt-get install -y rsync git zip unzip
4+
35
RUN docker-php-ext-install pdo pdo_mysql && \
46
pecl install pcov && \
57
docker-php-ext-enable pdo_mysql pcov
8+
9+
RUN curl -s https://getcomposer.org/installer | \
10+
php -- --install-dir=/usr/local/bin --filename=composer
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
const TEST_PATH = '/tmp/laravel/app/';
4+
5+
/** @var array $composerConfig */
6+
$composerConfig = json_decode(file_get_contents('/app/composer.json'), $assoc = true);
7+
8+
$laravelVersions = array_map(function ($version) {
9+
return trim($version, '^<>.0');
10+
}, explode('|', $composerConfig['require']['illuminate/database']));
11+
12+
foreach ($laravelVersions as $laravelVersion) {
13+
echo "Testing for Laravel {$laravelVersion}\n";
14+
15+
passthru(
16+
'rsync --delete -a --exclude=vendor/ --exclude=.*/ /app ' .
17+
dirname(TEST_PATH)
18+
);
19+
20+
chdir(TEST_PATH);
21+
22+
$composerConfig['require']['illuminate/database'] = "^{$laravelVersion}.0";
23+
$testBench = intval($laravelVersion) - 2;
24+
$composerConfig['require-dev']['orchestra/testbench'] = "^{$testBench}.0";
25+
26+
file_put_contents(TEST_PATH . 'composer.json', json_encode($composerConfig, JSON_PRETTY_PRINT));
27+
28+
exec('composer update -q');
29+
passthru('php ./vendor/bin/phpunit --colors=always', $resultCode);
30+
31+
if ($resultCode !== 0) {
32+
echo "\n\nTests failed for Laravel {$laravelVersion}\n";
33+
exit(1);
34+
}
35+
}

tests/migrations/2021_04_01_000000_create_people_table.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
use Illuminate\Support\Facades\DB;
66
use Illuminate\Support\Facades\Schema;
77

8-
return new class extends Migration
8+
class CreatePeopleTable extends Migration
99
{
1010
public function up(): void
1111
{
12+
Schema::dropIfExists('people');
13+
1214
Schema::create('people', function (Blueprint $table) {
13-
$table->id();
15+
$table->increments('id');
1416
$table->string('name');
1517
$table->date('dob');
1618
$table->string('greeting');
@@ -22,4 +24,4 @@ public function down(): void
2224
{
2325
Schema::drop('people');
2426
}
25-
};
27+
}

0 commit comments

Comments
 (0)