validator = Validation::createValidatorBuilder() ->enableAnnotationMapping() ->getValidator(); } /** * @dataProvider projectNameProvider */ public function testTheProjectNameShouldBeAString( mixed $projectName, int $expectedViolationCount, ): void { if ($projectName === null) { self::expectException(NotNormalizableValueException::class); } $configurationDataDTO = self::createConfigurationDTO(); $configurationDataDTO->name = $projectName; $violations = $this->validator->validate($configurationDataDTO); self::assertCount( expectedCount: $expectedViolationCount, haystack: $violations, ); } /** * @dataProvider projectLanguageProvider */ public function testTheProjectLanguageShouldBeASupportedLanguage( string $language, int $expectedViolationCount, ): void { $configurationDataDTO = self::createConfigurationDTO(); $configurationDataDTO->language = $language; $violations = $this->validator->validate($configurationDataDTO); self::assertCount( expectedCount: $expectedViolationCount, haystack: $violations, ); if ($expectedViolationCount > 0) { self::assertSame( actual: $language, expected: $violations[0]->getInvalidValue(), ); } } /** * @dataProvider validWebServerTypesProvider */ public function testTheWebServerTypeIsValid( string $webServer, int $expectedViolationCount, ): void { $configurationDataDTO = self::createConfigurationDTO(); $configurationDataDTO->web['type'] = $webServer; $violations = $this->validator->validate($configurationDataDTO); self::assertCount( expectedCount: $expectedViolationCount, haystack: $violations, ); if ($expectedViolationCount > 0) { self::assertSame( actual: $webServer, expected: $violations[0]->getInvalidValue(), ); } } public function projectLanguageProvider(): \Generator { return [ yield 'Supported language string' => ['php', 0], yield 'Non-supported language string' => ['not-supported', 1], yield 'Empty string' => ['', 1], ]; } public function projectNameProvider(): \Generator { return [ yield 'Non-empty string' => ['test', 0], yield 'Empty string' => ['', 1], ]; } public function validWebServerTypesProvider(): \Generator { return [ yield 'caddy' => [WebServer::Caddy->value, 0], yield 'invalid' => ['not-a-valid-web-server', 1], yield 'nginx' => [WebServer::Nginx->value, 0], ]; } private static function createConfigurationDTO(): Config { $configurationDataDTO = new Config(); $configurationDataDTO->language = 'php'; $configurationDataDTO->name = 'test'; $configurationDataDTO->type = 'drupal'; return $configurationDataDTO; } }