-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathColumnTest.php
More file actions
142 lines (108 loc) · 3.77 KB
/
ColumnTest.php
File metadata and controls
142 lines (108 loc) · 3.77 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
declare(strict_types=1);
namespace Cycle\Annotated\Tests\Unit\Attribute;
use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Tests\Unit\Attribute\SingleTable\StringEnum;
use PHPUnit\Framework\TestCase;
class ColumnTest extends TestCase
{
public const ENUM_VALUE_A = 'a';
public const ENUM_VALUE_B = 'b';
#[Column('integer', nullable: true, unsigned: true)]
private $column1;
#[Column('smallInt', unsigned: true, zerofill: true)]
private $column2;
#[Column('string(32)', size: 128)]
private $column3;
#[Column('string(32)', readonlySchema: true)]
private mixed $column4;
#[Column(type: 'enum(a,b)')]
private string $column5;
#[Column(
type: 'enum',
default: self::ENUM_VALUE_A,
values: [self::ENUM_VALUE_A, self::ENUM_VALUE_B],
)]
private string $column6 = self::ENUM_VALUE_A;
#[Column(
type: 'enum',
default: 'a',
typecast: StringEnum::class,
values: StringEnum::class,
)]
private StringEnum $column7 = StringEnum::A;
#[Column(
type: 'enum',
default: 'a',
values: [StringEnum::A, StringEnum::B],
)]
private string $column8 = 'a';
#[Column(type: 'string', length: 255, charset: 'ascii', collation: 'ascii_bin')]
private string $column9;
public function testOneAttribute(): void
{
$column = $this->getColumn('column1');
$this->assertSame(['unsigned' => true], $column->getAttributes());
}
public function testTwoAttributes(): void
{
$column = $this->getColumn('column2');
$this->assertSame(['unsigned' => true, 'zerofill' => true], $column->getAttributes());
}
public function testCustomSizeAttribute(): void
{
$column = $this->getColumn('column3');
$this->assertSame(['size' => 128], $column->getAttributes());
}
public function testDefaultReadonlySchema(): void
{
$column = $this->getColumn('column1');
$this->assertFalse($column->isReadonlySchema());
}
public function testReadonlySchema(): void
{
$column = $this->getColumn('column4');
$this->assertTrue($column->isReadonlySchema());
}
public function testEnumTypeString(): void
{
$column = $this->getColumn('column5');
$this->assertSame('enum(a,b)', $column->getType());
}
public function testEnumTypeArray(): void
{
$column = $this->getColumn('column6');
$this->assertSame('enum(a,b)', $column->getType());
$this->assertSame('a', $column->getDefault());
$this->assertArrayNotHasKey('values', $column->getAttributes());
}
public function testEnumTypeBackedEnum(): void
{
$column = $this->getColumn('column7');
$this->assertSame('enum(a,b)', $column->getType());
$this->assertSame('a', $column->getDefault());
$this->assertArrayNotHasKey('values', $column->getAttributes());
}
public function testEnumTypeArrayBackedEnum(): void
{
$column = $this->getColumn('column8');
$this->assertSame('enum(a,b)', $column->getType());
$this->assertSame('a', $column->getDefault());
$this->assertArrayNotHasKey('values', $column->getAttributes());
}
public function testCharsetAndCollationAttributes(): void
{
$column = $this->getColumn('column9');
$this->assertSame('string', $column->getType());
$this->assertSame([
'length' => 255,
'charset' => 'ascii',
'collation' => 'ascii_bin',
], $column->getAttributes());
}
private function getColumn(string $field): Column
{
$ref = new \ReflectionClass(static::class);
return $ref->getProperty($field)->getAttributes(Column::class)[0]->newInstance();
}
}