test: adding extra databases

This commit is contained in:
Oliver Davies 2023-11-23 00:59:27 +00:00
parent df070e1c7d
commit fb53f307af
3 changed files with 51 additions and 0 deletions

View file

@ -13,6 +13,7 @@
* Add `database.extra_databases` * Add `database.extra_databases`
* Add `php.phpstan.baseline` as an optional boolean. * Add `php.phpstan.baseline` as an optional boolean.
* Add `node.version` as a string. * Add `node.version` as a string.
* Add a test to ensure extra databases is an optional array of non-blank strings.
* Add a test to ensure the project type is a valid type. * Add a test to ensure the project type is a valid type.
* Add a test to ensure the web server is a valid type. * Add a test to ensure the web server is a valid type.
* Add a `test` task to `run` script. * Add a `test` task to `run` script.

View file

@ -16,6 +16,7 @@ final class Config
'extra_databases' => new Assert\Optional([ 'extra_databases' => new Assert\Optional([
new Assert\Type('array'), new Assert\Type('array'),
new Assert\All([ new Assert\All([
new Assert\NotBlank(),
new Assert\Type('string'), new Assert\Type('string'),
]), ]),
]), ]),

View file

@ -12,15 +12,54 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
class ConfigurationValidatorTest extends KernelTestCase class ConfigurationValidatorTest extends KernelTestCase
{ {
private Config $configurationDataDTO;
private ValidatorInterface $validator; private ValidatorInterface $validator;
public function setUp(): void public function setUp(): void
{ {
$this->configurationDataDTO = self::createConfigurationDTO();
$this->validator = Validation::createValidatorBuilder() $this->validator = Validation::createValidatorBuilder()
->enableAnnotationMapping() ->enableAnnotationMapping()
->getValidator(); ->getValidator();
} }
/**
* @dataProvider extraDatabaseProvider
*/
public function testThatExtraDatabasesCanBeSpecified(
?array $extraDatabases,
int $expectedViolationCount,
?string $expectedMessage,
): void
{
$this->configurationDataDTO->database = [
'extra_databases' => $extraDatabases,
'type' => 'mariadb',
'version' => 10,
];
$violations = $this->validator->validate($this->configurationDataDTO);
self::assertCount(
expectedCount: $expectedViolationCount,
haystack: $violations,
);
if ($expectedViolationCount > 0) {
self::assertSame(
actual: 'database[extra_databases][0]',
expected: $violations[0]->getPropertyPath(),
);
self::assertSame(
actual: $expectedMessage,
expected: $violations[0]->getMessage(),
);
}
}
/** /**
* @dataProvider projectNameProvider * @dataProvider projectNameProvider
*/ */
@ -118,6 +157,16 @@ class ConfigurationValidatorTest extends KernelTestCase
} }
} }
public function extraDatabaseProvider(): \Generator
{
return [
yield 'correct' => [['migrate'], 0, null],
yield 'empty string' => [[''], 1, 'This value should not be blank.'],
yield 'missing' => [null, 0, null],
yield 'no extra databases' => [[], 0, null],
];
}
public function projectLanguageProvider(): \Generator public function projectLanguageProvider(): \Generator
{ {
return [ return [