|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace PhpMyAdmin\Tests\Table; |
| 6 | + |
| 7 | +use PhpMyAdmin\Table\ColumnsDefinition; |
| 8 | +use PhpMyAdmin\Tests\AbstractTestCase; |
| 9 | + |
| 10 | +/** |
| 11 | + * @covers \PhpMyAdmin\Table\ColumnsDefinition |
| 12 | + */ |
| 13 | +class ColumnsDefinitionTest extends AbstractTestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * test for ColumnsDefinition::decorateColumnMetaDefault |
| 17 | + * |
| 18 | + * @param array $columnMeta column metadata |
| 19 | + * @param array $expected expected result |
| 20 | + * @phpstan-param array<string, string|null> $columnMeta |
| 21 | + * @phpstan-param array<string, string> $expected |
| 22 | + * |
| 23 | + * @dataProvider providerColumnMetaDefault |
| 24 | + */ |
| 25 | + public function testDecorateColumnMetaDefault(array $columnMeta, array $expected): void |
| 26 | + { |
| 27 | + $result = ColumnsDefinition::decorateColumnMetaDefault($columnMeta); |
| 28 | + |
| 29 | + $this->assertEquals($expected, $result); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Data provider for testDecorateColumnMetaDefault |
| 34 | + * |
| 35 | + * @return array |
| 36 | + * @psalm-return array<string, array{array<string, string|null>, array<string, string>}> |
| 37 | + */ |
| 38 | + public function providerColumnMetaDefault(): array |
| 39 | + { |
| 40 | + return [ |
| 41 | + 'when Default is null and Null is YES' => [ |
| 42 | + [ |
| 43 | + 'Default' => null, |
| 44 | + 'Null' => 'YES', |
| 45 | + ], |
| 46 | + [ |
| 47 | + 'DefaultType' => 'NULL', |
| 48 | + 'DefaultValue' => '', |
| 49 | + ], |
| 50 | + ], |
| 51 | + 'when Default is null and Null is NO' => [ |
| 52 | + [ |
| 53 | + 'Default' => null, |
| 54 | + 'Null' => 'NO', |
| 55 | + ], |
| 56 | + [ |
| 57 | + 'DefaultType' => 'NONE', |
| 58 | + 'DefaultValue' => '', |
| 59 | + ], |
| 60 | + ], |
| 61 | + 'when Default is CURRENT_TIMESTAMP' => [ |
| 62 | + ['Default' => 'CURRENT_TIMESTAMP'], |
| 63 | + [ |
| 64 | + 'DefaultType' => 'CURRENT_TIMESTAMP', |
| 65 | + 'DefaultValue' => '', |
| 66 | + ], |
| 67 | + ], |
| 68 | + 'when Default is current_timestamp' => [ |
| 69 | + ['Default' => 'current_timestamp()'], |
| 70 | + [ |
| 71 | + 'DefaultType' => 'CURRENT_TIMESTAMP', |
| 72 | + 'DefaultValue' => '', |
| 73 | + ], |
| 74 | + ], |
| 75 | + 'when Default is UUID' => [ |
| 76 | + ['Default' => 'UUID'], |
| 77 | + [ |
| 78 | + 'DefaultType' => 'UUID', |
| 79 | + 'DefaultValue' => '', |
| 80 | + ], |
| 81 | + ], |
| 82 | + 'when Default is uuid()' => [ |
| 83 | + ['Default' => 'uuid()'], |
| 84 | + [ |
| 85 | + 'DefaultType' => 'UUID', |
| 86 | + 'DefaultValue' => '', |
| 87 | + ], |
| 88 | + ], |
| 89 | + 'when Default is anything else and Type is text' => [ |
| 90 | + [ |
| 91 | + 'Default' => '"some\/thing"', |
| 92 | + 'Type' => 'text', |
| 93 | + ], |
| 94 | + [ |
| 95 | + 'Default' => 'some/thing', |
| 96 | + 'DefaultType' => 'USER_DEFINED', |
| 97 | + 'DefaultValue' => '"some\/thing"', |
| 98 | + ], |
| 99 | + ], |
| 100 | + 'when Default is anything else and Type is not text' => [ |
| 101 | + [ |
| 102 | + 'Default' => '"some\/thing"', |
| 103 | + 'Type' => 'something', |
| 104 | + ], |
| 105 | + [ |
| 106 | + 'DefaultType' => 'USER_DEFINED', |
| 107 | + 'DefaultValue' => '"some\/thing"', |
| 108 | + ], |
| 109 | + ], |
| 110 | + ]; |
| 111 | + } |
| 112 | +} |
0 commit comments