mirror of
https://github.com/opdavies/build-configs.git
synced 2025-03-13 05:26:56 +00:00
test: ensure the web server is a valid type
This commit is contained in:
parent
95012241e1
commit
b65e92b790
|
@ -165,7 +165,7 @@ final class CreateListOfFilesToGenerate
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strtoupper($webServer) === WebServer::CADDY->name;
|
return strtoupper($webServer) === WebServer::Caddy->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function isDocker(array $configurationData): bool
|
private static function isDocker(array $configurationData): bool
|
||||||
|
@ -188,6 +188,6 @@ final class CreateListOfFilesToGenerate
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strtoupper($webServer) === WebServer::NGINX->name;
|
return strtoupper($webServer) === WebServer::Nginx->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Enum;
|
namespace App\Enum;
|
||||||
|
|
||||||
enum WebServer
|
enum WebServer: string
|
||||||
{
|
{
|
||||||
case CADDY;
|
case Caddy = 'caddy';
|
||||||
case NGINX;
|
case Nginx = 'nginx';
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Tests;
|
namespace App\Tests;
|
||||||
|
|
||||||
use App\DataTransferObject\Config;
|
use App\DataTransferObject\Config;
|
||||||
|
use App\Enum\WebServer;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||||
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
|
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
|
||||||
|
@ -78,6 +79,38 @@ class ConfigurationValidatorTest extends KernelTestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider validWebServerTypesProvider
|
||||||
|
*/
|
||||||
|
public function testTheWebServerTypeIsValid(
|
||||||
|
string $webServer,
|
||||||
|
int $expectedViolationCount,
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$configurationData = [
|
||||||
|
'language' => 'php',
|
||||||
|
'name' => 'test',
|
||||||
|
'type' => 'drupal',
|
||||||
|
'web' => ['type' => $webServer],
|
||||||
|
];
|
||||||
|
|
||||||
|
$configurationDataDto = $this->createConfigurationDTO($configurationData);
|
||||||
|
|
||||||
|
$violations = $this->validator->validate($configurationDataDto);
|
||||||
|
|
||||||
|
self::assertCount(
|
||||||
|
expectedCount: $expectedViolationCount,
|
||||||
|
haystack: $violations,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($expectedViolationCount > 0) {
|
||||||
|
self::assertSame(
|
||||||
|
actual: $webServer,
|
||||||
|
expected: $violations[0]->getInvalidValue(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function projectLanguageProvider(): \Generator
|
public function projectLanguageProvider(): \Generator
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -103,4 +136,13 @@ class ConfigurationValidatorTest extends KernelTestCase
|
||||||
{
|
{
|
||||||
return $this->serializer->deserialize(json_encode($configurationData), Config::class, 'json');
|
return $this->serializer->deserialize(json_encode($configurationData), Config::class, 'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function validWebServerTypesProvider(): \Generator
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
yield 'caddy' => [WebServer::Caddy->value, 0],
|
||||||
|
yield 'invalid' => ['not-a-valid-web-server', 1],
|
||||||
|
yield 'nginx' => [WebServer::Nginx->value, 0],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue