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 final class Config
{ {
/** #[Assert\Type('array')]
* @var array<string,string|integer|array<int,string>> #[Assert\Valid]
*/
#[Assert\Collection( #[Assert\Collection(
allowExtraFields: false, allowExtraFields: false,
fields: [ fields: [
'extra_databases' => new Assert\Optional( 'type' => new Assert\Required([
new Assert\All(new Assert\Type('string')) new Assert\Choice(choices: ['mariadb', 'mysql']),
), new Assert\Type('string'),
'type' => new Assert\Choice(['mariadb', 'mysql']), ]),
'version' => new Assert\Type('integer'), 'version' => new Assert\Required([
new Assert\Type('int'),
]),
], ],
)] )]
public array $database; public array $database;
/** #[Assert\Type('array')]
* @var array<string,string|null> #[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( #[Assert\Collection(
allowExtraFields: false, allowExtraFields: false,
fields: ['docroot' => new Assert\Choice([null, 'web', 'docroot'])], fields: ['docroot' => new Assert\Choice([null, 'web', 'docroot'])],
)] )]
public array $drupal; public array $drupal;
/** #[Assert\Type('array')]
* @var array<string,string|null> #[Assert\Valid]
*/
#[Assert\Collection( #[Assert\Collection(
allowExtraFields: false, allowExtraFields: false,
allowMissingFields: true,
fields: [ fields: [
'createGitHubActionsConfiguration' => new Assert\Type('boolean'), 'createGitHubActionsConfiguration' => new Assert\Optional([
'runGitHooksBeforePush' => new Assert\Type('boolean'), new Assert\Type('bool'),
'useNewDatabaseCredentials' => new Assert\Type('boolean'), ]),
] 'runGitHooksBeforePush' => new Assert\Optional([
new Assert\Type('bool'),
]),
'useNewDatabaseCredentials' => new Assert\Optional([
new Assert\Type('bool'),
]),
],
)] )]
public array $experimental; 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'])] #[Assert\Choice(choices: ['javascript', 'php', 'typescript'])]
public string $language; public string $language;
#[Assert\NotBlank] #[Assert\NotBlank]
#[Assert\Type('string')]
public string $name; public string $name;
#[Assert\Choice(choices: ['astro', 'drupal', 'fractal', 'laravel', 'php-library', 'terraform', 'vuejs'])] #[Assert\Type('array')]
#[Assert\NotBlank] #[Assert\Valid]
public string $type;
#[Assert\Collection( #[Assert\Collection(
allowExtraFields: false, allowExtraFields: false,
fields: [ fields: [
'ignore' => new Assert\Optional([ 'type' => new Assert\Required([
new Assert\Type('array'),
new Assert\Collection([
'type' => new Assert\Required([
new Assert\Type('string'),
]),
]),
]),
],
)]
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\Type('array'),
new Assert\Count(['min' => 1]), new Assert\Count(['min' => 1]),
new Assert\All([ new Assert\All([
new Assert\Type('string'), 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 $git;
public array $php; 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 [ return [
yield 'Non-empty string' => ['test', 0], yield 'Non-empty string' => ['test', 0],
yield 'Empty string' => ['', 1], yield 'Empty string' => ['', 1],
yield 'False' => [false, 1],
yield 'Null' => [null, 1],
]; ];
} }