diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2021-09-22 22:31:10 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2021-09-22 22:31:10 +0300 |
commit | 87983d1cf532479b09eecd267bfc1c9a10cbb215 (patch) | |
tree | 70bcbd574856217366e6e1d1bfadbf1f9176830a /test | |
parent | 749ea69104fbe5c63a89ee19bcc36188f28aa33a (diff) |
Add `PhpMyAdmin\Dbal\TableName` value object class
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'test')
-rw-r--r-- | test/classes/Dbal/TableNameTest.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/classes/Dbal/TableNameTest.php b/test/classes/Dbal/TableNameTest.php new file mode 100644 index 0000000000..1c1847d117 --- /dev/null +++ b/test/classes/Dbal/TableNameTest.php @@ -0,0 +1,48 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Dbal; + +use InvalidArgumentException; +use PhpMyAdmin\Dbal\TableName; +use PHPUnit\Framework\TestCase; + +use function str_repeat; + +/** + * @covers \PhpMyAdmin\Dbal\TableName + */ +class TableNameTest extends TestCase +{ + public function testEmptyName(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Expected a different value than "".'); + new TableName(''); + } + + public function testNameWithTrailingWhitespace(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Expected a value not to end with " ". Got: "a "'); + new TableName('a '); + } + + public function testLongName(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage( + 'Expected a value to contain at most 64 characters. Got: ' + . '"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"' + ); + new TableName(str_repeat('a', 65)); + } + + public function testValidName(): void + { + $name = new TableName('name'); + $this->assertEquals('name', $name->getName()); + $this->assertEquals('name', (string) $name); + } +} |