getName()); self::assertSame($validName, (string) $name); } #[DataProvider('providerForTestValidNames')] public function testTryFromValueValidName(string $validName): void { $name = TableName::tryFrom($validName); self::assertNotNull($name); self::assertSame($validName, $name->getName()); self::assertSame($validName, (string) $name); } /** @return iterable */ public static function providerForTestValidNames(): iterable { yield ['name']; yield ['0']; yield [str_repeat('a', 64)]; } #[DataProvider('providerForTestInvalidNames')] public function testInvalidNames(mixed $name, string $exceptionMessage): void { self::assertNull(TableName::tryFrom($name)); $this->expectException(InvalidTableName::class); $this->expectExceptionMessage($exceptionMessage); TableName::from($name); } /** * @return iterable * @psalm-return iterable */ public static 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.']; } }