|
14 | 14 | class BooleanColumnTest extends CommonClass |
15 | 15 | { |
16 | 16 | public const DRIVER = 'mysql'; |
| 17 | + |
| 18 | + public function testBooleanDefaultSize(): void |
| 19 | + { |
| 20 | + $schema = $this->schema('table'); |
| 21 | + $schema->boolean('column'); |
| 22 | + $schema->save(); |
| 23 | + |
| 24 | + $column = $this->fetchSchema($schema)->column('column'); |
| 25 | + |
| 26 | + $this->assertSame('boolean', $column->getAbstractType()); |
| 27 | + $this->assertSame(1, $column->getSize()); |
| 28 | + } |
| 29 | + |
| 30 | + public function testBooleanComparisonWithSize(): void |
| 31 | + { |
| 32 | + $schema = $this->schema('table'); |
| 33 | + $foo = $schema->boolean('foo')->defaultValue(false)->nullable(false)->unsigned(true)->size(1)->zerofill(true); |
| 34 | + $bar = $schema->boolean('bar', nullable: true, unsigned: true, size: 1, zerofill: true); |
| 35 | + $baz = $schema->boolean('baz', nullable: false, unsigned: true); |
| 36 | + $mux = $schema->boolean('mux', nullable: false); |
| 37 | + $schema->save(); |
| 38 | + |
| 39 | + $schema = $this->schema('table'); |
| 40 | + $this->assertTrue($schema->exists()); |
| 41 | + $this->assertSame(1, $foo->getSize()); |
| 42 | + $this->assertSame(1, $bar->getSize()); |
| 43 | + $this->assertSame(1, $baz->getSize()); |
| 44 | + $this->assertSame(1, $mux->getSize()); |
| 45 | + $this->assertSame(1, $schema->column('foo')->getSize()); |
| 46 | + $this->assertSame(1, $schema->column('bar')->getSize()); |
| 47 | + $this->assertTrue(\in_array($schema->column('baz')->getSize(), [1, 4], true)); |
| 48 | + $this->assertSame(1, $schema->column('mux')->getSize()); |
| 49 | + $this->assertTrue($foo->compare($schema->column('foo'))); |
| 50 | + $this->assertTrue($bar->compare($schema->column('bar'))); |
| 51 | + $this->assertTrue($baz->compare($schema->column('baz'))); |
| 52 | + $this->assertTrue($mux->compare($schema->column('mux'))); |
| 53 | + } |
| 54 | + |
| 55 | + public function testBooleanWithProblematicValues(): void |
| 56 | + { |
| 57 | + $schema = $this->schema('table'); |
| 58 | + |
| 59 | + $column = $schema->boolean('target') |
| 60 | + ->defaultValue(false) |
| 61 | + ->nullable(false) |
| 62 | + ->unsigned(true) |
| 63 | + ->comment('Target comment'); |
| 64 | + |
| 65 | + $schema->save(); |
| 66 | + |
| 67 | + $this->assertTrue($schema->exists()); |
| 68 | + |
| 69 | + $schema = $this->schema('table'); |
| 70 | + $target = $schema->column('target'); |
| 71 | + |
| 72 | + $this->assertSame(1, $column->getSize()); |
| 73 | + $this->assertSame(4, $target->getSize()); |
| 74 | + $this->assertFalse($column->isNullable()); |
| 75 | + $this->assertFalse($target->isNullable()); |
| 76 | + $this->assertTrue($column->isUnsigned()); |
| 77 | + $this->assertTrue($target->isUnsigned()); |
| 78 | + |
| 79 | + $object = new \ReflectionObject($target); |
| 80 | + $property = $object->getProperty('defaultValue'); |
| 81 | + $property->setAccessible(true); |
| 82 | + $defaultValue = $property->getValue($target); |
| 83 | + |
| 84 | + $this->assertSame(false, $column->getDefaultValue()); |
| 85 | + $this->assertSame(0, $target->getDefaultValue()); |
| 86 | + $this->assertSame('0', $defaultValue); |
| 87 | + $this->assertTrue($column->compare($target)); |
| 88 | + $this->assertTrue($target->compare($column)); |
| 89 | + // The size was not changed |
| 90 | + $this->assertSame(4, $target->getSize()); |
| 91 | + } |
17 | 92 | } |
0 commit comments