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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Table;
use PhpMyAdmin\Table\ColumnsDefinition;
use PhpMyAdmin\Tests\AbstractTestCase;
/**
* @covers \PhpMyAdmin\Table\ColumnsDefinition
*/
class ColumnsDefinitionTest extends AbstractTestCase
{
/**
* test for ColumnsDefinition::decorateColumnMetaDefault
*
* @param array $columnMeta column metadata
* @param array $expected expected result
* @phpstan-param array<string, string|null> $columnMeta
* @phpstan-param array<string, string> $expected
*
* @dataProvider providerColumnMetaDefault
*/
public function testDecorateColumnMetaDefault(array $columnMeta, array $expected): void
{
$result = ColumnsDefinition::decorateColumnMetaDefault($columnMeta);
$this->assertEquals($expected, $result);
}
/**
* Data provider for testDecorateColumnMetaDefault
*
* @return array
* @psalm-return array<string, array{array<string, string|null>, array<string, string>}>
*/
public function providerColumnMetaDefault(): array
{
return [
'when Default is null and Null is YES' => [
[
'Default' => null,
'Null' => 'YES',
],
[
'DefaultType' => 'NULL',
'DefaultValue' => '',
],
],
'when Default is null and Null is NO' => [
[
'Default' => null,
'Null' => 'NO',
],
[
'DefaultType' => 'NONE',
'DefaultValue' => '',
],
],
'when Default is CURRENT_TIMESTAMP' => [
['Default' => 'CURRENT_TIMESTAMP'],
[
'DefaultType' => 'CURRENT_TIMESTAMP',
'DefaultValue' => '',
],
],
'when Default is current_timestamp' => [
['Default' => 'current_timestamp()'],
[
'DefaultType' => 'CURRENT_TIMESTAMP',
'DefaultValue' => '',
],
],
'when Default is UUID' => [
['Default' => 'UUID'],
[
'DefaultType' => 'UUID',
'DefaultValue' => '',
],
],
'when Default is uuid()' => [
['Default' => 'uuid()'],
[
'DefaultType' => 'UUID',
'DefaultValue' => '',
],
],
'when Default is anything else and Type is text' => [
[
'Default' => '"some\/thing"',
'Type' => 'text',
],
[
'Default' => 'some/thing',
'DefaultType' => 'USER_DEFINED',
'DefaultValue' => '"some\/thing"',
],
],
'when Default is anything else and Type is not text' => [
[
'Default' => '"some\/thing"',
'Type' => 'something',
],
[
'DefaultType' => 'USER_DEFINED',
'DefaultValue' => '"some\/thing"',
],
],
];
}
}
|