test: add violation message assertions

This commit is contained in:
Oliver Davies 2023-11-23 01:19:33 +00:00
parent fb53f307af
commit 9ae880664a
2 changed files with 48 additions and 16 deletions

View file

@ -1,5 +1,11 @@
# Changelog # Changelog
## 2023-11-23
### Added
* Test assertions for the expected violation messages.
## 2023-11-22 ## 2023-11-22
### Added ### Added

View file

@ -66,6 +66,7 @@ class ConfigurationValidatorTest extends KernelTestCase
public function testTheProjectNameShouldBeAString( public function testTheProjectNameShouldBeAString(
mixed $projectName, mixed $projectName,
int $expectedViolationCount, int $expectedViolationCount,
?string $expectedMessage,
): void { ): void {
if ($projectName === null) { if ($projectName === null) {
self::expectException(NotNormalizableValueException::class); self::expectException(NotNormalizableValueException::class);
@ -80,6 +81,13 @@ class ConfigurationValidatorTest extends KernelTestCase
expectedCount: $expectedViolationCount, expectedCount: $expectedViolationCount,
haystack: $violations, haystack: $violations,
); );
if ($violations->count() > 0) {
self::assertSame(
actual: $expectedMessage,
expected: $violations[0]->getMessage(),
);
}
} }
/** /**
@ -88,6 +96,7 @@ class ConfigurationValidatorTest extends KernelTestCase
public function testTheProjectLanguageShouldBeASupportedLanguage( public function testTheProjectLanguageShouldBeASupportedLanguage(
string $language, string $language,
int $expectedViolationCount, int $expectedViolationCount,
?string $expectedMessage,
): void { ): void {
$configurationDataDTO = self::createConfigurationDTO(); $configurationDataDTO = self::createConfigurationDTO();
$configurationDataDTO->language = $language; $configurationDataDTO->language = $language;
@ -104,6 +113,11 @@ class ConfigurationValidatorTest extends KernelTestCase
actual: $language, actual: $language,
expected: $violations[0]->getInvalidValue(), expected: $violations[0]->getInvalidValue(),
); );
self::assertSame(
actual: $expectedMessage,
expected: $violations[0]->getMessage(),
);
} }
} }
@ -113,6 +127,7 @@ class ConfigurationValidatorTest extends KernelTestCase
public function testTheProjectTypeShouldBeASupportedType( public function testTheProjectTypeShouldBeASupportedType(
string $projectType, string $projectType,
int $expectedViolationCount, int $expectedViolationCount,
?string $expectedMessage,
): void { ): void {
$configurationDataDTO = self::createConfigurationDTO(); $configurationDataDTO = self::createConfigurationDTO();
$configurationDataDTO->type = $projectType; $configurationDataDTO->type = $projectType;
@ -129,6 +144,11 @@ class ConfigurationValidatorTest extends KernelTestCase
actual: $projectType, actual: $projectType,
expected: $violations[0]->getInvalidValue(), expected: $violations[0]->getInvalidValue(),
); );
self::assertSame(
actual: $expectedMessage,
expected: $violations[0]->getMessage(),
);
} }
} }
@ -138,6 +158,7 @@ class ConfigurationValidatorTest extends KernelTestCase
public function testTheWebServerTypeIsValid( public function testTheWebServerTypeIsValid(
string $webServer, string $webServer,
int $expectedViolationCount, int $expectedViolationCount,
?string $expectedMessage,
): void { ): void {
$configurationDataDTO = self::createConfigurationDTO(); $configurationDataDTO = self::createConfigurationDTO();
$configurationDataDTO->web['type'] = $webServer; $configurationDataDTO->web['type'] = $webServer;
@ -154,6 +175,11 @@ class ConfigurationValidatorTest extends KernelTestCase
actual: $webServer, actual: $webServer,
expected: $violations[0]->getInvalidValue(), expected: $violations[0]->getInvalidValue(),
); );
self::assertSame(
actual: $expectedMessage,
expected: $violations[0]->getMessage(),
);
} }
} }
@ -170,40 +196,40 @@ class ConfigurationValidatorTest extends KernelTestCase
public function projectLanguageProvider(): \Generator public function projectLanguageProvider(): \Generator
{ {
return [ return [
yield 'Supported language string' => ['php', 0], yield 'Supported language string' => ['php', 0, null],
yield 'Non-supported language string' => ['not-supported', 1], yield 'Non-supported language string' => ['not-supported', 1, 'The value you selected is not a valid choice.'],
yield 'Empty string' => ['', 1], yield 'Empty string' => ['', 1, 'The value you selected is not a valid choice.'],
]; ];
} }
public function projectNameProvider(): \Generator public function projectNameProvider(): \Generator
{ {
return [ return [
yield 'Non-empty string' => ['test', 0], yield 'Non-empty string' => ['test', 0, null],
yield 'Empty string' => ['', 1], yield 'Empty string' => ['', 1, 'This value should not be blank.'],
]; ];
} }
public function projectTypeProvider(): \Generator public function projectTypeProvider(): \Generator
{ {
return [ return [
yield 'astro' => [ProjectType::Astro->value, 0], yield 'astro' => [ProjectType::Astro->value, 0, null],
yield 'drupal' => [ProjectType::Drupal->value, 0], yield 'drupal' => [ProjectType::Drupal->value, 0, null],
yield 'fractal' => [ProjectType::Fractal->value, 0], yield 'fractal' => [ProjectType::Fractal->value, 0, null],
yield 'invalid' => ['not-a-project-type', 1], yield 'invalid' => ['not-a-project-type', 1, 'The value you selected is not a valid choice.'],
yield 'laravel' => [ProjectType::Laravel->value, 0], yield 'laravel' => [ProjectType::Laravel->value, 0, null],
yield 'php-library' => [ProjectType::PHPLibrary->value, 0], yield 'php-library' => [ProjectType::PHPLibrary->value, 0, null],
yield 'symfony' => [ProjectType::Symfony->value, 0], yield 'symfony' => [ProjectType::Symfony->value, 0, null],
yield 'terraform' => [ProjectType::Terraform->value, 0], yield 'terraform' => [ProjectType::Terraform->value, 0, null],
]; ];
} }
public function validWebServerTypesProvider(): \Generator public function validWebServerTypesProvider(): \Generator
{ {
return [ return [
yield 'caddy' => [WebServer::Caddy->value, 0], yield 'caddy' => [WebServer::Caddy->value, 0, null],
yield 'invalid' => ['not-a-valid-web-server', 1], yield 'invalid' => ['not-a-valid-web-server', 1, 'The value you selected is not a valid choice.'],
yield 'nginx' => [WebServer::Nginx->value, 0], yield 'nginx' => [WebServer::Nginx->value, 0, null],
]; ];
} }