diff --git a/composer.json b/composer.json index 47c7066..9788cd9 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "license": "MIT", "require": { "php": ">=8.1", - "cycle/database": "^2.2", + "cycle/database": "^2.3", "spiral/core": "^3.0", "spiral/files": "^3.0", "spiral/tokenizer": "^3.0", diff --git a/src/Operation/Column/Column.php b/src/Operation/Column/Column.php index c5045da..dd9dd6f 100644 --- a/src/Operation/Column/Column.php +++ b/src/Operation/Column/Column.php @@ -43,21 +43,27 @@ protected function declareColumn(AbstractTable $schema): AbstractColumn //Type configuring if (method_exists($column, $this->type)) { $arguments = []; + $variadic = false; $method = new \ReflectionMethod($column, $this->type); foreach ($method->getParameters() as $parameter) { if ($this->hasOption($parameter->getName())) { - $arguments[] = $this->getOption($parameter->getName()); + $arguments[$parameter->getName()] = $this->getOption($parameter->getName()); } elseif (!$parameter->isOptional()) { throw new ColumnException( "Option '{$parameter->getName()}' are required to define column with type '{$this->type}'" ); - } else { - $arguments[] = $parameter->getDefaultValue(); + } elseif ($parameter->isDefaultValueAvailable()) { + $arguments[$parameter->getName()] = $parameter->getDefaultValue(); + } elseif ($parameter->isVariadic()) { + $variadic = true; } } - call_user_func_array([$column, $this->type], $arguments); + \call_user_func_array( + [$column, $this->type], + $variadic ? $arguments + $this->options + $column->getAttributes() : $arguments, + ); } else { $column->type($this->type); } diff --git a/tests/Migrations/AtomizerTest.php b/tests/Migrations/AtomizerTest.php index f6d41e4..128c3a7 100644 --- a/tests/Migrations/AtomizerTest.php +++ b/tests/Migrations/AtomizerTest.php @@ -310,7 +310,7 @@ public function testCreateDatetimeNowColumn(): void $this->migrator->configure(); $schema = $this->schema('sample'); - $column = $schema->datetime('value'); + $column = $schema->datetime('value', size: 2, foo: 'bar'); $column->defaultValue(new Fragment($column::DATETIME_NOW)); $this->atomize('migration1', [$schema]); @@ -318,7 +318,10 @@ public function testCreateDatetimeNowColumn(): void $this->migrator->run(); $this->assertTrue($this->db->hasTable('sample')); - $this->assertSame((string)$column->getDefaultValue(), (string)$this->schema('sample')->column('value')->getDefaultValue()); + $this->assertSame( + (string)$column->getDefaultValue(), + (string)$this->schema('sample')->column('value')->getDefaultValue() + ); $this->migrator->rollback(); $this->assertFalse($this->db->hasTable('sample'));