-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b56c0a9
commit a7a384b
Showing
1 changed file
with
168 additions
and
0 deletions.
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
tests/phpunit/Components/Configuration/Services/ConfigurationValidatorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |