mirror of
https://github.com/opdavies/build-configs.git
synced 2025-01-22 10:17:32 +00:00
test: re-add original tests
This commit is contained in:
parent
1a4eba7349
commit
1c5eac72bb
6
.env.test
Normal file
6
.env.test
Normal file
|
@ -0,0 +1,6 @@
|
|||
# define your env variables for the test env here
|
||||
KERNEL_CLASS='App\Kernel'
|
||||
APP_SECRET='$ecretf0rt3st'
|
||||
SYMFONY_DEPRECATIONS_HELPER=999999
|
||||
PANTHER_APP_ENV=panther
|
||||
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
|
16
.gitignore
vendored
16
.gitignore
vendored
|
@ -11,3 +11,19 @@
|
|||
/var/
|
||||
/vendor/
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
/new-bin/
|
||||
|
||||
###> phpstan/phpstan ###
|
||||
phpstan.neon
|
||||
###< phpstan/phpstan ###
|
||||
|
||||
###> symfony/phpunit-bridge ###
|
||||
.phpunit.result.cache
|
||||
/phpunit.xml
|
||||
###< symfony/phpunit-bridge ###
|
||||
|
||||
###> phpunit/phpunit ###
|
||||
/phpunit.xml
|
||||
.phpunit.result.cache
|
||||
###< phpunit/phpunit ###
|
||||
|
|
|
@ -36,7 +36,8 @@
|
|||
"allow-plugins": {
|
||||
"symfony/flex": true,
|
||||
"symfony/runtime": true,
|
||||
"bamarni/composer-bin-plugin": true
|
||||
"bamarni/composer-bin-plugin": true,
|
||||
"pestphp/pest-plugin": true
|
||||
}
|
||||
},
|
||||
"bin": ["bin/build-configs"],
|
||||
|
@ -69,6 +70,10 @@
|
|||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8",
|
||||
"symfony/maker-bundle": "^1.48"
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"symfony/browser-kit": "6.2.*",
|
||||
"symfony/css-selector": "6.2.*",
|
||||
"symfony/maker-bundle": "^1.48",
|
||||
"symfony/phpunit-bridge": "^6.3"
|
||||
}
|
||||
}
|
||||
|
|
2032
composer.lock
generated
2032
composer.lock
generated
File diff suppressed because it is too large
Load diff
38
phpunit.xml.dist
Normal file
38
phpunit.xml.dist
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
convertDeprecationsToExceptions="false"
|
||||
>
|
||||
<php>
|
||||
<ini name="display_errors" value="1" />
|
||||
<ini name="error_reporting" value="-1" />
|
||||
<server name="APP_ENV" value="test" force="true" />
|
||||
<server name="SHELL_VERBOSITY" value="-1" />
|
||||
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
|
||||
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Project Test Suite">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">src</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
|
||||
<listeners>
|
||||
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
|
||||
</listeners>
|
||||
|
||||
<extensions>
|
||||
</extensions>
|
||||
</phpunit>
|
|
@ -49,7 +49,6 @@ final class Config
|
|||
#[Assert\Choice(choices: ['javascript', 'php', 'typescript'])]
|
||||
public string $language;
|
||||
|
||||
#[Assert\Length(min: 1)]
|
||||
#[Assert\NotBlank]
|
||||
public string $name;
|
||||
|
||||
|
@ -57,9 +56,6 @@ final class Config
|
|||
#[Assert\NotBlank]
|
||||
public string $type;
|
||||
|
||||
#[Assert\NotBlank]
|
||||
public ?string $projectRoot;
|
||||
|
||||
#[Assert\Collection(
|
||||
allowExtraFields: false,
|
||||
fields: [
|
||||
|
|
41
symfony.lock
41
symfony.lock
|
@ -11,6 +11,32 @@
|
|||
"php": {
|
||||
"version": "7.2.9"
|
||||
},
|
||||
"phpstan/phpstan": {
|
||||
"version": "1.10",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes-contrib",
|
||||
"branch": "main",
|
||||
"version": "1.0",
|
||||
"ref": "5e490cc197fb6bb1ae22e5abbc531ddc633b6767"
|
||||
},
|
||||
"files": [
|
||||
"phpstan.dist.neon"
|
||||
]
|
||||
},
|
||||
"phpunit/phpunit": {
|
||||
"version": "9.6",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "9.6",
|
||||
"ref": "7364a21d87e658eb363c5020c072ecfdc12e2326"
|
||||
},
|
||||
"files": [
|
||||
".env.test",
|
||||
"phpunit.xml.dist",
|
||||
"tests/bootstrap.php"
|
||||
]
|
||||
},
|
||||
"psr/cache": {
|
||||
"version": "1.0.1"
|
||||
},
|
||||
|
@ -127,6 +153,21 @@
|
|||
"ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f"
|
||||
}
|
||||
},
|
||||
"symfony/phpunit-bridge": {
|
||||
"version": "6.3",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "6.3",
|
||||
"ref": "01dfaa98c58f7a7b5a9b30e6edb7074af7ed9819"
|
||||
},
|
||||
"files": [
|
||||
".env.test",
|
||||
"new-bin/phpunit",
|
||||
"phpunit.xml.dist",
|
||||
"tests/bootstrap.php"
|
||||
]
|
||||
},
|
||||
"symfony/polyfill-intl-grapheme": {
|
||||
"version": "v1.22.1"
|
||||
},
|
||||
|
|
101
tests/Kernel/Validator/ConfigurationValidatorTest.php
Normal file
101
tests/Kernel/Validator/ConfigurationValidatorTest.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\DataTransferObject\Config;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
class ConfigurationValidatorTest extends KernelTestCase
|
||||
{
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
private ValidatorInterface $validator;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$normalizer = new ObjectNormalizer(null, new CamelCaseToSnakeCaseNameConverter());
|
||||
|
||||
$this->serializer = new Serializer([$normalizer], [new JsonEncoder()]);
|
||||
|
||||
$this->validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider projectNameProvider
|
||||
* @test
|
||||
*/
|
||||
public function project_name_should_be_a_string(string|int|bool|null $projectName, int $expectedViolationCount): void
|
||||
{
|
||||
$configurationData = [
|
||||
'language' => 'php',
|
||||
'name' => $projectName,
|
||||
'type' => 'drupal',
|
||||
];
|
||||
|
||||
$configurationDataDto = $this->createConfigurationDTO($configurationData);
|
||||
|
||||
$violations = $this->validator->validate($configurationDataDto);
|
||||
|
||||
self::assertCount(
|
||||
expectedCount: $expectedViolationCount,
|
||||
haystack: $violations,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider projectLanguageProvider
|
||||
* @test
|
||||
*/
|
||||
public function the_project_language_should_be_a_supported_language(string|int|bool|null $language, int $expectedViolationCount): void
|
||||
{
|
||||
$configurationData = [
|
||||
'language' => $language,
|
||||
'name' => 'test',
|
||||
'type' => 'drupal',
|
||||
];
|
||||
|
||||
$configurationDataDto = $this->createConfigurationDTO($configurationData);
|
||||
|
||||
$violations = $this->validator->validate($configurationDataDto);
|
||||
|
||||
self::assertCount(
|
||||
expectedCount: $expectedViolationCount,
|
||||
haystack: $violations,
|
||||
);
|
||||
}
|
||||
|
||||
public function projectLanguageProvider(): \Generator
|
||||
{
|
||||
return [
|
||||
yield 'Supported language string' => ['php', 0],
|
||||
yield 'Non-supported language string' => ['not-supported', 1],
|
||||
yield 'Empty string' => ['', 1],
|
||||
yield 'True' => [true, 1],
|
||||
yield 'False' => [false, 1],
|
||||
// yield 'Integer' => [1, 2],
|
||||
// yield 'Null' => [null, 1],
|
||||
];
|
||||
}
|
||||
|
||||
public function projectNameProvider(): \Generator
|
||||
{
|
||||
return [
|
||||
yield 'Non-empty string' => ['test', 0],
|
||||
yield 'Empty string' => ['', 1],
|
||||
yield 'False' => [false, 1],
|
||||
// yield 'Null' => [null, 1],
|
||||
];
|
||||
}
|
||||
|
||||
private function createConfigurationDTO(array $configurationData): Config
|
||||
{
|
||||
return $this->serializer->deserialize(json_encode($configurationData), Config::class, 'json');
|
||||
}
|
||||
}
|
15
tests/bootstrap.php
Normal file
15
tests/bootstrap.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
use Symfony\Component\Dotenv\Dotenv;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
|
||||
if (file_exists(dirname(__DIR__).'/config/bootstrap.php')) {
|
||||
require dirname(__DIR__).'/config/bootstrap.php';
|
||||
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
|
||||
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
|
||||
}
|
||||
|
||||
if ($_SERVER['APP_DEBUG']) {
|
||||
umask(0000);
|
||||
}
|
Loading…
Reference in a new issue