Skip to content
Permalink
Browse files

add whitelist unique check

  • Loading branch information
Aleš
Aleš committed Sep 4, 2019
1 parent 837d5c8 commit 64688813ceee45c9dca1a426f7171aa7a4737245
Showing with 10 additions and 1 deletion.
  1. +7 −1 src/DI/TranslationExtension.php
  2. +3 −0 tests/Tests/DI/TranslationExtension.phpt
@@ -27,7 +27,13 @@ public function getConfigSchema(): Nette\Schema\Schema
'debugger' => Expect::bool(interface_exists(Tracy\IBarPanel::class)),
'logger' => Expect::mixed()->default(null),
'locales' => Expect::structure([
'whitelist' => Expect::array()->default(null), // @todo unique check?
'whitelist' => Expect::array()->default(null)->assert(function (array $array): bool {
if (count($array) !== count(array_unique($array))) {
throw new Contributte\Translation\Exceptions\InvalidArgument('Whitelist settings have not unique values.');
}
return true;
}),
'default' => Expect::string('en'),
'fallback' => Expect::array()->default(null),
]),
@@ -18,6 +18,9 @@ class TranslationExtension extends Tests\TestAbstract
public function test01(): void
{
Tester\Assert::exception(function (): void {
$this->createContainer(['locales' => ['whitelist' => ['en', 'en']]]);
}, Contributte\Translation\Exceptions\InvalidArgument::class, 'Whitelist settings have not unique values.');
Tester\Assert::exception(function (): void {
$this->createContainer(['localeResolvers' => [stdClass::class]]);
}, Contributte\Translation\Exceptions\InvalidArgument::class, 'Resolver must implement interface "' . Contributte\Translation\LocalesResolvers\ResolverInterface::class . '".');

0 comments on commit 6468881

Please sign in to comment.
You can’t perform that action at this time.