This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

251 lines
9.1 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
2017-02-08 07:24:27 +00:00
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
use Symfony\Bundle\FullStack;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Processor;
2017-02-08 07:24:27 +00:00
class ConfigurationTest extends TestCase
{
public function testDefaultConfig()
{
$processor = new Processor();
2014-05-10 23:14:12 +01:00
$config = $processor->processConfiguration(new Configuration(true), array(array('secret' => 's3cr3t')));
$this->assertEquals(
array_merge(array('secret' => 's3cr3t', 'trusted_hosts' => array()), self::getBundleDefaultConfig()),
$config
);
}
public function testDoNoDuplicateDefaultFormResources()
{
$input = array('templating' => array(
'form' => array('resources' => array('FrameworkBundle:Form')),
'engines' => array('php'),
));
$processor = new Processor();
2015-08-26 19:16:18 +01:00
$config = $processor->processConfiguration(new Configuration(true), array($input));
$this->assertEquals(array('FrameworkBundle:Form'), $config['templating']['form']['resources']);
}
public function testAssetsCanBeEnabled()
{
$processor = new Processor();
$configuration = new Configuration(true);
$config = $processor->processConfiguration($configuration, array(array('assets' => null)));
$defaultConfig = array(
'enabled' => true,
2016-01-25 21:22:29 +00:00
'version_strategy' => null,
'version' => null,
'version_format' => '%%s?%%s',
'base_path' => '',
'base_urls' => array(),
'packages' => array(),
'json_manifest_path' => null,
);
$this->assertEquals($defaultConfig, $config['assets']);
}
2016-01-25 21:22:29 +00:00
/**
* @dataProvider provideInvalidAssetConfigurationTests
2016-01-25 21:22:29 +00:00
*/
public function testInvalidAssetsConfiguration(array $assetConfig, $expectedMessage)
2016-01-25 21:22:29 +00:00
{
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(
InvalidConfigurationException::class,
$expectedMessage
);
if (method_exists($this, 'expectExceptionMessage')) {
$this->expectExceptionMessage($expectedMessage);
}
2016-01-25 21:22:29 +00:00
$processor = new Processor();
$configuration = new Configuration(true);
$processor->processConfiguration($configuration, array(
array(
'assets' => $assetConfig,
2016-01-25 21:22:29 +00:00
),
));
2016-01-25 21:22:29 +00:00
}
public function provideInvalidAssetConfigurationTests()
2016-01-25 21:22:29 +00:00
{
// helper to turn config into embedded package config
$createPackageConfig = function (array $packageConfig) {
return array(
'base_urls' => '//example.com',
'version' => 1,
'packages' => array(
'foo' => $packageConfig,
2016-01-25 21:22:29 +00:00
),
);
};
$config = array(
'version' => 1,
'version_strategy' => 'foo',
);
yield array($config, 'You cannot use both "version_strategy" and "version" at the same time under "assets".');
yield array($createPackageConfig($config), 'You cannot use both "version_strategy" and "version" at the same time under "assets" packages.');
$config = array(
'json_manifest_path' => '/foo.json',
'version_strategy' => 'foo',
);
yield array($config, 'You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets".');
yield array($createPackageConfig($config), 'You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets" packages.');
$config = array(
'json_manifest_path' => '/foo.json',
'version' => '1',
);
yield array($config, 'You cannot use both "version" and "json_manifest_path" at the same time under "assets".');
yield array($createPackageConfig($config), 'You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.');
2016-01-25 21:22:29 +00:00
}
protected static function getBundleDefaultConfig()
{
return array(
'http_method_override' => true,
2014-10-22 19:27:13 +01:00
'ide' => null,
'default_locale' => 'en',
'csrf_protection' => array(
'enabled' => false,
),
Merge branch '2.3' into 2.5 * 2.3: Remove aligned '=>' and '=' Break infinite loop while resolving aliases [Security][listener] change priority of switchuser Improved the phpdoc for security token classes bumped Symfony version to 2.3.22 updated VERSION for 2.3.21 update CONTRIBUTORS for 2.3.21 updated CHANGELOG for 2.3.21 Conflicts: src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php src/Symfony/Bridge/Propel1/Form/Type/ModelType.php src/Symfony/Bridge/Propel1/Logger/PropelLogger.php src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Controller/LocalizedController.php src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Controller/LoginController.php src/Symfony/Component/Console/Descriptor/JsonDescriptor.php src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php src/Symfony/Component/Console/Helper/ProgressHelper.php src/Symfony/Component/Debug/ErrorHandler.php src/Symfony/Component/DependencyInjection/Container.php src/Symfony/Component/Finder/Shell/Command.php src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php src/Symfony/Component/Form/Extension/Core/Type/FormType.php src/Symfony/Component/Form/Extension/Core/Type/IntegerType.php src/Symfony/Component/Form/Extension/Core/Type/NumberType.php src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php src/Symfony/Component/HttpFoundation/File/UploadedFile.php src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php src/Symfony/Component/HttpKernel/Kernel.php src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php src/Symfony/Component/HttpKernel/Tests/HttpCache/TestMultipleHttpKernel.php src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php src/Symfony/Component/Routing/Route.php src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php src/Symfony/Component/Security/Tests/Core/Validator/Constraints/UserPasswordValidatorTest.php src/Symfony/Component/Templating/PhpEngine.php src/Symfony/Component/Validator/Constraints/ImageValidator.php src/Symfony/Component/Validator/Constraints/TypeValidator.php
2014-10-26 07:41:27 +00:00
'form' => array(
'enabled' => !class_exists(FullStack::class),
'csrf_protection' => array(
'enabled' => null, // defaults to csrf_protection.enabled
'field_name' => '_token',
),
),
2014-10-22 19:27:13 +01:00
'esi' => array('enabled' => false),
Merge branch '2.5' * 2.5: Remove aligned '=>' and '=' Break infinite loop while resolving aliases [Security][listener] change priority of switchuser Improved the phpdoc for security token classes bumped Symfony version to 2.5.7 updated VERSION for 2.5.6 updated CHANGELOG for 2.5.6 bumped Symfony version to 2.3.22 updated VERSION for 2.3.21 update CONTRIBUTORS for 2.3.21 updated CHANGELOG for 2.3.21 Conflicts: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php src/Symfony/Component/Debug/ErrorHandler.php src/Symfony/Component/Debug/ExceptionHandler.php src/Symfony/Component/Form/Extension/Core/Type/BaseType.php src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php src/Symfony/Component/Form/Extension/Core/Type/DateType.php src/Symfony/Component/Form/Extension/Core/Type/TimeType.php src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php src/Symfony/Component/HttpFoundation/Request.php src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php src/Symfony/Component/HttpKernel/Kernel.php src/Symfony/Component/Security/Core/SecurityContextInterface.php src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationFailureHandler.php src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php src/Symfony/Component/Serializer/Serializer.php src/Symfony/Component/Validator/Constraints/File.php
2014-10-26 07:46:28 +00:00
'ssi' => array('enabled' => false),
2014-10-22 19:27:13 +01:00
'fragments' => array(
'enabled' => false,
2014-10-22 19:27:13 +01:00
'path' => '/_fragment',
),
2014-10-22 19:27:13 +01:00
'profiler' => array(
'enabled' => false,
'only_exceptions' => false,
'only_master_requests' => false,
2014-10-22 19:27:13 +01:00
'dsn' => 'file:%kernel.cache_dir%/profiler',
'collect' => true,
'matcher' => array(
'enabled' => false,
'ips' => array(),
),
),
2014-10-22 19:27:13 +01:00
'translator' => array(
'enabled' => !class_exists(FullStack::class),
'fallbacks' => array('en'),
2014-11-04 14:29:39 +00:00
'logging' => true,
'formatter' => 'translator.formatter.default',
'paths' => array(),
),
2014-10-22 19:27:13 +01:00
'validation' => array(
'enabled' => !class_exists(FullStack::class),
'enable_annotations' => !class_exists(FullStack::class),
2014-10-30 20:17:55 +00:00
'static_method' => array('loadValidatorMetadata'),
'translation_domain' => 'validators',
2014-10-30 20:17:55 +00:00
'strict_email' => false,
'mapping' => array(
'paths' => array(),
),
),
2014-10-22 19:27:13 +01:00
'annotations' => array(
'cache' => 'php_array',
'file_cache_dir' => '%kernel.cache_dir%/annotations',
2016-03-12 17:49:05 +00:00
'debug' => true,
'enabled' => true,
),
2014-10-22 19:27:13 +01:00
'serializer' => array(
'enabled' => !class_exists(FullStack::class),
'enable_annotations' => !class_exists(FullStack::class),
'mapping' => array('paths' => array()),
),
'property_access' => array(
'magic_call' => false,
'throw_exception_on_invalid_index' => false,
),
2015-09-28 12:22:50 +01:00
'property_info' => array(
'enabled' => false,
),
'router' => array(
'enabled' => false,
'http_port' => 80,
'https_port' => 443,
'strict_requirements' => true,
),
'session' => array(
'enabled' => false,
'storage_id' => 'session.storage.native',
'handler_id' => 'session.handler.native_file',
'cookie_httponly' => true,
'gc_probability' => 1,
'save_path' => '%kernel.cache_dir%/sessions',
'metadata_update_threshold' => '0',
),
'request' => array(
'enabled' => false,
'formats' => array(),
),
'templating' => array(
'enabled' => false,
'hinclude_default_template' => null,
'form' => array(
'resources' => array('FrameworkBundle:Form'),
),
'engines' => array(),
'loaders' => array(),
),
'assets' => array(
'enabled' => !class_exists(FullStack::class),
'version_strategy' => null,
'version' => null,
'version_format' => '%%s?%%s',
'base_path' => '',
'base_urls' => array(),
'packages' => array(),
'json_manifest_path' => null,
),
'cache' => array(
'pools' => array(),
'app' => 'cache.adapter.filesystem',
'system' => 'cache.adapter.system',
'directory' => '%kernel.cache_dir%/pools',
'default_redis_provider' => 'redis://localhost',
'default_memcached_provider' => 'memcached://localhost',
),
'workflows' => array(
'enabled' => false,
'workflows' => array(),
),
'php_errors' => array(
'log' => true,
'throw' => true,
),
2017-04-04 12:58:36 +01:00
'web_link' => array(
'enabled' => !class_exists(FullStack::class),
),
);
}
}