diff --git a/bin/doctrine-dbal b/bin/doctrine-dbal new file mode 120000 index 0000000..110e93c --- /dev/null +++ b/bin/doctrine-dbal @@ -0,0 +1 @@ +../vendor/doctrine/dbal/bin/doctrine-dbal \ No newline at end of file diff --git a/bin/phpunit b/bin/phpunit new file mode 120000 index 0000000..4ba3256 --- /dev/null +++ b/bin/phpunit @@ -0,0 +1 @@ +../vendor/phpunit/phpunit/phpunit \ No newline at end of file diff --git a/bin/yaml-lint b/bin/yaml-lint new file mode 120000 index 0000000..73c0353 --- /dev/null +++ b/bin/yaml-lint @@ -0,0 +1 @@ +../vendor/symfony/yaml/Resources/bin/yaml-lint \ No newline at end of file diff --git a/composer.json b/composer.json index ec8c265..dd64543 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,10 @@ ], "require": { "php": ">=7.1", - "doctrine/dbal": "^2.5", - "fzaninotto/faker": "^1.6", - "symfony/console": "^4.0", - "symfony/yaml": "^4.0" + "doctrine/dbal": "^2.5 | ^3.3", + "symfony/console": "^4.0 | ^5.0 | ^6.0", + "symfony/yaml": "^4.0 | ^5.0 | ^6.0", + "fakerphp/faker": "^1.12" }, "require-dev": { "phpunit/phpunit": "^6.0" diff --git a/src/Database/DBALConnection.php b/src/Database/DBALConnection.php index 0ba6c9b..f189dcd 100644 --- a/src/Database/DBALConnection.php +++ b/src/Database/DBALConnection.php @@ -18,14 +18,21 @@ public function __construct(DbConnection $connection) $this->connection = $connection; } - /** @throws \Doctrine\DBAL\DBALException */ + /** + * @param string $table + * @param Row $row + * @throws \Doctrine\DBAL\DBALException + */ public function insert(string $table, Row $row): void { $insert = Insert::into($table, $row); $this->connection->executeUpdate($insert->toSQL($this->connection), $insert->parameters()); - $row->assignId($this->connection->lastInsertId()); + try { + $id = $this->connection->lastInsertId(); + $row->assignId($id); + } catch (\Exception $e) {}; } /** diff --git a/src/Database/Insert.php b/src/Database/Insert.php index f136ac0..1538778 100644 --- a/src/Database/Insert.php +++ b/src/Database/Insert.php @@ -36,7 +36,9 @@ public function parameters(): array { $parameters = []; foreach ($this->row->values() as $value) { - if (is_numeric($value) || trim($value, '`') === $value) { + if(is_array($value)) { + $parameters[] = json_encode($value); + } elseif (is_numeric($value) || trim($value, '`') === $value) { $parameters[] = $value; } } diff --git a/src/Database/Row.php b/src/Database/Row.php index 658af3d..1b1795f 100644 --- a/src/Database/Row.php +++ b/src/Database/Row.php @@ -76,7 +76,7 @@ public function placeholders(): array { $placeholders = []; foreach ($this->values as $column => $value) { - if (is_numeric($value) || trim($value, '`') === $value) { + if (is_array($value) || is_numeric($value) || trim($value, '`') === $value) { $placeholders[$column] = '?'; } else { $placeholders[$column] = $value === null ? 'null' : trim($value, '`'); diff --git a/src/Processors/FakerProcessor.php b/src/Processors/FakerProcessor.php index 61dbbb9..71d58d1 100644 --- a/src/Processors/FakerProcessor.php +++ b/src/Processors/FakerProcessor.php @@ -30,8 +30,9 @@ public function beforeInsert(Row $row): void } } - private function generateFakeDataIfNeeded(Row $row, string $column, ?string $value): void + private function generateFakeDataIfNeeded(Row $row, string $column, $value): void { + if(!is_scalar($value)) return; $formatted = $value; while (FormatterCall::matches($formatted)) { $formatted = FormatterCall::from($formatted)->run($this->generator); diff --git a/src/Processors/ForeignKeyProcessor.php b/src/Processors/ForeignKeyProcessor.php index c0120e6..4a4f54b 100644 --- a/src/Processors/ForeignKeyProcessor.php +++ b/src/Processors/ForeignKeyProcessor.php @@ -59,8 +59,9 @@ public function addReference(Row $row) /** * @return mixed */ - private function parseKeyIfNeeded(string $value) + private function parseKeyIfNeeded($value) { + if (!is_scalar($value)) return $value; if ($this->isAReference($value) && $this->referenceExistsFor($value)) { return $this->references[substr($value, 1)]; }