mirror of
https://github.com/opdavies/build-configs.git
synced 2025-02-02 13:57:33 +00:00
test: ensure the project type is valid
This commit is contained in:
parent
08852c898a
commit
e9d5c4ea6f
|
@ -6,9 +6,11 @@
|
||||||
|
|
||||||
* Add CHANGELOG.md.
|
* Add CHANGELOG.md.
|
||||||
* Add missing validation rules to the `Configuration` DTO object.
|
* Add missing validation rules to the `Configuration` DTO object.
|
||||||
|
* 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.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
* `App\Enum\ProjectType` now returns a string.
|
||||||
* `App\Enum\Webserver` now returns a string.
|
* `App\Enum\Webserver` now returns a string.
|
||||||
* `ConfigurationValidatorTest` no longer performs serialisation.
|
* `ConfigurationValidatorTest` no longer performs serialisation.
|
||||||
|
|
8
run
8
run
|
@ -1,11 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -eu
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
TTY="${TTY:-}"
|
|
||||||
if [[ ! -t 1 ]]; then
|
|
||||||
TTY="-T"
|
|
||||||
fi
|
|
||||||
|
|
||||||
export PATH=$PATH:./bin:./vendor/bin:./vendor-bin/box/vendor/bin
|
export PATH=$PATH:./bin:./vendor/bin:./vendor-bin/box/vendor/bin
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,7 @@ final class Config
|
||||||
|
|
||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank]
|
||||||
#[Assert\Type('string')]
|
#[Assert\Type('string')]
|
||||||
#[Assert\Choice(choices: ['drupal', 'fractal', 'laravel', 'php-library', 'symfony'])]
|
#[Assert\Choice(choices: ['astro', 'drupal', 'fractal', 'laravel', 'php-library', 'symfony', 'terraform'])]
|
||||||
public string $type;
|
public string $type;
|
||||||
|
|
||||||
#[Assert\Type('array')]
|
#[Assert\Type('array')]
|
||||||
|
|
|
@ -4,10 +4,13 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Enum;
|
namespace App\Enum;
|
||||||
|
|
||||||
enum ProjectType
|
enum ProjectType: string
|
||||||
{
|
{
|
||||||
case Astro;
|
case Astro = 'astro';
|
||||||
case Drupal;
|
case Drupal = 'drupal';
|
||||||
case Fractal;
|
case Fractal = 'fractal';
|
||||||
case Terraform;
|
case Laravel = 'laravel';
|
||||||
|
case PHPLibrary = 'php-library';
|
||||||
|
case Symfony = 'symfony';
|
||||||
|
case Terraform = 'terraform';
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Tests;
|
namespace App\Tests;
|
||||||
|
|
||||||
use App\DataTransferObject\Config;
|
use App\DataTransferObject\Config;
|
||||||
|
use App\Enum\ProjectType;
|
||||||
use App\Enum\WebServer;
|
use App\Enum\WebServer;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
|
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
|
||||||
|
@ -67,6 +68,31 @@ class ConfigurationValidatorTest extends KernelTestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider projectTypeProvider
|
||||||
|
*/
|
||||||
|
public function testTheProjectTypeShouldBeASupportedType(
|
||||||
|
string $projectType,
|
||||||
|
int $expectedViolationCount,
|
||||||
|
): void {
|
||||||
|
$configurationDataDTO = self::createConfigurationDTO();
|
||||||
|
$configurationDataDTO->type = $projectType;
|
||||||
|
|
||||||
|
$violations = $this->validator->validate($configurationDataDTO);
|
||||||
|
|
||||||
|
self::assertCount(
|
||||||
|
expectedCount: $expectedViolationCount,
|
||||||
|
haystack: $violations,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($expectedViolationCount > 0) {
|
||||||
|
self::assertSame(
|
||||||
|
actual: $projectType,
|
||||||
|
expected: $violations[0]->getInvalidValue(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider validWebServerTypesProvider
|
* @dataProvider validWebServerTypesProvider
|
||||||
*/
|
*/
|
||||||
|
@ -109,6 +135,20 @@ class ConfigurationValidatorTest extends KernelTestCase
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function projectTypeProvider(): \Generator
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
yield 'astro' => [ProjectType::Astro->value, 0],
|
||||||
|
yield 'drupal' => [ProjectType::Drupal->value, 0],
|
||||||
|
yield 'fractal' => [ProjectType::Fractal->value, 0],
|
||||||
|
yield 'invalid' => ['not-a-project-type', 1],
|
||||||
|
yield 'laravel' => [ProjectType::Laravel->value, 0],
|
||||||
|
yield 'php-library' => [ProjectType::PHPLibrary->value, 0],
|
||||||
|
yield 'symfony' => [ProjectType::Symfony->value, 0],
|
||||||
|
yield 'terraform' => [ProjectType::Terraform->value, 0],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function validWebServerTypesProvider(): \Generator
|
public function validWebServerTypesProvider(): \Generator
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Reference in a new issue