Completed
Push — develop ( 4c851b...fa6865 )
by Freddie
03:54
created

TableTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 25
dl 0
loc 38
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testItDefinition() 0 36 1
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;
11
12
use FlexPHP\Database\Column;
13
use FlexPHP\Database\Table;
14
use FlexPHP\Schema\Constants\Keyword;
15
use FlexPHP\Schema\Schema;
16
use FlexPHP\Schema\SchemaAttribute;
17
18
class TableTest extends TestCase
19
{
20
    public function testItDefinition(): void
21
    {
22
        $attribute1 = [
23
            Keyword::NAME => 'foo',
24
            Keyword::DATATYPE => 'string',
25
            Keyword::CONSTRAINTS => [
26
                'minlength' => 10,
27
                'maxlength' => 100,
28
            ],
29
        ];
30
31
        $attribute2 = [
32
            Keyword::NAME => 'baz',
33
            Keyword::DATATYPE => 'integer',
34
            Keyword::CONSTRAINTS => [
35
                'min' => 10,
36
                'max' => 100,
37
            ],
38
        ];
39
40
        $schemaAttribute1 = new SchemaAttribute('foo', 'string', $attribute1[Keyword::CONSTRAINTS]);
41
        $schemaAttribute2 = new SchemaAttribute('baz', 'integer', $attribute2[Keyword::CONSTRAINTS]);
42
43
        $column1 = new Column($schemaAttribute1);
44
        $column2 = new Column($schemaAttribute2);
45
46
        $schema = new Schema('bar', 'title', [$attribute1, $attribute2]);
47
48
        $table = new Table($schema);
49
50
        $this->assertEquals($schema->name(), $table->getName());
51
        $this->assertEquals([$column1, $column2], $table->getColumns());
52
        $this->assertEquals([
53
            'charset' => 'utf8mb4',
54
            'collate' => 'utf8mb4_unicode_ci',
55
        ], $table->getOptions());
56
    }
57
}
58