chore: add missing values to the Config DTO

Add missing properties and constraints to the `Config` data transfer
object.
This commit is contained in:
Oliver Davies 2023-11-22 20:07:11 +00:00
parent 517309e222
commit 95012241e1
2 changed files with 193 additions and 33 deletions

View file

@ -8,67 +8,229 @@ use Symfony\Component\Validator\Constraints as Assert;
final class Config
{
/**
* @var array<string,string|integer|array<int,string>>
*/
#[Assert\Type('array')]
#[Assert\Valid]
#[Assert\Collection(
allowExtraFields: false,
fields: [
'extra_databases' => new Assert\Optional(
new Assert\All(new Assert\Type('string'))
),
'type' => new Assert\Choice(['mariadb', 'mysql']),
'version' => new Assert\Type('integer'),
'type' => new Assert\Required([
new Assert\Choice(choices: ['mariadb', 'mysql']),
new Assert\Type('string'),
]),
'version' => new Assert\Required([
new Assert\Type('int'),
]),
],
)]
public array $database;
/**
* @var array<string,string|null>
*/
#[Assert\Type('array')]
#[Assert\Valid]
#[Assert\Collection(
allowExtraFields: false,
fields: [
'services' => new Assert\Required([
new Assert\Type('array'),
new Assert\Count(['min' => 1]),
new Assert\All([
new Assert\Type('string'),
]),
]),
],
)]
public array $dockerCompose;
#[Assert\Type('array')]
#[Assert\Valid]
#[Assert\Collection(
allowExtraFields: false,
fields: [
'stages' => new Assert\Optional([
new Assert\Type('array'),
new Assert\All([
new Assert\Collection([
'commands' => new Assert\Optional([
new Assert\Type('array'),
new Assert\All([
new Assert\Type('string'),
]),
]),
'extends' => new Assert\Optional([
new Assert\Type('string'),
]),
'extensions' => new Assert\Optional([
new Assert\Collection(
allowExtraFields: false,
fields: [
'install' => new Assert\Required([
new Assert\Type('array'),
new Assert\All([
new Assert\Type('string'),
]),
]),
],
),
]),
'packages' => new Assert\Optional([
new Assert\Type('array'),
new Assert\All([
new Assert\Type('string'),
]),
]),
'root_commands' => new Assert\Optional([
new Assert\Type('array'),
new Assert\All([
new Assert\Type('string'),
]),
]),
]),
]),
]),
],
)]
public array $dockerfile;
#[Assert\Type('array')]
#[Assert\Valid]
#[Assert\Collection(
allowExtraFields: false,
fields: ['docroot' => new Assert\Choice([null, 'web', 'docroot'])],
)]
public array $drupal;
/**
* @var array<string,string|null>
*/
#[Assert\Type('array')]
#[Assert\Valid]
#[Assert\Collection(
allowExtraFields: false,
allowMissingFields: true,
fields: [
'createGitHubActionsConfiguration' => new Assert\Type('boolean'),
'runGitHooksBeforePush' => new Assert\Type('boolean'),
'useNewDatabaseCredentials' => new Assert\Type('boolean'),
]
'createGitHubActionsConfiguration' => new Assert\Optional([
new Assert\Type('bool'),
]),
'runGitHooksBeforePush' => new Assert\Optional([
new Assert\Type('bool'),
]),
'useNewDatabaseCredentials' => new Assert\Optional([
new Assert\Type('bool'),
]),
],
)]
public array $experimental;
#[Assert\Type('array')]
#[Assert\Valid()]
#[Assert\Collection([
'ignore' => new Assert\Optional([
new Assert\All([
new Assert\Type('string'),
]),
]),
])]
public array $git;
#[Assert\Type('array')]
#[Assert\Valid]
#[Assert\Collection(
allowExtraFields: false,
fields: [
'devshell' => new Assert\Required([
new Assert\Type('array'),
new Assert\Collection([
'packages' => new Assert\Required([
new Assert\Type('array'),
new Assert\All([
new Assert\Type('string'),
]),
]),
]),
]),
],
)]
public array $flake;
#[Assert\Type('string')]
#[Assert\Choice(choices: ['javascript', 'php', 'typescript'])]
public string $language;
#[Assert\NotBlank]
#[Assert\Type('string')]
public string $name;
#[Assert\Choice(choices: ['astro', 'drupal', 'fractal', 'laravel', 'php-library', 'terraform', 'vuejs'])]
#[Assert\NotBlank]
public string $type;
#[Assert\Type('array')]
#[Assert\Valid]
#[Assert\Collection(
allowExtraFields: false,
fields: [
'ignore' => new Assert\Optional([
'type' => new Assert\Required([
new Assert\Type('array'),
new Assert\Count(['min' => 1]),
new Assert\All([
new Assert\Type('string'),
])
])
]
new Assert\Collection([
'type' => new Assert\Required([
new Assert\Type('string'),
]),
]),
]),
],
)]
public array $git;
public array $node;
#[Assert\Type('array')]
#[Assert\Valid]
#[Assert\Collection(
allowExtraFields: false,
fields: [
'version' => new Assert\Required([
new Assert\Type('string'),
]),
'phpcs' => new Assert\Optional([
new Assert\Collection([
'paths' => new Assert\Required([
new Assert\Type('array'),
new Assert\Count(['min' => 1]),
new Assert\All([
new Assert\Type('string'),
]),
]),
'standards' => new Assert\Required([
new Assert\Type('array'),
new Assert\Count(['min' => 1]),
new Assert\All([
new Assert\Type('string'),
]),
]),
]),
]),
'phpstan' => new Assert\Optional([
new Assert\Collection([
'level' => new Assert\Required([
new Assert\Type(['string', 'integer']),
]),
'paths' => new Assert\Required([
new Assert\Type('array'),
new Assert\Count(['min' => 1]),
new Assert\All([
new Assert\Type('string'),
]),
]),
]),
]),
],
)]
public array $php;
#[Assert\Type('string')]
public string $projectRoot;
#[Assert\NotBlank]
#[Assert\Type('string')]
#[Assert\Choice(choices: ['drupal', 'fractal', 'laravel', 'php-library', 'symfony'])]
public string $type;
#[Assert\Type('array')]
#[Assert\Valid()]
#[Assert\Collection([
'type' => new Assert\Required([
new Assert\Type('string'),
new Assert\Choice(choices: ['nginx', 'caddy']),
]),
])]
public array $web;
}

View file

@ -96,8 +96,6 @@ class ConfigurationValidatorTest extends KernelTestCase
return [
yield 'Non-empty string' => ['test', 0],
yield 'Empty string' => ['', 1],
yield 'False' => [false, 1],
yield 'Null' => [null, 1],
];
}