Skip to content

Commit

Permalink
add configuration validator test
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Dec 24, 2023
1 parent b56c0a9 commit a7a384b
Showing 1 changed file with 168 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?php

namespace phpunit\Components\Configuration\Services;

use PHPUnit\Framework\TestCase;
use phpunit\Utils\Traits\TranslationSetBuilderTrait;
use PHPUnuhi\Configuration\Services\ConfigurationValidator;
use PHPUnuhi\Exceptions\ConfigurationException;
use PHPUnuhi\Models\Configuration\Configuration;
use PHPUnuhi\Models\Configuration\Filter;
use PHPUnuhi\Models\Configuration\Protection;
use PHPUnuhi\Models\Translation\Locale;
use PHPUnuhi\Models\Translation\TranslationSet;

class ConfigurationValidatorTest extends TestCase
{
use TranslationSetBuilderTrait;


/**
* @var ConfigurationValidator
*/
private $validator;

/**
* @return void
*/
public function setUp(): void
{
$this->validator = new ConfigurationValidator();
}

/**
* @throws ConfigurationException
* @return void
*/
public function testEmptySetsLeadToException(): void
{
$this->expectException(ConfigurationException::class);

$configuration = new Configuration([]);

$this->validator->validateConfig($configuration);
}

/**
* @throws ConfigurationException
* @return void
*/
public function testSetsWithoutNameLeadToException(): void
{
$this->expectException(ConfigurationException::class);

$set = new TranslationSet(
'',
'',
new Protection(),
[],
new Filter(),
[],
[],
[]
);

$configuration = new Configuration([$set]);

$this->validator->validateConfig($configuration);
}

/**
* @throws ConfigurationException
* @return void
*/
public function testSetsWithoutFormatLeadToException(): void
{
$this->expectException(ConfigurationException::class);

$set = new TranslationSet(
'Storefront',
'',
new Protection(),
[],
new Filter(),
[],
[],
[]
);

$configuration = new Configuration([$set]);

$this->validator->validateConfig($configuration);
}

/**
* @throws ConfigurationException
* @return void
*/
public function testSetsWithSameNameLeadToException(): void
{
$this->expectException(ConfigurationException::class);

$set = new TranslationSet(
'Storefront',
'json',
new Protection(),
[],
new Filter(),
[],
[],
[]
);

$configuration = new Configuration([$set, $set]);

$this->validator->validateConfig($configuration);
}

/**
* @throws ConfigurationException
* @return void
*/
public function testLocalesWithoutNameLeadToException(): void
{
$this->expectException(ConfigurationException::class);

$locale = new Locale('', '', '');

$set = $this->buildTranslationSet([$locale], []);

$configuration = new Configuration([$set, $set]);

$this->validator->validateConfig($configuration);
}

/**
* @throws ConfigurationException
* @return void
*/
public function testLocalesWithSameNameLeadToException(): void
{
$this->expectException(ConfigurationException::class);

$locale = new Locale('DE', '', '');

$set = $this->buildTranslationSet([$locale, $locale], []);

$configuration = new Configuration([$set, $set]);

$this->validator->validateConfig($configuration);
}

/**
* @throws ConfigurationException
* @return void
*/
public function testLocalesWithNotExistingFileLeadToException(): void
{
$this->expectException(ConfigurationException::class);

$locale = new Locale('DE', 'not-existing.json', '');

$set = $this->buildTranslationSet([$locale], []);

$configuration = new Configuration([$set, $set]);

$this->validator->validateConfig($configuration);
}
}

0 comments on commit a7a384b

Please sign in to comment.