diff --git a/src/Sylius/Bundle/CoreBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/CoreBundle/DependencyInjection/Configuration.php index b89277adcf..b8d486cd4c 100644 --- a/src/Sylius/Bundle/CoreBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/CoreBundle/DependencyInjection/Configuration.php @@ -54,6 +54,10 @@ final class Configuration implements ConfigurationInterface ->setDeprecated('sylius/sylius', '1.10', 'The "%path%.%node%" parameter is deprecated and will be removed in 2.0.') ->defaultFalse() ->end() + ->integerNode('order_token_length') + ->defaultValue(64) + ->min(1)->max(255) + ->end() ->arrayNode('catalog_promotions') ->addDefaultsIfNotSet() ->children() diff --git a/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php b/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php index 365f52d41e..730a183fcd 100644 --- a/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php +++ b/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php @@ -61,6 +61,7 @@ final class SyliusCoreExtension extends AbstractResourceExtension implements Pre $container->setParameter('sylius_core.taxation.shipping_address_based_taxation', $config['shipping_address_based_taxation']); $container->setParameter('sylius_core.order_by_identifier', $config['order_by_identifier']); + $container->setParameter('sylius_core.order_token_length', $config['order_token_length']); $container->setParameter('sylius_core.catalog_promotions.batch_size', $config['catalog_promotions']['batch_size']); /** @var string $env */ diff --git a/src/Sylius/Bundle/CoreBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Sylius/Bundle/CoreBundle/Tests/DependencyInjection/ConfigurationTest.php index f2333fba14..96b65f34b6 100644 --- a/src/Sylius/Bundle/CoreBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Sylius/Bundle/CoreBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -72,6 +72,42 @@ final class ConfigurationTest extends TestCase ); } + /** @test */ + public function it_has_a_set_default_order_token_length(): void + { + $this->assertProcessedConfigurationEquals( + [[]], + ['order_token_length' => 64], + 'order_token_length', + ); + } + + /** @test */ + public function it_allows_changing_the_order_token_length(): void + { + $this->assertProcessedConfigurationEquals( + [['order_token_length' => 128]], + ['order_token_length' => 128], + 'order_token_length', + ); + } + + /** @test */ + public function it_throws_exception_when_order_token_length_is_invalid(): void + { + $this->assertConfigurationIsInvalid([['order_token_length' => 'string']]); + $this->assertConfigurationIsInvalid( + [['order_token_length' => 0]], + '/Should be greater than or equal to 1$/', + true, + ); + $this->assertConfigurationIsInvalid( + [['order_token_length' => 256]], + '/Should be less than or equal to 255$/', + true, + ); + } + /** @test */ public function it_throws_an_exception_if_value_other_then_integer_is_declared_as_batch_size(): void {