*/ class ExportRendererValidatorTest extends ConstraintValidatorTestCase { protected function createValidator(): ExportRendererValidator { return new ExportRendererValidator(); } public static function getValidColors(): iterable { yield ['csv']; yield ['xlsx']; yield [null]; } public function testConstraintIsInvalid(): void { $this->expectException(UnexpectedTypeException::class); $this->validator->validate('#000', new NotBlank()); } /** * @dataProvider getValidColors */ public function testConstraintWithValidColor(?string $color): void { $constraint = new ExportRenderer(); $this->validator->validate($color, $constraint); $this->assertNoViolation(); } public static function getInvalidColors(): iterable { yield ['CSV']; yield ['XLSX']; yield ['PDF']; yield ['HTML']; yield ['fff000']; yield ['000aaa']; yield ['fffaaa']; yield ['#f']; yield ['#ff']; yield ['#ffdd']; yield ['#ffddd']; yield ['#ffddddd']; yield [new \stdClass(), 'object']; yield [[], 'array']; } /** * @dataProvider getInvalidColors */ public function testValidationError(mixed $color, ?string $parameterType = null): void { $constraint = new ExportRenderer(); $this->validator->validate($color, $constraint); if (\is_string($color)) { $expectedFormat = '"' . $color . '"'; } else { $expectedFormat = $parameterType ?? ''; } $this->buildViolation('Unknown exporter type.') ->setParameter('{{ value }}', $expectedFormat) ->setCode(ExportRenderer::UNKNOWN_TYPE) ->assertRaised(); } }