-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathBooleanColumnTest.php
More file actions
92 lines (75 loc) · 3.24 KB
/
BooleanColumnTest.php
File metadata and controls
92 lines (75 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
declare(strict_types=1);
namespace Cycle\Database\Tests\Functional\Driver\MySQL\Schema;
// phpcs:ignore
use Cycle\Database\Tests\Functional\Driver\Common\Schema\BooleanColumnTest as CommonClass;
/**
* @group driver
* @group driver-mysql
*/
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));
$this->assertTrue($target->compare($column));
// The size was not changed
$this->assertSame(4, $target->getSize());
}
}