phpmyadmin/test/classes/Dbal/TableNameTest.php
Maurício Meneghini Fauth 0c781c9335
Rename TableName|DatabaseName create method to fromString
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2021-09-30 22:14:51 -03:00

49 lines
1.3 KiB
PHP

<?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 "".');
TableName::fromString('');
}
public function testNameWithTrailingWhitespace(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expected a value not to end with " ". Got: "a "');
TableName::fromString('a ');
}
public function testLongName(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
'Expected a value to contain at most 64 characters. Got: '
. '"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"'
);
TableName::fromString(str_repeat('a', 65));
}
public function testValidName(): void
{
$name = TableName::fromString('name');
$this->assertEquals('name', $name->getName());
$this->assertEquals('name', (string) $name);
}
}