Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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 src/Driver/Jsoner.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function toJson(mixed $value, bool $encode = true, bool $validate

$result = (string) $value;

if ($validate && !json_validate($result)) {
if ($validate && !\json_validate($result)) {
throw new BuilderException('Invalid JSON value.');
}

Expand Down
4 changes: 4 additions & 0 deletions src/Driver/MySQL/Schema/MySQLColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ public function compare(AbstractColumn $initial): bool
return $result && $this->size === $initial->size;
}

// if (! $result && $this->userType === 'boolean' && $this->size === 1 && $initial->size === 4) {
// return true; // Ignore size differences for boolean columns when matching defaults
// }

return $result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,76 @@
class BooleanColumnTest extends CommonClass
{
public const DRIVER = 'mysql';

public function testBooleanDefaultSize(): void
{
$schema = $this->schema('table');
$schema->boolean('column');
$schema->save();

$column = $this->fetchSchema($schema)->column('column');

$this->assertSame('boolean', $column->getAbstractType());
$this->assertSame(1, $column->getSize());
}

public function testBooleanComparisonWithSize(): void
{
$schema = $this->schema('table');
$foo = $schema->boolean('foo')->defaultValue(false)->nullable(false)->unsigned(true)->size(1)->zerofill(true);
$bar = $schema->boolean('bar', nullable: true, unsigned: true, size: 1, zerofill: true);
$baz = $schema->boolean('baz', nullable: false, unsigned: true);
$mux = $schema->boolean('mux', nullable: false);
$schema->save();

$schema = $this->schema('table');
$this->assertTrue($schema->exists());
$this->assertSame(1, $foo->getSize());
$this->assertSame(1, $bar->getSize());
$this->assertSame(1, $baz->getSize());
$this->assertSame(1, $mux->getSize());
$this->assertSame(1, $schema->column('foo')->getSize());
$this->assertSame(1, $schema->column('bar')->getSize());
$this->assertTrue(\in_array($schema->column('baz')->getSize(), [1, 4], true));
$this->assertSame(1, $schema->column('mux')->getSize());
$this->assertTrue($foo->compare($schema->column('foo')));
$this->assertTrue($bar->compare($schema->column('bar')));
$this->assertTrue($baz->compare($schema->column('baz')));
$this->assertTrue($mux->compare($schema->column('mux')));
}

public function testBooleanWithProblematicValues(): void
{
$schema = $this->schema('table');

$column = $schema->boolean('target')
->defaultValue(false)
->nullable(false)
->unsigned(true)
->comment('Target comment');

$schema->save();

$this->assertTrue($schema->exists());

$schema = $this->schema('table');
$target = $schema->column('target');

$this->assertSame(1, $column->getSize());
$this->assertSame(4, $target->getSize());
$this->assertFalse($column->isNullable());
$this->assertFalse($target->isNullable());
$this->assertTrue($column->isUnsigned());
$this->assertTrue($target->isUnsigned());

$object = new \ReflectionObject($target);
$property = $object->getProperty('defaultValue');
$property->setAccessible(true);
$defaultValue = $property->getValue($target);

$this->assertSame(false, $column->getDefaultValue());
$this->assertSame(0, $target->getDefaultValue());
$this->assertSame('0', $defaultValue);
$this->assertTrue($column->compare($target));
}
Comment on lines +55 to +88
Copy link
Contributor Author

@puzzledpolymath puzzledpolymath Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roxblnfk It took a while! But here is the test case which confirms the issue, under very specific conditions and attributes defined. Having a comment somehow contributes to the problem.

}
Loading