-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathTableTest.php
More file actions
77 lines (60 loc) · 2.73 KB
/
TableTest.php
File metadata and controls
77 lines (60 loc) · 2.73 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
<?php
declare(strict_types=1);
namespace Cycle\Annotated\Tests\Functional\Driver\MySQL;
// phpcs:ignore
use Cycle\Annotated\Entities;
use Cycle\Annotated\Locator\TokenizerEntityLocator;
use Cycle\Annotated\MergeColumns;
use Cycle\Annotated\Tests\Functional\Driver\Common\TableTestCase;
use Cycle\Schema\Generator\RenderTables;
use Cycle\Schema\Generator\SyncTables;
use Cycle\Schema\Registry;
use PHPUnit\Framework\Attributes\Group;
use Spiral\Attributes\AttributeReader;
#[Group('driver')]
#[Group('driver-mysql')]
final class TableTest extends TableTestCase
{
public const DRIVER = 'mysql';
public function testUnsigned(): void
{
$reader = new AttributeReader();
$r = new Registry($this->dbal);
(new Entities(new TokenizerEntityLocator($this->locator, $reader), $reader))->run($r);
(new MergeColumns($reader))->run($r);
(new RenderTables())->run($r);
$schema = $r->getTableSchema($r->getEntity('label'));
$this->assertTrue($schema->column('unsigned')->isUnsigned());
$this->assertFalse($schema->column('simple')->isUnsigned());
$schema->save();
$this->assertTrue($this->dbal->database()->table('labels')->getSchema()->column('unsigned')->isUnsigned());
$this->assertFalse($this->dbal->database()->table('labels')->getSchema()->column('simple')->isUnsigned());
}
public function testZerofill(): void
{
$reader = new AttributeReader();
$r = new Registry($this->dbal);
(new Entities(new TokenizerEntityLocator($this->locator, $reader), $reader))->run($r);
(new MergeColumns($reader))->run($r);
(new RenderTables())->run($r);
$schema = $r->getTableSchema($r->getEntity('label'));
$this->assertTrue($schema->column('zerofill')->isZerofill());
$this->assertFalse($schema->column('simple')->isZerofill());
$schema->save();
$this->assertTrue($this->dbal->database()->table('labels')->getSchema()->column('zerofill')->isUnsigned());
$this->assertFalse($this->dbal->database()->table('labels')->getSchema()->column('simple')->isUnsigned());
}
public function testColumnCustomAttributes(): void
{
$reader = new AttributeReader();
$r = new Registry($this->dbal);
(new Entities(new TokenizerEntityLocator($this->locator, $reader), $reader))->run($r);
(new MergeColumns($reader))->run($r);
(new RenderTables())->run($r);
(new SyncTables())->run($r);
$dbSchema = $this->dbal->database()->table('labels')->getSchema();
$attributes = $dbSchema->column('charset_column')->getAttributes();
$this->assertSame('ascii', $attributes['charset']);
$this->assertSame('ascii_bin', $attributes['collation']);
}
}