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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Config\Settings;
use PhpMyAdmin\Config\Settings\Console;
use PHPUnit\Framework\TestCase;
use function array_keys;
use function array_merge;
/**
* @covers \PhpMyAdmin\Config\Settings\Console
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\PhpMyAdmin\Config\Settings\Console::class)]
class ConsoleTest extends TestCase
{
/** @var array<string, bool|int|string> */
private $defaultValues = [
'StartHistory' => false,
'AlwaysExpand' => false,
'CurrentQuery' => true,
'EnterExecutes' => false,
'DarkTheme' => false,
'Mode' => 'info',
'Height' => 92,
'GroupQueries' => false,
'OrderBy' => 'exec',
'Order' => 'asc',
];
/**
* @param mixed[][] $values
* @psalm-param (array{0: string, 1: mixed, 2: mixed})[] $values
*
* @dataProvider providerForTestConstructor
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerForTestConstructor')]
public function testConstructor(array $values): void
{
$actualValues = [];
$expectedValues = [];
/** @psalm-suppress MixedAssignment */
foreach ($values as $value) {
$actualValues[$value[0]] = $value[1];
$expectedValues[$value[0]] = $value[2];
}
$expected = array_merge($this->defaultValues, $expectedValues);
$settings = new Console($actualValues);
foreach (array_keys($expectedValues) as $key) {
self::assertSame($expected[$key], $settings->$key);
}
}
/**
* [setting key, actual value, expected value]
*
* @return mixed[][][][]
* @psalm-return (array{0: string, 1: mixed, 2: mixed})[][][]
*/
public static function providerForTestConstructor(): array
{
return [
'null values' => [
[
['StartHistory', null, false],
['AlwaysExpand', null, false],
['CurrentQuery', null, true],
['EnterExecutes', null, false],
['DarkTheme', null, false],
['Mode', null, 'info'],
['Height', null, 92],
['GroupQueries', null, false],
['OrderBy', null, 'exec'],
['Order', null, 'asc'],
],
],
'valid values' => [
[
['StartHistory', false, false],
['AlwaysExpand', false, false],
['CurrentQuery', true, true],
['EnterExecutes', false, false],
['DarkTheme', false, false],
['Mode', 'info', 'info'],
['Height', 1, 1],
['GroupQueries', false, false],
['OrderBy', 'exec', 'exec'],
['Order', 'asc', 'asc'],
],
],
'valid values 2' => [
[
['StartHistory', true, true],
['AlwaysExpand', true, true],
['CurrentQuery', false, false],
['EnterExecutes', true, true],
['DarkTheme', true, true],
['Mode', 'show', 'show'],
['GroupQueries', true, true],
['OrderBy', 'time', 'time'],
['Order', 'desc', 'desc'],
],
],
'valid values 3' => [
[
['Mode', 'collapse', 'collapse'],
['OrderBy', 'count', 'count'],
],
],
'valid values with type coercion' => [
[
['StartHistory', 1, true],
['AlwaysExpand', 1, true],
['CurrentQuery', 0, false],
['EnterExecutes', 1, true],
['DarkTheme', 1, true],
['Height', '2', 2],
['GroupQueries', 1, true],
],
],
'invalid values' => [
[
['Mode', 'invalid', 'info'],
['Height', 0, 92],
['OrderBy', 'invalid', 'exec'],
['Order', 'invalid', 'asc'],
],
],
];
}
}
|