Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TableNameTest.php « Dbal « classes « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0ea928dc383a20f806f21736ebf09e8aec6e9f5b (plain)
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
<?php

declare(strict_types=1);

namespace PhpMyAdmin\Tests\Dbal;

use PhpMyAdmin\Dbal\InvalidTableName;
use PhpMyAdmin\Dbal\TableName;
use PHPUnit\Framework\TestCase;

use function str_repeat;

/**
 * @covers \PhpMyAdmin\Dbal\TableName
 * @covers \PhpMyAdmin\Dbal\InvalidTableName
 */
class TableNameTest extends TestCase
{
    /**
     * @dataProvider providerForTestValidNames
     */
    public function testValidName(string $validName): void
    {
        $name = TableName::fromValue($validName);
        $this->assertEquals($validName, $name->getName());
        $this->assertEquals($validName, (string) $name);
    }

    /**
     * @return iterable<int, string[]>
     */
    public function providerForTestValidNames(): iterable
    {
        yield ['name'];
        yield ['0'];
        yield [str_repeat('a', 64)];
    }

    /**
     * @param mixed $name
     *
     * @dataProvider providerForTestInvalidNames
     */
    public function testInvalidNames($name, string $exceptionMessage): void
    {
        $this->expectException(InvalidTableName::class);
        $this->expectExceptionMessage($exceptionMessage);
        TableName::fromValue($name);
    }

    /**
     * @return iterable<string, mixed[]>
     * @psalm-return iterable<string, array{mixed, non-empty-string}>
     */
    public function providerForTestInvalidNames(): iterable
    {
        yield 'null' => [null, 'The table name must be a non-empty string.'];
        yield 'integer' => [1, 'The table name must be a non-empty string.'];
        yield 'array' => [['table'], 'The table name must be a non-empty string.'];
        yield 'empty string' => ['', 'The table name must be a non-empty string.'];
        yield 'too long name' => [str_repeat('a', 65), 'The table name cannot be longer than 64 characters.'];
        yield 'trailing space' => ['a ', 'The table name cannot end with a space character.'];
    }
}