mirror of
https://github.com/opdavies/build-configs.git
synced 2025-02-02 05:47:32 +00:00
test: adding extra databases
This commit is contained in:
parent
df070e1c7d
commit
fb53f307af
|
@ -13,6 +13,7 @@
|
|||
* Add `database.extra_databases`
|
||||
* Add `php.phpstan.baseline` as an optional boolean.
|
||||
* 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 web server is a valid type.
|
||||
* Add a `test` task to `run` script.
|
||||
|
|
|
@ -16,6 +16,7 @@ final class Config
|
|||
'extra_databases' => new Assert\Optional([
|
||||
new Assert\Type('array'),
|
||||
new Assert\All([
|
||||
new Assert\NotBlank(),
|
||||
new Assert\Type('string'),
|
||||
]),
|
||||
]),
|
||||
|
|
|
@ -12,15 +12,54 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|||
|
||||
class ConfigurationValidatorTest extends KernelTestCase
|
||||
{
|
||||
private Config $configurationDataDTO;
|
||||
|
||||
private ValidatorInterface $validator;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->configurationDataDTO = self::createConfigurationDTO();
|
||||
|
||||
$this->validator = Validation::createValidatorBuilder()
|
||||
->enableAnnotationMapping()
|
||||
->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
|
||||
*/
|
||||
|
@ -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
|
||||
{
|
||||
return [
|
||||
|
|
Loading…
Reference in a new issue