DmsTableTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
c 1
b 0
f 0
dl 0
loc 88
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPhpNameData() 0 26 1
A testGetColumns() 0 3 1
A testGetName() 0 3 1
A setUp() 0 14 2
A testGetPhpName() 0 8 1
1
<?php declare(strict_types=1);
2
3
namespace Janisbiz\LightOrm\Tests\Unit\Dms\MySQL\Generator\Dms;
4
5
use Janisbiz\LightOrm\Dms\MySQL\Generator\Dms\DmsColumn;
6
use Janisbiz\LightOrm\Dms\MySQL\Generator\Dms\DmsTable;
7
use PHPUnit\Framework\TestCase;
8
9
class DmsTableTest extends TestCase
10
{
11
    const TABLE_NAME = 'table_name_snake_case';
12
13
    /**
14
     * @var DmsColumn[]
15
     */
16
    private $dmsColumns = [];
17
18
    /**
19
     * @var DmsTable
20
     */
21
    private $dmsTable;
22
23
    public function setUp()
24
    {
25
        for ($i = 1; $i <= 3; $i++) {
26
            $this->dmsColumns[] = new DmsColumn(
27
                \sprintf('%s_%d', DmsColumnTest::COLUMN_NAME, $i),
28
                DmsColumnTest::COLUMN_TYPE,
29
                DmsColumnTest::COLUMN_NULLABLE,
30
                DmsColumnTest::COLUMN_KEY,
31
                DmsColumnTest::COLUMN_DEFAULT,
32
                DmsColumnTest::COLUMN_EXTRA
33
            );
34
        }
35
36
        $this->dmsTable = new DmsTable(static::TABLE_NAME, $this->dmsColumns);
37
    }
38
39
    public function testGetName()
40
    {
41
        $this->assertEquals(static::TABLE_NAME, $this->dmsTable->getName());
42
    }
43
44
    /**
45
     * @dataProvider getPhpNameData
46
     *
47
     * @param string $name
48
     * @param string $phpName
49
     */
50
    public function testGetPhpName(string $name, string $phpName)
51
    {
52
        $dmsTable = new DmsTable(
53
            $name,
54
            $this->dmsColumns
55
        );
56
57
        $this->assertEquals($phpName, $dmsTable->getPhpName());
58
    }
59
60
    /**
61
     *
62
     * @return array
63
     */
64
    public function getPhpNameData()
65
    {
66
        return [
67
            [
68
                'name_snake_case',
69
                'NameSnakeCase',
70
            ],
71
            [
72
                'name__snake__case',
73
                'NameSnakeCase',
74
            ],
75
            [
76
                'name-snake-case',
77
                'NameSnakeCase',
78
            ],
79
            [
80
                'name1-snake2-case3',
81
                'Name1Snake2Case3',
82
            ],
83
            [
84
                '1name-2snake-3case',
85
                '1name2snake3case',
86
            ],
87
            [
88
                'name',
89
                'Name',
90
            ],
91
        ];
92
    }
93
94
    public function testGetColumns()
95
    {
96
        $this->assertEquals(\count($this->dmsColumns), \count($this->dmsTable->getDmsColumns()));
97
    }
98
}
99