diff --git a/src/Driver/MySQL/Schema/MySQLColumn.php b/src/Driver/MySQL/Schema/MySQLColumn.php index 6e34add4..c8cf6464 100644 --- a/src/Driver/MySQL/Schema/MySQLColumn.php +++ b/src/Driver/MySQL/Schema/MySQLColumn.php @@ -23,17 +23,17 @@ * Attention! You can use only one timestamp or datetime with DATETIME_NOW setting! Thought, it will * work on multiple fields with MySQL 5.6.6+ version. * - * @method $this|AbstractColumn primary(int $size, bool $unsigned = false, $zerofill = false) - * @method $this|AbstractColumn smallPrimary(int $size, bool $unsigned = false, $zerofill = false) - * @method $this|AbstractColumn bigPrimary(int $size, bool $unsigned = false, $zerofill = false) - * @method $this|AbstractColumn integer(int $size, bool $unsigned = false, $zerofill = false) - * @method $this|AbstractColumn tinyInteger(int $size, bool $unsigned = false, $zerofill = false) - * @method $this|AbstractColumn smallInteger(int $size, bool $unsigned = false, $zerofill = false) - * @method $this|AbstractColumn bigInteger(int $size, bool $unsigned = false, $zerofill = false) - * @method $this|AbstractColumn unsigned(bool $value) - * @method $this|AbstractColumn zerofill(bool $value) - * @method $this|AbstractColumn comment(string $value) - * @method $this|AbstractColumn after(string $column) + * @method $this primary(int $size, bool $unsigned = false, $zerofill = false) + * @method $this smallPrimary(int $size, bool $unsigned = false, $zerofill = false) + * @method $this bigPrimary(int $size, bool $unsigned = false, $zerofill = false) + * @method $this integer(int $size, bool $unsigned = false, $zerofill = false) + * @method $this tinyInteger(int $size, bool $unsigned = false, $zerofill = false) + * @method $this smallInteger(int $size, bool $unsigned = false, $zerofill = false) + * @method $this bigInteger(int $size, bool $unsigned = false, $zerofill = false) + * @method $this unsigned(bool $value) + * @method $this zerofill(bool $value) + * @method $this comment(string $value) + * @method $this after(string $column) */ class MySQLColumn extends AbstractColumn { diff --git a/tests/Database/Functional/Driver/MySQL/Connection/CustomOptionsTest.php b/tests/Database/Functional/Driver/MySQL/Connection/CustomOptionsTest.php index 0225ae43..a775df82 100644 --- a/tests/Database/Functional/Driver/MySQL/Connection/CustomOptionsTest.php +++ b/tests/Database/Functional/Driver/MySQL/Connection/CustomOptionsTest.php @@ -94,6 +94,45 @@ public function testNamedArgumentsToConfigureInteger(): void $this->assertTrue($foo->isNullable()); } + public function testNamedArgumentsToConfigureBoolean(): void + { + $schema = $this->schema('foo'); + $schema->boolean('bar')->defaultValue(false)->nullable(false)->unsigned(true)->size(1)->zerofill(true); + $schema->boolean('baz', nullable: true, unsigned: true, size: 1, zerofill: true); + $schema->boolean('qux', nullable: false, unsigned: true); + $schema->boolean('quux', nullable: false); + $schema->save(); + + $this->assertInstanceOf(MySQLColumn::class, $bar = $this->fetchSchema($schema)->column('bar')); + $this->assertInstanceOf(MySQLColumn::class, $baz = $this->fetchSchema($schema)->column('baz')); + $this->assertInstanceOf(MySQLColumn::class, $qux = $this->fetchSchema($schema)->column('qux')); + $this->assertInstanceOf(MySQLColumn::class, $quux = $this->fetchSchema($schema)->column('quux')); + + self::assertInstanceOf(MySQLColumn::class, $bar); + self::assertInstanceOf(MySQLColumn::class, $baz); + self::assertInstanceOf(MySQLColumn::class, $qux); + self::assertInstanceOf(MySQLColumn::class, $quux); + $this->assertTrue($bar->isZerofill()); + $this->assertTrue($baz->isZerofill()); + $this->assertFalse($qux->isZerofill()); + $this->assertFalse($quux->isZerofill()); + $this->assertTrue($bar->isUnsigned()); + $this->assertTrue($baz->isUnsigned()); + $this->assertTrue($qux->isUnsigned()); + $this->assertFalse($quux->isUnsigned()); + + $this->assertSame(1, $bar->getSize()); + $this->assertSame(1, $baz->getSize()); + // In case of zerofill=false and unsigned=true the size value might be resolved to 4 + $this->assertTrue(\in_array($qux->getSize(), [1, 4], true)); + $this->assertSame(1, $quux->getSize()); + + $this->assertFalse($bar->isNullable()); + $this->assertTrue($baz->isNullable()); + $this->assertFalse($qux->isNullable()); + $this->assertFalse($quux->isNullable()); + } + /** * The `text` have no the `unsigned` attribute. It will be stored in the additional attributes. */