Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ https://dev.mysql.com/doc/refman/8.0/en/insert-optimization.html

## Installation

**Requires Laravel version > 8**
**Requires Laravel 6 or above**

```bash
composer require ellgreen/laravel-loadfile
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
},
"require": {
"php": "^7.4",
"illuminate/database": "^8.28"
"illuminate/database": "^6.0|^7.0|^8.0"
},
"require-dev": {
"phpunit/phpunit": "^9",
"orchestra/testbench": "^6.17",
"orchestra/testbench": "^4.0|^5.0|^6.0",
"squizlabs/php_codesniffer": "^3.6",
"vimeo/psalm": "^4.7"
},
Expand All @@ -35,15 +35,16 @@
"test-unit-coverage": "php ./vendor/bin/phpunit tests/Unit --coverage-html .coverage/unit",
"check": [
"@docker-up",
"@docker-test",
"@docker-laravel-test",
"@docker-cs",
"@docker-static-analysis"
],
"docker-up": "docker compose up -d database",
"docker-test": "docker compose run --rm app php ./vendor/bin/phpunit",
"docker-laravel-test": "docker compose run --rm app php tests/laravel/laravel-version-test.php",
"docker-test-coverage": "docker compose run --rm app php ./vendor/bin/phpunit --coverage-html .coverage/all",
"docker-static-analysis": "docker compose run --rm app php ./vendor/bin/psalm",
"docker-cs": "docker compose run --rm app php ./vendor/bin/phpcs --standard=PSR12 src/"
"docker-cs": "docker compose run --rm app php ./vendor/bin/phpcs --standard=PSR12 src/",
"docker-static-analysis": "docker compose run --rm app php ./vendor/bin/psalm"
},
"extra": {
"laravel": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
build: ./tests/docker
volumes:
- .:/app
- $HOME/.composer/cache:/root/.composer/cache
working_dir: /app

database:
Expand Down
11 changes: 7 additions & 4 deletions src/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public function compileLoadFile(Builder $query): CompiledQuery
throw CompilationException::noFileOrTableSupplied();
}

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

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

return new CompiledQuery($querySegments->filter()->implode(' '), $bindings->toArray());
return new CompiledQuery(
$querySegments->flatten()->filter()->implode(' '),
$bindings->flatten()->toArray()
);
}

private function compileFields(
Expand Down
5 changes: 5 additions & 0 deletions tests/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
FROM php:7.4-cli

RUN apt-get update && apt-get install -y rsync git zip unzip

RUN docker-php-ext-install pdo pdo_mysql && \
pecl install pcov && \
docker-php-ext-enable pdo_mysql pcov

RUN curl -s https://getcomposer.org/installer | \
php -- --install-dir=/usr/local/bin --filename=composer
35 changes: 35 additions & 0 deletions tests/laravel/laravel-version-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

const TEST_PATH = '/tmp/laravel/app/';

/** @var array $composerConfig */
$composerConfig = json_decode(file_get_contents('/app/composer.json'), $assoc = true);

$laravelVersions = array_map(function ($version) {
return trim($version, '^<>.0');
}, explode('|', $composerConfig['require']['illuminate/database']));

foreach ($laravelVersions as $laravelVersion) {
echo "Testing for Laravel {$laravelVersion}\n";

passthru(
'rsync --delete -a --exclude=vendor/ --exclude=.*/ /app ' .
dirname(TEST_PATH)
);

chdir(TEST_PATH);

$composerConfig['require']['illuminate/database'] = "^{$laravelVersion}.0";
$testBench = intval($laravelVersion) - 2;
$composerConfig['require-dev']['orchestra/testbench'] = "^{$testBench}.0";

file_put_contents(TEST_PATH . 'composer.json', json_encode($composerConfig, JSON_PRETTY_PRINT));

exec('composer update -q');
passthru('php ./vendor/bin/phpunit --colors=always', $resultCode);

if ($resultCode !== 0) {
echo "\n\nTests failed for Laravel {$laravelVersion}\n";
exit(1);
}
}
8 changes: 5 additions & 3 deletions tests/migrations/2021_04_01_000000_create_people_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
class CreatePeopleTable extends Migration
{
public function up(): void
{
Schema::dropIfExists('people');

Schema::create('people', function (Blueprint $table) {
$table->id();
$table->increments('id');
$table->string('name');
$table->date('dob');
$table->string('greeting');
Expand All @@ -22,4 +24,4 @@ public function down(): void
{
Schema::drop('people');
}
};
}