Completed
Push — master ( b2555a...090da9 )
by Maurício
01:57 queued 30s
created

TriggerNameTest::testInvalidNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\Tests\Identifiers;
6
7
use PhpMyAdmin\Identifiers\InvalidTriggerName;
8
use PhpMyAdmin\Identifiers\TriggerName;
0 ignored issues
show
Bug introduced by
The type PhpMyAdmin\Identifiers\TriggerName was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use PHPUnit\Framework\TestCase;
10
11
use function str_repeat;
12
13
/**
14
 * @covers \PhpMyAdmin\Identifiers\InvalidTriggerName
15
 * @covers \PhpMyAdmin\Identifiers\TriggerName
16
 */
17
final class TriggerNameTest extends TestCase
18
{
19
    /** @dataProvider providerForTestValidNames */
20
    public function testValidName(string $validName): void
21
    {
22
        $name = TriggerName::from($validName);
23
        $this->assertEquals($validName, $name->getName());
24
        $this->assertEquals($validName, (string) $name);
25
    }
26
27
    /** @dataProvider providerForTestValidNames */
28
    public function testTryFromValueValidName(string $validName): void
29
    {
30
        $name = TriggerName::tryFrom($validName);
31
        $this->assertNotNull($name);
32
        $this->assertEquals($validName, $name->getName());
33
        $this->assertEquals($validName, (string) $name);
34
    }
35
36
    /** @return iterable<int, string[]> */
37
    public static function providerForTestValidNames(): iterable
38
    {
39
        yield ['name'];
40
        yield ['0'];
41
        yield [str_repeat('a', 64)];
42
    }
43
44
    /** @dataProvider providerForTestInvalidNames */
45
    public function testInvalidNames(mixed $name, string $exceptionMessage): void
46
    {
47
        $this->assertNull(TriggerName::tryFrom($name));
48
        $this->expectException(InvalidTriggerName::class);
49
        $this->expectExceptionMessage($exceptionMessage);
50
        TriggerName::from($name);
51
    }
52
53
    /**
54
     * @return iterable<string, mixed[]>
55
     * @psalm-return iterable<string, array{mixed, non-empty-string}>
56
     */
57
    public static function providerForTestInvalidNames(): iterable
58
    {
59
        yield 'null' => [null, 'The trigger name must not be empty.'];
60
        yield 'integer' => [1, 'The trigger name must not be empty.'];
61
        yield 'array' => [['trigger_name'], 'The trigger name must not be empty.'];
62
        yield 'empty string' => ['', 'The trigger name must not be empty.'];
63
        yield 'too long name' => [str_repeat('a', 65), 'The trigger name cannot be longer than 64 characters.'];
64
        yield 'trailing space' => ['a ', 'The trigger name cannot end with a space character.'];
65
    }
66
}
67