1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
* This file is part of FlexPHP. |
4
|
|
|
* |
5
|
|
|
* (c) Freddie Gar <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace FlexPHP\Database\Tests\Unit; |
11
|
|
|
|
12
|
|
|
use FlexPHP\Database\Column; |
13
|
|
|
use FlexPHP\Database\Table; |
14
|
|
|
use FlexPHP\Database\Tests\TestCase; |
15
|
|
|
use FlexPHP\Schema\Constants\Keyword; |
16
|
|
|
use FlexPHP\Schema\Schema; |
17
|
|
|
use FlexPHP\Schema\SchemaAttribute; |
18
|
|
|
|
19
|
|
|
class TableTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
public function testItDefinition(): void |
22
|
|
|
{ |
23
|
|
|
$attribute1 = [ |
24
|
|
|
Keyword::NAME => 'foo', |
25
|
|
|
Keyword::DATATYPE => 'string', |
26
|
|
|
Keyword::CONSTRAINTS => [ |
27
|
|
|
'minlength' => 10, |
28
|
|
|
'maxlength' => 100, |
29
|
|
|
], |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
$attribute2 = [ |
33
|
|
|
Keyword::NAME => 'baz', |
34
|
|
|
Keyword::DATATYPE => 'integer', |
35
|
|
|
Keyword::CONSTRAINTS => [ |
36
|
|
|
'min' => 10, |
37
|
|
|
'max' => 100, |
38
|
|
|
], |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
$schemaAttribute1 = new SchemaAttribute('foo', 'string', $attribute1[Keyword::CONSTRAINTS]); |
42
|
|
|
$schemaAttribute2 = new SchemaAttribute('baz', 'integer', $attribute2[Keyword::CONSTRAINTS]); |
43
|
|
|
|
44
|
|
|
$column1 = new Column($schemaAttribute1); |
45
|
|
|
$column2 = new Column($schemaAttribute2); |
46
|
|
|
|
47
|
|
|
$schema = new Schema('bar', 'title', [$attribute1, $attribute2]); |
48
|
|
|
|
49
|
|
|
$table = new Table($schema); |
50
|
|
|
|
51
|
|
|
$this->assertEquals($schema->name(), $table->getName()); |
52
|
|
|
$this->assertEquals([$column1, $column2], $table->getColumns()); |
53
|
|
|
$this->assertEquals([ |
54
|
|
|
'charset' => 'utf8mb4', |
55
|
|
|
'collate' => 'utf8mb4_unicode_ci', |
56
|
|
|
], $table->getOptions()); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|