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/FrameworkExtensionTest.php

1385 lines
66 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;
use Doctrine\Common\Annotations\Annotation;
use Psr\Log\LoggerAwareInterface;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
refactored configuration names How to upgrade (have a look at the skeleton): * the "web:config" namespace is now "app:config" - <web:config csrf-secret="xxxxxxxxxx" charset="UTF-8" error-handler="null"> - <web:router resource="%kernel.root_dir%/config/routing.xml" /> - <web:validation enabled="true" annotations="true" /> - </web:config> + <app:config csrf-secret="xxxxxxxxxx" charset="UTF-8" error-handler="null"> + <app:router resource="%kernel.root_dir%/config/routing.xml" /> + <app:validation enabled="true" annotations="true" /> + </app:config> * the "web:templating" namespace is now a sub-namespace of "app:config" - <web:templating - escaping="htmlspecialchars" - /> + <app:config> + <app:templating escaping="htmlspecialchars" /> + </app:config> * the "web:user" namespace is now a sub-namespace of "app:config" - <web:user default-locale="fr"> - <web:session name="SYMFONY" type="Native" lifetime="3600" /> - </web:user> + <app:config> + <app:user default-locale="fr"> + <app:session name="SYMFONY" type="Native" lifetime="3600" /> + </app:user> + </app:config> * the "web:test" namespace is now a sub-namespace of "app:config" - <web:test /> + <app:config error_handler="false"> + <app:test /> + </app:config> * the "swift:mailer" namespace is now "swiftmailer:config" - <swift:mailer + <swiftmailer:config transport="smtp" encryption="ssl" auth_mode="login" * the "zend:logger" namespace is now a sub-namespace of "zend:config" - <zend:logger - priority="info" - path="%kernel.logs_dir%/%kernel.environment%.log" - /> + <zend:config> + <zend:logger priority="info" path="%kernel.logs_dir%/%kernel.environment%.log" /> + </zend:config>
2010-09-20 20:01:41 +01:00
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
2018-07-26 10:03:18 +01:00
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FullStack;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\ChainAdapter;
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\ProxyAdapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\DependencyInjection\LoggerPass;
2018-04-27 20:23:37 +01:00
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Tests\Fixtures\SecondMessage;
use Symfony\Component\Messenger\Transport\TransportFactory;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
use Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
use Symfony\Component\Validator\Validation;
2018-02-08 17:13:25 +00:00
use Symfony\Component\Workflow;
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
abstract class FrameworkExtensionTest extends TestCase
{
private static $containerCache = array();
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
abstract protected function loadFromFile(ContainerBuilder $container, $file);
public function testFormCsrfProtection()
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
{
$container = $this->createContainerFromFile('full');
$def = $container->getDefinition('form.type_extension.csrf');
$this->assertTrue($container->getParameter('form.type_extension.csrf.enabled'));
$this->assertEquals('%form.type_extension.csrf.enabled%', $def->getArgument(1));
$this->assertEquals('_csrf', $container->getParameter('form.type_extension.csrf.field_name'));
$this->assertEquals('%form.type_extension.csrf.field_name%', $def->getArgument(2));
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
public function testPropertyAccessWithDefaultValue()
{
$container = $this->createContainerFromFile('full');
$def = $container->getDefinition('property_accessor');
2014-09-20 01:33:54 +01:00
$this->assertFalse($def->getArgument(0));
$this->assertFalse($def->getArgument(1));
}
public function testPropertyAccessWithOverriddenValues()
{
$container = $this->createContainerFromFile('property_accessor');
$def = $container->getDefinition('property_accessor');
2014-09-20 01:33:54 +01:00
$this->assertTrue($def->getArgument(0));
$this->assertTrue($def->getArgument(1));
}
public function testPropertyAccessCache()
{
$container = $this->createContainerFromFile('property_accessor');
if (!method_exists(PropertyAccessor::class, 'createCache')) {
return $this->assertFalse($container->hasDefinition('cache.property_access'));
}
$cache = $container->getDefinition('cache.property_access');
$this->assertSame(array(PropertyAccessor::class, 'createCache'), $cache->getFactory(), 'PropertyAccessor::createCache() should be used in non-debug mode');
$this->assertSame(AdapterInterface::class, $cache->getClass());
}
public function testPropertyAccessCacheWithDebug()
{
$container = $this->createContainerFromFile('property_accessor', array('kernel.debug' => true));
if (!method_exists(PropertyAccessor::class, 'createCache')) {
return $this->assertFalse($container->hasDefinition('cache.property_access'));
}
$cache = $container->getDefinition('cache.property_access');
$this->assertNull($cache->getFactory());
$this->assertSame(ArrayAdapter::class, $cache->getClass(), 'ArrayAdapter should be used in debug mode');
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage CSRF protection needs sessions to be enabled.
*/
public function testCsrfProtectionNeedsSessionToBeEnabled()
{
$this->createContainerFromFile('csrf_needs_session');
}
public function testCsrfProtectionForFormsEnablesCsrfProtectionAutomatically()
{
$container = $this->createContainerFromFile('csrf');
$this->assertTrue($container->hasDefinition('security.csrf.token_manager'));
}
public function testHttpMethodOverride()
{
$container = $this->createContainerFromFile('full');
$this->assertFalse($container->getParameter('kernel.http_method_override'));
}
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
public function testEsi()
{
$container = $this->createContainerFromFile('full');
$this->assertTrue($container->hasDefinition('esi'), '->registerEsiConfiguration() loads esi.xml');
2017-06-22 20:48:55 +01:00
$this->assertTrue($container->hasDefinition('fragment.renderer.esi'), 'The ESI fragment renderer is registered');
}
public function testEsiDisabled()
{
$container = $this->createContainerFromFile('esi_disabled');
$this->assertFalse($container->hasDefinition('fragment.renderer.esi'), 'The ESI fragment renderer is not registered');
$this->assertFalse($container->hasDefinition('esi'));
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
public function testSsi()
{
$container = $this->createContainerFromFile('full');
$this->assertTrue($container->hasDefinition('ssi'), '->registerSsiConfiguration() loads ssi.xml');
2017-06-22 20:48:55 +01:00
$this->assertTrue($container->hasDefinition('fragment.renderer.ssi'), 'The SSI fragment renderer is registered');
}
public function testSsiDisabled()
{
$container = $this->createContainerFromFile('ssi_disabled');
$this->assertFalse($container->hasDefinition('fragment.renderer.ssi'), 'The SSI fragment renderer is not registered');
$this->assertFalse($container->hasDefinition('ssi'));
2017-06-22 20:48:55 +01:00
}
public function testEsiAndSsiWithoutFragments()
{
$container = $this->createContainerFromFile('esi_and_ssi_without_fragments');
$this->assertFalse($container->hasDefinition('fragment.renderer.hinclude'), 'The HInclude fragment renderer is not registered');
$this->assertTrue($container->hasDefinition('fragment.renderer.esi'), 'The ESI fragment renderer is registered');
$this->assertTrue($container->hasDefinition('fragment.renderer.ssi'), 'The SSI fragment renderer is registered');
}
public function testEnabledProfiler()
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
{
$container = $this->createContainerFromFile('profiler');
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$this->assertTrue($container->hasDefinition('profiler'), '->registerProfilerConfiguration() loads profiling.xml');
$this->assertTrue($container->hasDefinition('data_collector.config'), '->registerProfilerConfiguration() loads collectors.xml');
2013-02-14 15:42:17 +00:00
}
public function testDisabledProfiler()
{
$container = $this->createContainerFromFile('full');
2013-02-14 15:42:17 +00:00
$this->assertFalse($container->hasDefinition('profiler'), '->registerProfilerConfiguration() does not load profiling.xml');
$this->assertFalse($container->hasDefinition('data_collector.config'), '->registerProfilerConfiguration() does not load collectors.xml');
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
public function testWorkflows()
2016-03-25 15:43:30 +00:00
{
$container = $this->createContainerFromFile('workflows');
$this->assertTrue($container->hasDefinition('workflow.article'), 'Workflow is registered as a service');
$this->assertSame('workflow.abstract', $container->getDefinition('workflow.article')->getParent());
$this->assertTrue($container->hasDefinition('workflow.article.definition'), 'Workflow definition is registered as a service');
$workflowDefinition = $container->getDefinition('workflow.article.definition');
$this->assertSame(
array(
'draft',
'wait_for_journalist',
'approved_by_journalist',
'wait_for_spellchecker',
'approved_by_spellchecker',
'published',
),
$workflowDefinition->getArgument(0),
'Places are passed to the workflow definition'
);
$this->assertSame(array('workflow.definition' => array(array('name' => 'article', 'type' => 'workflow', 'marking_store' => 'multiple_state'))), $workflowDefinition->getTags());
2018-02-08 17:13:25 +00:00
$this->assertCount(4, $workflowDefinition->getArgument(1));
$this->assertSame('draft', $workflowDefinition->getArgument(2));
$this->assertTrue($container->hasDefinition('state_machine.pull_request'), 'State machine is registered as a service');
$this->assertSame('state_machine.abstract', $container->getDefinition('state_machine.pull_request')->getParent());
$this->assertTrue($container->hasDefinition('state_machine.pull_request.definition'), 'State machine definition is registered as a service');
$stateMachineDefinition = $container->getDefinition('state_machine.pull_request.definition');
$this->assertSame(
array(
'start',
'coding',
'travis',
'review',
'merged',
'closed',
),
$stateMachineDefinition->getArgument(0),
'Places are passed to the state machine definition'
);
$this->assertSame(array('workflow.definition' => array(array('name' => 'pull_request', 'type' => 'state_machine', 'marking_store' => 'single_state'))), $stateMachineDefinition->getTags());
$this->assertCount(9, $stateMachineDefinition->getArgument(1));
$this->assertSame('start', $stateMachineDefinition->getArgument(2));
2018-02-08 17:13:25 +00:00
$metadataStoreDefinition = $stateMachineDefinition->getArgument(3);
$this->assertInstanceOf(Definition::class, $metadataStoreDefinition);
$this->assertSame(Workflow\Metadata\InMemoryMetadataStore::class, $metadataStoreDefinition->getClass());
$workflowMetadata = $metadataStoreDefinition->getArgument(0);
$this->assertSame(array('title' => 'workflow title'), $workflowMetadata);
$placesMetadata = $metadataStoreDefinition->getArgument(1);
$this->assertArrayHasKey('start', $placesMetadata);
$this->assertSame(array('title' => 'place start title'), $placesMetadata['start']);
$transitionsMetadata = $metadataStoreDefinition->getArgument(2);
$this->assertSame(\SplObjectStorage::class, $transitionsMetadata->getClass());
$transitionsMetadataCall = $transitionsMetadata->getMethodCalls()[0];
$this->assertSame('attach', $transitionsMetadataCall[0]);
$params = $transitionsMetadataCall[1];
$this->assertCount(2, $params);
$this->assertInstanceOf(Definition::class, $params[0]);
$this->assertSame(Workflow\Transition::class, $params[0]->getClass());
$this->assertSame(array('submit', 'start', 'travis'), $params[0]->getArguments());
$this->assertSame(array('title' => 'transition submit title'), $params[1]);
$serviceMarkingStoreWorkflowDefinition = $container->getDefinition('workflow.service_marking_store_workflow');
/** @var Reference $markingStoreRef */
$markingStoreRef = $serviceMarkingStoreWorkflowDefinition->getArgument(1);
$this->assertInstanceOf(Reference::class, $markingStoreRef);
$this->assertEquals('workflow_service', (string) $markingStoreRef);
2018-07-16 15:05:32 +01:00
$this->assertTrue($container->hasDefinition('workflow.registry'), 'Workflow registry is registered as a service');
$registryDefinition = $container->getDefinition('workflow.registry');
$this->assertGreaterThan(0, \count($registryDefinition->getMethodCalls()));
2016-03-25 15:43:30 +00:00
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage "type" and "service" cannot be used together.
*/
public function testWorkflowCannotHaveBothTypeAndService()
{
$this->createContainerFromFile('workflow_with_type_and_service');
}
2017-01-18 14:08:35 +00:00
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage "supports" and "support_strategy" cannot be used together.
*/
public function testWorkflowCannotHaveBothSupportsAndSupportStrategy()
{
$this->createContainerFromFile('workflow_with_support_and_support_strategy');
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage "supports" or "support_strategy" should be configured.
*/
public function testWorkflowShouldHaveOneOfSupportsAndSupportStrategy()
{
$this->createContainerFromFile('workflow_without_support_and_support_strategy');
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage "arguments" and "service" cannot be used together.
*/
public function testWorkflowCannotHaveBothArgumentsAndService()
{
$this->createContainerFromFile('workflow_with_arguments_and_service');
}
public function testWorkflowMultipleTransitionsWithSameName()
{
$container = $this->createContainerFromFile('workflow_with_multiple_transitions_with_same_name');
$this->assertTrue($container->hasDefinition('workflow.article'), 'Workflow is registered as a service');
$this->assertTrue($container->hasDefinition('workflow.article.definition'), 'Workflow definition is registered as a service');
$workflowDefinition = $container->getDefinition('workflow.article.definition');
$transitions = $workflowDefinition->getArgument(1);
$this->assertCount(5, $transitions);
$this->assertSame('request_review', $transitions[0]->getArgument(0));
$this->assertSame('journalist_approval', $transitions[1]->getArgument(0));
$this->assertSame('spellchecker_approval', $transitions[2]->getArgument(0));
$this->assertSame('publish', $transitions[3]->getArgument(0));
$this->assertSame('publish', $transitions[4]->getArgument(0));
$this->assertSame(array('approved_by_journalist', 'approved_by_spellchecker'), $transitions[3]->getArgument(1));
$this->assertSame(array('draft'), $transitions[4]->getArgument(1));
}
public function testWorkflowServicesCanBeEnabled()
{
$container = $this->createContainerFromFile('workflows_enabled');
2018-02-08 17:13:25 +00:00
$this->assertTrue($container->has(Workflow\Registry::class));
$this->assertTrue($container->hasDefinition('console.command.workflow_dump'));
}
public function testEnabledPhpErrorsConfig()
{
$container = $this->createContainerFromFile('php_errors_enabled');
$definition = $container->getDefinition('debug.debug_handlers_listener');
$this->assertEquals(new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE), $definition->getArgument(1));
$this->assertNull($definition->getArgument(2));
$this->assertSame(-1, $container->getParameter('debug.error_handler.throw_at'));
}
public function testDisabledPhpErrorsConfig()
{
$container = $this->createContainerFromFile('php_errors_disabled');
$definition = $container->getDefinition('debug.debug_handlers_listener');
$this->assertNull($definition->getArgument(1));
$this->assertNull($definition->getArgument(2));
$this->assertSame(0, $container->getParameter('debug.error_handler.throw_at'));
}
2018-04-02 09:50:34 +01:00
public function testPhpErrorsWithLogLevel()
{
$container = $this->createContainerFromFile('php_errors_log_level');
$definition = $container->getDefinition('debug.debug_handlers_listener');
$this->assertEquals(new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE), $definition->getArgument(1));
$this->assertSame(8, $definition->getArgument(2));
2018-04-02 09:50:34 +01:00
}
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
public function testRouter()
{
$container = $this->createContainerFromFile('full');
2011-07-18 09:10:04 +01:00
$this->assertTrue($container->has('router'), '->registerRouterConfiguration() loads routing.xml');
$arguments = $container->findDefinition('router')->getArguments();
$this->assertEquals($container->getParameter('kernel.project_dir').'/config/routing.xml', $container->getParameter('router.resource'), '->registerRouterConfiguration() sets routing resource');
$this->assertEquals('%router.resource%', $arguments[1], '->registerRouterConfiguration() sets routing resource');
$this->assertEquals('xml', $arguments[2]['resource_type'], '->registerRouterConfiguration() sets routing resource type');
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
*/
public function testRouterRequiresResourceOption()
{
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$container = $this->createContainer();
refactored configuration names How to upgrade (have a look at the skeleton): * the "web:config" namespace is now "app:config" - <web:config csrf-secret="xxxxxxxxxx" charset="UTF-8" error-handler="null"> - <web:router resource="%kernel.root_dir%/config/routing.xml" /> - <web:validation enabled="true" annotations="true" /> - </web:config> + <app:config csrf-secret="xxxxxxxxxx" charset="UTF-8" error-handler="null"> + <app:router resource="%kernel.root_dir%/config/routing.xml" /> + <app:validation enabled="true" annotations="true" /> + </app:config> * the "web:templating" namespace is now a sub-namespace of "app:config" - <web:templating - escaping="htmlspecialchars" - /> + <app:config> + <app:templating escaping="htmlspecialchars" /> + </app:config> * the "web:user" namespace is now a sub-namespace of "app:config" - <web:user default-locale="fr"> - <web:session name="SYMFONY" type="Native" lifetime="3600" /> - </web:user> + <app:config> + <app:user default-locale="fr"> + <app:session name="SYMFONY" type="Native" lifetime="3600" /> + </app:user> + </app:config> * the "web:test" namespace is now a sub-namespace of "app:config" - <web:test /> + <app:config error_handler="false"> + <app:test /> + </app:config> * the "swift:mailer" namespace is now "swiftmailer:config" - <swift:mailer + <swiftmailer:config transport="smtp" encryption="ssl" auth_mode="login" * the "zend:logger" namespace is now a sub-namespace of "zend:config" - <zend:logger - priority="info" - path="%kernel.logs_dir%/%kernel.environment%.log" - /> + <zend:config> + <zend:logger priority="info" path="%kernel.logs_dir%/%kernel.environment%.log" /> + </zend:config>
2010-09-20 20:01:41 +01:00
$loader = new FrameworkExtension();
$loader->load(array(array('router' => true)), $container);
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
public function testSession()
{
$container = $this->createContainerFromFile('full');
$this->assertTrue($container->hasDefinition('session'), '->registerSessionConfiguration() loads session.xml');
$this->assertEquals('fr', $container->getParameter('kernel.default_locale'));
$this->assertEquals('session.storage.native', (string) $container->getAlias('session.storage'));
$this->assertEquals('session.handler.native_file', (string) $container->getAlias('session.handler'));
2011-03-02 18:51:17 +00:00
$options = $container->getParameter('session.storage.options');
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$this->assertEquals('_SYMFONY', $options['name']);
$this->assertEquals(86400, $options['cookie_lifetime']);
$this->assertEquals('/', $options['cookie_path']);
$this->assertEquals('example.com', $options['cookie_domain']);
$this->assertTrue($options['cookie_secure']);
$this->assertFalse($options['cookie_httponly']);
$this->assertTrue($options['use_cookies']);
$this->assertEquals(108, $options['gc_divisor']);
$this->assertEquals(1, $options['gc_probability']);
$this->assertEquals(90000, $options['gc_maxlifetime']);
$this->assertEquals('/path/to/sessions', $container->getParameter('session.save_path'));
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
public function testNullSessionHandler()
{
$container = $this->createContainerFromFile('session');
$this->assertTrue($container->hasDefinition('session'), '->registerSessionConfiguration() loads session.xml');
$this->assertNull($container->getDefinition('session.storage.native')->getArgument(1));
$this->assertNull($container->getDefinition('session.storage.php_bridge')->getArgument(0));
$expected = array('session', 'initialized_session');
$this->assertEquals($expected, array_keys($container->getDefinition('session_listener')->getArgument(0)->getValues()));
}
public function testRequest()
{
$container = $this->createContainerFromFile('full');
$this->assertTrue($container->hasDefinition('request.add_request_formats_listener'), '->registerRequestConfiguration() loads request.xml');
$listenerDef = $container->getDefinition('request.add_request_formats_listener');
$this->assertEquals(array('csv' => array('text/csv', 'text/plain'), 'pdf' => array('application/pdf')), $listenerDef->getArgument(0));
}
public function testEmptyRequestFormats()
{
$container = $this->createContainerFromFile('request');
$this->assertFalse($container->hasDefinition('request.add_request_formats_listener'), '->registerRequestConfiguration() does not load request.xml when no request formats are defined');
}
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
public function testTemplating()
{
$container = $this->createContainerFromFile('full');
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$this->assertTrue($container->hasDefinition('templating.name_parser'), '->registerTemplatingConfiguration() loads templating.xml');
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$this->assertEquals('templating.engine.delegating', (string) $container->getAlias('templating'), '->registerTemplatingConfiguration() configures delegating loader if multiple engines are provided');
$this->assertEquals($container->getDefinition('templating.loader.chain'), $container->getDefinition('templating.loader.wrapped'), '->registerTemplatingConfiguration() configures loader chain if multiple loaders are provided');
$this->assertEquals($container->getDefinition('templating.loader'), $container->getDefinition('templating.loader.cache'), '->registerTemplatingConfiguration() configures the loader to use cache');
$this->assertEquals('%templating.loader.cache.path%', $container->getDefinition('templating.loader.cache')->getArgument(1));
$this->assertEquals('/path/to/cache', $container->getParameter('templating.loader.cache.path'));
$this->assertEquals(array('php', 'twig'), $container->getParameter('templating.engines'), '->registerTemplatingConfiguration() sets a templating.engines parameter');
$this->assertEquals(array('FrameworkBundle:Form', 'theme1', 'theme2'), $container->getParameter('templating.helper.form.resources'), '->registerTemplatingConfiguration() registers the theme and adds the base theme');
$this->assertEquals('global_hinclude_template', $container->getParameter('fragment.renderer.hinclude.global_template'), '->registerTemplatingConfiguration() registers the global hinclude.js template');
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
public function testTemplatingCanBeDisabled()
{
$container = $this->createContainerFromFile('templating_disabled');
$this->assertFalse($container->hasParameter('templating.engines'), '"templating.engines" container parameter is not registered when templating is disabled.');
}
2015-02-12 09:20:19 +00:00
public function testAssets()
{
2015-02-12 09:20:19 +00:00
$container = $this->createContainerFromFile('assets');
$packages = $container->getDefinition('assets.packages');
2015-02-12 09:20:19 +00:00
// default package
2017-01-10 07:04:52 +00:00
$defaultPackage = $container->getDefinition((string) $packages->getArgument(0));
2015-02-12 09:20:19 +00:00
$this->assertUrlPackage($container, $defaultPackage, array('http://cdn.example.com'), 'SomeVersionScheme', '%%s?version=%%s');
2015-02-12 09:20:19 +00:00
// packages
$packages = $packages->getArgument(1);
$this->assertCount(6, $packages);
2015-02-12 09:20:19 +00:00
2017-01-10 07:04:52 +00:00
$package = $container->getDefinition((string) $packages['images_path']);
2015-02-12 09:20:19 +00:00
$this->assertPathPackage($container, $package, '/foo', 'SomeVersionScheme', '%%s?version=%%s');
2017-01-10 07:04:52 +00:00
$package = $container->getDefinition((string) $packages['images']);
2015-02-12 09:20:19 +00:00
$this->assertUrlPackage($container, $package, array('http://images1.example.com', 'http://images2.example.com'), '1.0.0', '%%s?version=%%s');
2017-01-10 07:04:52 +00:00
$package = $container->getDefinition((string) $packages['foo']);
2015-02-12 09:20:19 +00:00
$this->assertPathPackage($container, $package, '', '1.0.0', '%%s-%%s');
2017-01-10 07:04:52 +00:00
$package = $container->getDefinition((string) $packages['bar']);
2015-02-12 09:20:19 +00:00
$this->assertUrlPackage($container, $package, array('https://bar2.example.com'), 'SomeVersionScheme', '%%s?version=%%s');
2016-01-25 21:22:29 +00:00
2017-01-10 07:04:52 +00:00
$package = $container->getDefinition((string) $packages['bar_version_strategy']);
2016-01-25 21:22:29 +00:00
$this->assertEquals('assets.custom_version_strategy', (string) $package->getArgument(1));
$package = $container->getDefinition((string) $packages['json_manifest_strategy']);
$versionStrategy = $container->getDefinition((string) $package->getArgument(1));
$this->assertEquals('assets.json_manifest_version_strategy', $versionStrategy->getParent());
$this->assertEquals('/path/to/manifest.json', $versionStrategy->getArgument(0));
2016-01-25 21:22:29 +00:00
}
public function testAssetsDefaultVersionStrategyAsService()
{
$container = $this->createContainerFromFile('assets_version_strategy_as_service');
$packages = $container->getDefinition('assets.packages');
// default package
2017-01-10 07:04:52 +00:00
$defaultPackage = $container->getDefinition((string) $packages->getArgument(0));
2016-01-25 21:22:29 +00:00
$this->assertEquals('assets.custom_version_strategy', (string) $defaultPackage->getArgument(1));
}
public function testAssetsCanBeDisabled()
{
$container = $this->createContainerFromFile('assets_disabled');
$this->assertFalse($container->has('templating.helper.assets'), 'The templating.helper.assets helper service is removed when assets are disabled.');
}
2017-04-04 12:58:36 +01:00
public function testWebLink()
{
2017-04-04 12:58:36 +01:00
$container = $this->createContainerFromFile('web_link');
$this->assertTrue($container->hasDefinition('web_link.add_link_header_listener'));
}
public function testMessenger()
{
$container = $this->createContainerFromFile('messenger');
$this->assertTrue($container->hasAlias('message_bus'));
2018-08-17 13:07:19 +01:00
$this->assertTrue($container->getAlias('message_bus')->isPublic());
$this->assertFalse($container->hasDefinition('messenger.transport.amqp.factory'));
$this->assertTrue($container->hasDefinition('messenger.transport_factory'));
$this->assertSame(TransportFactory::class, $container->getDefinition('messenger.transport_factory')->getClass());
}
public function testMessengerTransports()
2018-03-13 16:34:51 +00:00
{
$container = $this->createContainerFromFile('messenger_transports');
$this->assertTrue($container->hasDefinition('messenger.transport.default'));
$this->assertTrue($container->getDefinition('messenger.transport.default')->hasTag('messenger.receiver'));
$this->assertTrue($container->getDefinition('messenger.transport.default')->hasTag('messenger.sender'));
2018-05-10 22:13:07 +01:00
$this->assertEquals(array(array('alias' => 'default')), $container->getDefinition('messenger.transport.default')->getTag('messenger.receiver'));
$this->assertEquals(array(array('alias' => 'default')), $container->getDefinition('messenger.transport.default')->getTag('messenger.sender'));
$this->assertTrue($container->hasDefinition('messenger.transport.customised'));
$transportFactory = $container->getDefinition('messenger.transport.customised')->getFactory();
$transportArguments = $container->getDefinition('messenger.transport.customised')->getArguments();
$this->assertEquals(array(new Reference('messenger.transport_factory'), 'createTransport'), $transportFactory);
$this->assertCount(2, $transportArguments);
$this->assertSame('amqp://localhost/%2f/messages?exchange_name=exchange_name', $transportArguments[0]);
$this->assertSame(array('queue' => array('name' => 'Queue')), $transportArguments[1]);
$this->assertTrue($container->hasDefinition('messenger.transport.amqp.factory'));
2018-03-13 16:34:51 +00:00
}
2018-04-27 20:23:37 +01:00
public function testMessengerRouting()
{
$container = $this->createContainerFromFile('messenger_routing');
$senderLocatorDefinition = $container->getDefinition('messenger.asynchronous.routing.sender_locator');
$sendMessageMiddlewareDefinition = $container->getDefinition('messenger.middleware.route_messages');
2018-04-27 20:23:37 +01:00
$messageToSenderIdsMapping = array(
DummyMessage::class => '.messenger.chain_sender.'.DummyMessage::class,
SecondMessage::class => '.messenger.chain_sender.'.SecondMessage::class,
'*' => 'amqp',
);
$messageToSendAndHandleMapping = array(
DummyMessage::class => false,
SecondMessage::class => true,
'*' => false,
2018-04-27 20:23:37 +01:00
);
$this->assertSame($messageToSenderIdsMapping, $senderLocatorDefinition->getArgument(1));
$this->assertSame($messageToSendAndHandleMapping, $sendMessageMiddlewareDefinition->getArgument(1));
$this->assertEquals(array(new Reference('messenger.transport.amqp'), new Reference('audit')), $container->getDefinition('.messenger.chain_sender.'.DummyMessage::class)->getArgument(0));
2018-04-27 20:23:37 +01:00
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
* @expectedExceptionMessage The default Messenger serializer cannot be enabled as the Serializer support is not available. Try enable it or install it by running "composer require symfony/serializer-pack".
*/
public function testMessengerTransportConfigurationWithoutSerializer()
{
$this->createContainerFromFile('messenger_transport_no_serializer');
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
* @expectedExceptionMessage The default AMQP transport is not available. Make sure you have installed and enabled the Serializer component. Try enable it or install it by running "composer require symfony/serializer-pack".
*/
public function testMessengerAMQPTransportConfigurationWithoutSerializer()
{
$this->createContainerFromFile('messenger_amqp_transport_no_serializer');
}
public function testMessengerTransportConfiguration()
{
$container = $this->createContainerFromFile('messenger_transport');
$this->assertSame('messenger.transport.symfony_serializer', (string) $container->getAlias('messenger.transport.serializer'));
$serializerTransportDefinition = $container->getDefinition('messenger.transport.symfony_serializer');
$this->assertSame('csv', $serializerTransportDefinition->getArgument(1));
$this->assertSame(array('enable_max_depth' => true), $serializerTransportDefinition->getArgument(2));
}
public function testMessengerWithMultipleBuses()
{
$container = $this->createContainerFromFile('messenger_multiple_buses');
$this->assertTrue($container->has('messenger.bus.commands'));
$this->assertSame(array(), $container->getDefinition('messenger.bus.commands')->getArgument(0));
$this->assertEquals(array(
array('id' => 'logging'),
array('id' => 'route_messages'),
array('id' => 'call_message_handler'),
), $container->getParameter('messenger.bus.commands.middleware'));
$this->assertTrue($container->has('messenger.bus.events'));
$this->assertSame(array(), $container->getDefinition('messenger.bus.events')->getArgument(0));
$this->assertEquals(array(
array('id' => 'logging'),
array('id' => 'with_factory', 'arguments' => array('foo', true, array('bar' => 'baz'))),
array('id' => 'allow_no_handler', 'arguments' => array()),
array('id' => 'route_messages'),
array('id' => 'call_message_handler'),
), $container->getParameter('messenger.bus.events.middleware'));
$this->assertTrue($container->has('messenger.bus.queries'));
$this->assertSame(array(), $container->getDefinition('messenger.bus.queries')->getArgument(0));
$this->assertEquals(array(
array('id' => 'route_messages', 'arguments' => array()),
array('id' => 'allow_no_handler', 'arguments' => array()),
array('id' => 'call_message_handler', 'arguments' => array()),
), $container->getParameter('messenger.bus.queries.middleware'));
$this->assertTrue($container->hasAlias('message_bus'));
$this->assertSame('messenger.bus.commands', (string) $container->getAlias('message_bus'));
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage There is an error at path "framework.messenger" in one of the buses middleware definitions: expected a single entry for a middleware item config, with factory id as key and arguments as value. Got "{"foo":["qux"],"bar":["baz"]}"
*/
public function testMessengerMiddlewareFactoryErroneousFormat()
{
$this->createContainerFromFile('messenger_middleware_factory_erroneous_format');
}
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
public function testTranslator()
{
$container = $this->createContainerFromFile('full');
$this->assertTrue($container->hasDefinition('translator.default'), '->registerTranslatorConfiguration() loads translation.xml');
$this->assertEquals('translator.default', (string) $container->getAlias('translator'), '->registerTranslatorConfiguration() redefines translator service from identity to real translator');
$options = $container->getDefinition('translator.default')->getArgument(4);
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$files = array_map('realpath', $options['resource_files']['en']);
$ref = new \ReflectionClass('Symfony\Component\Validator\Validation');
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$this->assertContains(
strtr(\dirname($ref->getFileName()).'/Resources/translations/validators.en.xlf', '/', \DIRECTORY_SEPARATOR),
$files,
'->registerTranslatorConfiguration() finds Validator translation resources'
);
$ref = new \ReflectionClass('Symfony\Component\Form\Form');
$this->assertContains(
strtr(\dirname($ref->getFileName()).'/Resources/translations/validators.en.xlf', '/', \DIRECTORY_SEPARATOR),
$files,
'->registerTranslatorConfiguration() finds Form translation resources'
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
);
$ref = new \ReflectionClass('Symfony\Component\Security\Core\Security');
$this->assertContains(
strtr(\dirname($ref->getFileName()).'/Resources/translations/security.en.xlf', '/', \DIRECTORY_SEPARATOR),
$files,
'->registerTranslatorConfiguration() finds Security translation resources'
);
$this->assertContains(
strtr(__DIR__.'/Fixtures/translations/test_paths.en.yml', '/', \DIRECTORY_SEPARATOR),
$files,
'->registerTranslatorConfiguration() finds translation resources in custom paths'
);
$this->assertContains(
strtr(__DIR__.'/translations/test_default.en.xlf', '/', \DIRECTORY_SEPARATOR),
$files,
'->registerTranslatorConfiguration() finds translation resources in default path'
);
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$calls = $container->getDefinition('translator.default')->getMethodCalls();
$this->assertEquals(array('fr'), $calls[1][1][0]);
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
2015-02-04 07:25:10 +00:00
public function testTranslatorMultipleFallbacks()
{
$container = $this->createContainerFromFile('translator_fallbacks');
$calls = $container->getDefinition('translator.default')->getMethodCalls();
$this->assertEquals(array('en', 'fr'), $calls[1][1][0]);
}
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
*/
public function testTemplatingRequiresAtLeastOneEngine()
{
$container = $this->createContainer();
refactored configuration names How to upgrade (have a look at the skeleton): * the "web:config" namespace is now "app:config" - <web:config csrf-secret="xxxxxxxxxx" charset="UTF-8" error-handler="null"> - <web:router resource="%kernel.root_dir%/config/routing.xml" /> - <web:validation enabled="true" annotations="true" /> - </web:config> + <app:config csrf-secret="xxxxxxxxxx" charset="UTF-8" error-handler="null"> + <app:router resource="%kernel.root_dir%/config/routing.xml" /> + <app:validation enabled="true" annotations="true" /> + </app:config> * the "web:templating" namespace is now a sub-namespace of "app:config" - <web:templating - escaping="htmlspecialchars" - /> + <app:config> + <app:templating escaping="htmlspecialchars" /> + </app:config> * the "web:user" namespace is now a sub-namespace of "app:config" - <web:user default-locale="fr"> - <web:session name="SYMFONY" type="Native" lifetime="3600" /> - </web:user> + <app:config> + <app:user default-locale="fr"> + <app:session name="SYMFONY" type="Native" lifetime="3600" /> + </app:user> + </app:config> * the "web:test" namespace is now a sub-namespace of "app:config" - <web:test /> + <app:config error_handler="false"> + <app:test /> + </app:config> * the "swift:mailer" namespace is now "swiftmailer:config" - <swift:mailer + <swiftmailer:config transport="smtp" encryption="ssl" auth_mode="login" * the "zend:logger" namespace is now a sub-namespace of "zend:config" - <zend:logger - priority="info" - path="%kernel.logs_dir%/%kernel.environment%.log" - /> + <zend:config> + <zend:logger priority="info" path="%kernel.logs_dir%/%kernel.environment%.log" /> + </zend:config>
2010-09-20 20:01:41 +01:00
$loader = new FrameworkExtension();
$loader->load(array(array('templating' => null)), $container);
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
public function testValidation()
{
$container = $this->createContainerFromFile('full');
$projectDir = $container->getParameter('kernel.project_dir');
2010-06-16 13:19:46 +01:00
$ref = new \ReflectionClass('Symfony\Component\Form\Form');
$xmlMappings = array(
\dirname($ref->getFileName()).'/Resources/config/validation.xml',
strtr($projectDir.'/config/validator/foo.xml', '/', \DIRECTORY_SEPARATOR),
);
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
$annotations = !class_exists(FullStack::class) && class_exists(Annotation::class);
$this->assertCount($annotations ? 7 : 6, $calls);
$this->assertSame('setConstraintValidatorFactory', $calls[0][0]);
$this->assertEquals(array(new Reference('validator.validator_factory')), $calls[0][1]);
$this->assertSame('setTranslator', $calls[1][0]);
$this->assertEquals(array(new Reference('translator')), $calls[1][1]);
$this->assertSame('setTranslationDomain', $calls[2][0]);
$this->assertSame(array('%validator.translation_domain%'), $calls[2][1]);
$this->assertSame('addXmlMappings', $calls[3][0]);
$this->assertSame(array($xmlMappings), $calls[3][1]);
$i = 3;
if ($annotations) {
$this->assertSame('enableAnnotationMapping', $calls[++$i][0]);
}
$this->assertSame('addMethodMapping', $calls[++$i][0]);
$this->assertSame(array('loadValidatorMetadata'), $calls[$i][1]);
$this->assertSame('setMetadataCache', $calls[++$i][0]);
$this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[$i][1]);
}
public function testValidationService()
{
$container = $this->createContainerFromFile('validation_annotations', array('kernel.charset' => 'UTF-8'), false);
2015-01-19 17:16:09 +00:00
$this->assertInstanceOf('Symfony\Component\Validator\Validator\ValidatorInterface', $container->get('validator'));
}
public function testAnnotations()
{
$container = $this->createContainerFromFile('full', array(), true, false);
$container->addCompilerPass(new TestAnnotationsPass());
$container->compile();
$this->assertEquals($container->getParameter('kernel.cache_dir').'/annotations', $container->getDefinition('annotations.filesystem_cache')->getArgument(0));
$this->assertSame('annotations.filesystem_cache', (string) $container->getDefinition('annotation_reader')->getArgument(1));
}
public function testFileLinkFormat()
{
if (ini_get('xdebug.file_link_format') || get_cfg_var('xdebug.file_link_format')) {
$this->markTestSkipped('A custom file_link_format is defined.');
}
$container = $this->createContainerFromFile('full');
$this->assertEquals('file%link%format', $container->getParameter('debug.file_link_format'));
}
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
public function testValidationAnnotations()
{
$container = $this->createContainerFromFile('validation_annotations');
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
$this->assertCount(7, $calls);
2014-04-02 17:29:34 +01:00
$this->assertSame('enableAnnotationMapping', $calls[4][0]);
$this->assertEquals(array(new Reference('annotation_reader')), $calls[4][1]);
$this->assertSame('addMethodMapping', $calls[5][0]);
$this->assertSame(array('loadValidatorMetadata'), $calls[5][1]);
$this->assertSame('setMetadataCache', $calls[6][0]);
$this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[6][1]);
// no cache this time
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
public function testValidationPaths()
2010-08-10 14:55:05 +01:00
{
require_once __DIR__.'/Fixtures/TestBundle/TestBundle.php';
2011-04-15 20:12:02 +01:00
$container = $this->createContainerFromFile('validation_annotations', array(
'kernel.bundles' => array('TestBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\TestBundle'),
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/TestBundle')),
));
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
$this->assertCount(8, $calls);
$this->assertSame('addXmlMappings', $calls[3][0]);
$this->assertSame('addYamlMappings', $calls[4][0]);
2014-04-02 17:29:34 +01:00
$this->assertSame('enableAnnotationMapping', $calls[5][0]);
$this->assertSame('addMethodMapping', $calls[6][0]);
$this->assertSame(array('loadValidatorMetadata'), $calls[6][1]);
$this->assertSame('setMetadataCache', $calls[7][0]);
$this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[7][1]);
$xmlMappings = $calls[3][1][0];
$this->assertCount(3, $xmlMappings);
try {
// Testing symfony/symfony
$this->assertStringEndsWith('Component'.\DIRECTORY_SEPARATOR.'Form/Resources/config/validation.xml', $xmlMappings[0]);
} catch (\Exception $e) {
// Testing symfony/framework-bundle with deps=high
$this->assertStringEndsWith('symfony'.\DIRECTORY_SEPARATOR.'form/Resources/config/validation.xml', $xmlMappings[0]);
}
$this->assertStringEndsWith('TestBundle/Resources/config/validation.xml', $xmlMappings[1]);
$yamlMappings = $calls[4][1][0];
$this->assertCount(1, $yamlMappings);
$this->assertStringEndsWith('TestBundle/Resources/config/validation.yml', $yamlMappings[0]);
}
public function testValidationPathsUsingCustomBundlePath()
{
require_once __DIR__.'/Fixtures/CustomPathBundle/src/CustomPathBundle.php';
$container = $this->createContainerFromFile('validation_annotations', array(
'kernel.bundles' => array('CustomPathBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\CustomPathBundle'),
'kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/CustomPathBundle')),
));
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
$xmlMappings = $calls[3][1][0];
$this->assertCount(3, $xmlMappings);
try {
// Testing symfony/symfony
$this->assertStringEndsWith('Component'.\DIRECTORY_SEPARATOR.'Form/Resources/config/validation.xml', $xmlMappings[0]);
} catch (\Exception $e) {
// Testing symfony/framework-bundle with deps=high
$this->assertStringEndsWith('symfony'.\DIRECTORY_SEPARATOR.'form/Resources/config/validation.xml', $xmlMappings[0]);
}
$this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.xml', $xmlMappings[1]);
$yamlMappings = $calls[4][1][0];
$this->assertCount(1, $yamlMappings);
$this->assertStringEndsWith('CustomPathBundle/Resources/config/validation.yml', $yamlMappings[0]);
}
public function testValidationNoStaticMethod()
{
$container = $this->createContainerFromFile('validation_no_static_method');
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
$annotations = !class_exists(FullStack::class) && class_exists(Annotation::class);
$this->assertCount($annotations ? 6 : 5, $calls);
$this->assertSame('addXmlMappings', $calls[3][0]);
$i = 3;
if ($annotations) {
$this->assertSame('enableAnnotationMapping', $calls[++$i][0]);
}
$this->assertSame('setMetadataCache', $calls[++$i][0]);
$this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[$i][1]);
// no cache, no annotations, no static methods
}
2017-12-12 19:30:26 +00:00
/**
* @group legacy
* @expectedDeprecation The "framework.validation.strict_email" configuration key has been deprecated in Symfony 4.1. Use the "framework.validation.email_validation_mode" configuration key instead.
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage "strict_email" and "email_validation_mode" cannot be used together.
*/
public function testCannotConfigureStrictEmailAndEmailValidationModeAtTheSameTime()
{
$this->createContainerFromFile('validation_strict_email_and_validation_mode');
}
/**
* @group legacy
* @expectedDeprecation The "framework.validation.strict_email" configuration key has been deprecated in Symfony 4.1. Use the "framework.validation.email_validation_mode" configuration key instead.
*/
public function testEnabledStrictEmailOptionIsMappedToStrictEmailValidationMode()
{
$container = $this->createContainerFromFile('validation_strict_email_enabled');
$this->assertSame('strict', $container->getDefinition('validator.email')->getArgument(0));
}
/**
* @group legacy
* @expectedDeprecation The "framework.validation.strict_email" configuration key has been deprecated in Symfony 4.1. Use the "framework.validation.email_validation_mode" configuration key instead.
*/
public function testDisabledStrictEmailOptionIsMappedToLooseEmailValidationMode()
{
$container = $this->createContainerFromFile('validation_strict_email_disabled');
$this->assertSame('loose', $container->getDefinition('validator.email')->getArgument(0));
}
public function testEmailValidationModeIsPassedToEmailValidator()
{
$container = $this->createContainerFromFile('validation_email_validation_mode');
$this->assertSame('html5', $container->getDefinition('validator.email')->getArgument(0));
}
public function testValidationTranslationDomain()
{
$container = $this->createContainerFromFile('validation_translation_domain');
$this->assertSame('messages', $container->getParameter('validator.translation_domain'));
}
public function testValidationMapping()
{
$container = $this->createContainerFromFile('validation_mapping');
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
$this->assertSame('addXmlMappings', $calls[3][0]);
$this->assertCount(3, $calls[3][1][0]);
$this->assertSame('addYamlMappings', $calls[4][0]);
$this->assertCount(3, $calls[4][1][0]);
$this->assertContains('foo.yml', $calls[4][1][0][0]);
$this->assertContains('validation.yml', $calls[4][1][0][1]);
$this->assertContains('validation.yaml', $calls[4][1][0][2]);
}
public function testFormsCanBeEnabledWithoutCsrfProtection()
{
$container = $this->createContainerFromFile('form_no_csrf');
$this->assertFalse($container->getParameter('form.type_extension.csrf.enabled'));
}
public function testStopwatchEnabledWithDebugModeEnabled()
{
$container = $this->createContainerFromFile('default_config', array(
'kernel.container_class' => 'foo',
'kernel.debug' => true,
));
$this->assertTrue($container->has('debug.stopwatch'));
}
public function testStopwatchEnabledWithDebugModeDisabled()
{
$container = $this->createContainerFromFile('default_config', array(
'kernel.container_class' => 'foo',
));
$this->assertTrue($container->has('debug.stopwatch'));
}
public function testSerializerDisabled()
{
$container = $this->createContainerFromFile('default_config');
$this->assertSame(!class_exists(FullStack::class) && class_exists(Serializer::class), $container->has('serializer'));
}
public function testSerializerEnabled()
{
$container = $this->createContainerFromFile('full');
$this->assertTrue($container->has('serializer'));
$argument = $container->getDefinition('serializer.mapping.chain_loader')->getArgument(0);
$this->assertCount(2, $argument);
$this->assertEquals('Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader', $argument[0]->getClass());
$this->assertNull($container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
$this->assertEquals(new Reference('serializer.name_converter.camel_case_to_snake_case'), $container->getDefinition('serializer.normalizer.object')->getArgument(1));
2016-07-26 15:19:03 +01:00
$this->assertEquals(new Reference('property_info', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE), $container->getDefinition('serializer.normalizer.object')->getArgument(3));
$this->assertEquals(array('setCircularReferenceHandler', array(new Reference('my.circular.reference.handler'))), $container->getDefinition('serializer.normalizer.object')->getMethodCalls()[0]);
$this->assertEquals(array('setMaxDepthHandler', array(new Reference('my.max.depth.handler'))), $container->getDefinition('serializer.normalizer.object')->getMethodCalls()[1]);
}
public function testRegisterSerializerExtractor()
{
$container = $this->createContainerFromFile('full');
$serializerExtractorDefinition = $container->getDefinition('property_info.serializer_extractor');
$this->assertEquals('serializer.mapping.class_metadata_factory', $serializerExtractorDefinition->getArgument(0)->__toString());
$this->assertFalse($serializerExtractorDefinition->isPublic());
$tag = $serializerExtractorDefinition->getTag('property_info.list_extractor');
$this->assertEquals(array('priority' => -999), $tag[0]);
}
public function testDataUriNormalizerRegistered()
{
$container = $this->createContainerFromFile('full');
$definition = $container->getDefinition('serializer.normalizer.data_uri');
$tag = $definition->getTag('serializer.normalizer');
$this->assertEquals(DataUriNormalizer::class, $definition->getClass());
$this->assertEquals(-920, $tag[0]['priority']);
}
public function testDateIntervalNormalizerRegistered()
{
if (!class_exists(DateIntervalNormalizer::class)) {
$this->markTestSkipped('The DateIntervalNormalizer has been introduced in the Serializer Component version 3.4.');
}
$container = $this->createContainerFromFile('full');
$definition = $container->getDefinition('serializer.normalizer.dateinterval');
$tag = $definition->getTag('serializer.normalizer');
$this->assertEquals(DateIntervalNormalizer::class, $definition->getClass());
$this->assertEquals(-915, $tag[0]['priority']);
}
public function testDateTimeNormalizerRegistered()
{
$container = $this->createContainerFromFile('full');
$definition = $container->getDefinition('serializer.normalizer.datetime');
$tag = $definition->getTag('serializer.normalizer');
$this->assertEquals(DateTimeNormalizer::class, $definition->getClass());
$this->assertEquals(-910, $tag[0]['priority']);
}
public function testJsonSerializableNormalizerRegistered()
{
$container = $this->createContainerFromFile('full');
$definition = $container->getDefinition('serializer.normalizer.json_serializable');
$tag = $definition->getTag('serializer.normalizer');
$this->assertEquals(JsonSerializableNormalizer::class, $definition->getClass());
$this->assertEquals(-900, $tag[0]['priority']);
}
public function testObjectNormalizerRegistered()
{
$container = $this->createContainerFromFile('full');
$definition = $container->getDefinition('serializer.normalizer.object');
$tag = $definition->getTag('serializer.normalizer');
2016-03-02 12:43:59 +00:00
$this->assertEquals('Symfony\Component\Serializer\Normalizer\ObjectNormalizer', $definition->getClass());
$this->assertEquals(-1000, $tag[0]['priority']);
}
public function testSerializerCacheActivated()
{
$container = $this->createContainerFromFile('serializer_enabled');
$this->assertTrue($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
$cache = $container->getDefinition('serializer.mapping.cache_class_metadata_factory')->getArgument(1);
$this->assertEquals(new Reference('serializer.mapping.cache.symfony'), $cache);
}
public function testSerializerCacheDisabled()
{
$container = $this->createContainerFromFile('serializer_enabled', array('kernel.debug' => true, 'kernel.container_class' => __CLASS__));
$this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
}
public function testSerializerMapping()
{
$container = $this->createContainerFromFile('serializer_mapping', array('kernel.bundles_metadata' => array('TestBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/TestBundle'))));
$projectDir = $container->getParameter('kernel.project_dir');
$configDir = __DIR__.'/Fixtures/TestBundle/Resources/config';
$expectedLoaders = array(
new Definition(AnnotationLoader::class, array(new Reference('annotation_reader'))),
new Definition(XmlFileLoader::class, array($configDir.'/serialization.xml')),
new Definition(YamlFileLoader::class, array($configDir.'/serialization.yml')),
new Definition(YamlFileLoader::class, array($projectDir.'/config/serializer/foo.yml')),
new Definition(XmlFileLoader::class, array($configDir.'/serializer_mapping/files/foo.xml')),
new Definition(YamlFileLoader::class, array($configDir.'/serializer_mapping/files/foo.yml')),
new Definition(YamlFileLoader::class, array($configDir.'/serializer_mapping/serialization.yml')),
new Definition(YamlFileLoader::class, array($configDir.'/serializer_mapping/serialization.yaml')),
);
foreach ($expectedLoaders as $definition) {
if (is_file($arg = $definition->getArgument(0))) {
$definition->replaceArgument(0, strtr($arg, '/', \DIRECTORY_SEPARATOR));
}
$definition->setPublic(false);
}
$loaders = $container->getDefinition('serializer.mapping.chain_loader')->getArgument(0);
foreach ($loaders as $loader) {
if (is_file($arg = $loader->getArgument(0))) {
$loader->replaceArgument(0, strtr($arg, '/', \DIRECTORY_SEPARATOR));
}
}
$this->assertEquals($expectedLoaders, $loaders);
}
public function testAssetHelperWhenAssetsAreEnabled()
{
$container = $this->createContainerFromFile('full');
$packages = $container->getDefinition('templating.helper.assets')->getArgument(0);
$this->assertSame('assets.packages', (string) $packages);
}
public function testAssetHelperWhenTemplatesAreEnabledAndNoAssetsConfiguration()
{
$container = $this->createContainerFromFile('templating_no_assets');
$packages = $container->getDefinition('templating.helper.assets')->getArgument(0);
$this->assertSame('assets.packages', (string) $packages);
}
public function testAssetsHelperIsRemovedWhenPhpTemplatingEngineIsEnabledAndAssetsAreDisabled()
{
$container = $this->createContainerFromFile('templating_php_assets_disabled');
$this->assertTrue(!$container->has('templating.helper.assets'), 'The templating.helper.assets helper service is removed when assets are disabled.');
}
public function testAssetHelperWhenAssetsAndTemplatesAreDisabled()
{
$container = $this->createContainerFromFile('default_config');
2015-05-06 01:54:25 +01:00
$this->assertFalse($container->hasDefinition('templating.helper.assets'));
}
public function testSerializerServiceIsRegisteredWhenEnabled()
{
$container = $this->createContainerFromFile('serializer_enabled');
$this->assertTrue($container->hasDefinition('serializer'));
}
public function testSerializerServiceIsNotRegisteredWhenDisabled()
{
$container = $this->createContainerFromFile('serializer_disabled');
$this->assertFalse($container->hasDefinition('serializer'));
}
2015-09-28 12:22:50 +01:00
public function testPropertyInfoEnabled()
{
$container = $this->createContainerFromFile('property_info');
$this->assertTrue($container->has('property_info'));
}
public function testEventDispatcherService()
{
$container = $this->createContainer(array('kernel.charset' => 'UTF-8', 'kernel.secret' => 'secret'));
$container->registerExtension(new FrameworkExtension());
$container->getCompilerPassConfig()->setBeforeOptimizationPasses(array(new LoggerPass()));
$this->loadFromFile($container, 'default_config');
$container
->register('foo', \stdClass::class)
->setPublic(true)
->setProperty('dispatcher', new Reference('event_dispatcher'));
$container->compile();
$this->assertInstanceOf(EventDispatcherInterface::class, $container->get('foo')->dispatcher);
}
public function testCacheDefaultRedisProvider()
{
$container = $this->createContainerFromFile('cache');
$redisUrl = 'redis://localhost';
$providerId = '.cache_connection.'.ContainerBuilder::hash($redisUrl);
$this->assertTrue($container->hasDefinition($providerId));
$url = $container->getDefinition($providerId)->getArgument(0);
$this->assertSame($redisUrl, $url);
}
public function testCacheDefaultRedisProviderWithEnvVar()
{
$container = $this->createContainerFromFile('cache_env_var');
$redisUrl = 'redis://paas.com';
$providerId = '.cache_connection.'.ContainerBuilder::hash($redisUrl);
$this->assertTrue($container->hasDefinition($providerId));
$url = $container->getDefinition($providerId)->getArgument(0);
$this->assertSame($redisUrl, $url);
}
public function testCachePoolServices()
{
$container = $this->createContainerFromFile('cache');
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.foo', 'cache.adapter.apcu', 30);
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.bar', 'cache.adapter.doctrine', 5);
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.baz', 'cache.adapter.filesystem', 7);
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.foobar', 'cache.adapter.psr6', 10);
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.def', 'cache.app', 11);
}
public function testRemovesResourceCheckerConfigCacheFactoryArgumentOnlyIfNoDebug()
{
$container = $this->createContainer(array('kernel.debug' => true));
(new FrameworkExtension())->load(array(), $container);
$this->assertCount(1, $container->getDefinition('config_cache_factory')->getArguments());
$container = $this->createContainer(array('kernel.debug' => false));
(new FrameworkExtension())->load(array(), $container);
$this->assertEmpty($container->getDefinition('config_cache_factory')->getArguments());
}
public function testLoggerAwareRegistration()
{
$container = $this->createContainerFromFile('full', array(), true, false);
$container->addCompilerPass(new ResolveInstanceofConditionalsPass());
$container->register('foo', LoggerAwareInterface::class)
->setAutoconfigured(true);
$container->compile();
$calls = $container->findDefinition('foo')->getMethodCalls();
$this->assertCount(1, $calls, 'Definition should contain 1 method call');
$this->assertSame('setLogger', $calls[0][0], 'Method name should be "setLogger"');
$this->assertInstanceOf(Reference::class, $calls[0][1][0]);
$this->assertSame('logger', (string) $calls[0][1][0], 'Argument should be a reference to "logger"');
}
public function testSessionCookieSecureAuto()
{
$container = $this->createContainerFromFile('session_cookie_secure_auto');
$expected = array('session', 'initialized_session', 'session_storage', 'request_stack');
$this->assertEquals($expected, array_keys($container->getDefinition('session_listener')->getArgument(0)->getValues()));
}
protected function createContainer(array $data = array())
{
return new ContainerBuilder(new ParameterBag(array_merge(array(
2014-10-22 19:27:13 +01:00
'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'),
'kernel.bundles_metadata' => array('FrameworkBundle' => array('namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..')),
2014-10-22 19:27:13 +01:00
'kernel.cache_dir' => __DIR__,
'kernel.project_dir' => __DIR__,
2014-10-22 19:27:13 +01:00
'kernel.debug' => false,
'kernel.environment' => 'test',
2014-10-22 19:27:13 +01:00
'kernel.name' => 'kernel',
'kernel.root_dir' => __DIR__,
'kernel.container_class' => 'testContainer',
'container.build_hash' => 'Abc1234',
'container.build_id' => hash('crc32', 'Abc123423456789'),
'container.build_time' => 23456789,
), $data)));
2010-08-10 14:55:05 +01:00
}
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
protected function createContainerFromFile($file, $data = array(), $resetCompilerPasses = true, $compile = true)
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
{
$cacheKey = md5(\get_class($this).$file.serialize($data));
if ($compile && isset(self::$containerCache[$cacheKey])) {
return self::$containerCache[$cacheKey];
}
$container = $this->createContainer($data);
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$container->registerExtension(new FrameworkExtension());
$this->loadFromFile($container, $file);
if ($resetCompilerPasses) {
$container->getCompilerPassConfig()->setOptimizationPasses(array());
$container->getCompilerPassConfig()->setRemovingPasses(array());
}
$container->getCompilerPassConfig()->setBeforeOptimizationPasses(array(new LoggerPass()));
$container->getCompilerPassConfig()->setBeforeRemovingPasses(array(new AddConstraintValidatorsPass(), new TranslatorPass('translator.default', 'translation.reader')));
$container->getCompilerPassConfig()->setAfterRemovingPasses(array(new AddAnnotationsCachedReaderPass()));
if (!$compile) {
return $container;
}
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$container->compile();
return self::$containerCache[$cacheKey] = $container;
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
protected function createContainerFromClosure($closure, $data = array())
{
$container = $this->createContainer($data);
$container->registerExtension(new FrameworkExtension());
$loader = new ClosureLoader($container);
$loader->load($closure);
$container->getCompilerPassConfig()->setOptimizationPasses(array());
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->compile();
return $container;
}
private function assertPathPackage(ContainerBuilder $container, ChildDefinition $package, $basePath, $version, $format)
{
$this->assertEquals('assets.path_package', $package->getParent());
$this->assertEquals($basePath, $package->getArgument(0));
$this->assertVersionStrategy($container, $package->getArgument(1), $version, $format);
}
private function assertUrlPackage(ContainerBuilder $container, ChildDefinition $package, $baseUrls, $version, $format)
{
$this->assertEquals('assets.url_package', $package->getParent());
$this->assertEquals($baseUrls, $package->getArgument(0));
$this->assertVersionStrategy($container, $package->getArgument(1), $version, $format);
}
private function assertVersionStrategy(ContainerBuilder $container, Reference $reference, $version, $format)
{
$versionStrategy = $container->getDefinition((string) $reference);
if (null === $version) {
$this->assertEquals('assets.empty_version_strategy', (string) $reference);
} else {
$this->assertEquals('assets.static_version_strategy', $versionStrategy->getParent());
$this->assertEquals($version, $versionStrategy->getArgument(0));
$this->assertEquals($format, $versionStrategy->getArgument(1));
}
}
private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $container, $id, $adapter, $defaultLifetime)
{
$this->assertTrue($container->has($id), sprintf('Service definition "%s" for cache pool of type "%s" is registered', $id, $adapter));
$poolDefinition = $container->getDefinition($id);
$this->assertInstanceOf(ChildDefinition::class, $poolDefinition, sprintf('Cache pool "%s" is based on an abstract cache pool.', $id));
$this->assertTrue($poolDefinition->hasTag('cache.pool'), sprintf('Service definition "%s" is tagged with the "cache.pool" tag.', $id));
$this->assertFalse($poolDefinition->isAbstract(), sprintf('Service definition "%s" is not abstract.', $id));
$tag = $poolDefinition->getTag('cache.pool');
2018-02-01 05:55:42 +00:00
$this->assertArrayHasKey('default_lifetime', $tag[0], 'The default lifetime is stored as an attribute of the "cache.pool" tag.');
$this->assertSame($defaultLifetime, $tag[0]['default_lifetime'], 'The default lifetime is stored as an attribute of the "cache.pool" tag.');
$parentDefinition = $poolDefinition;
do {
$parentId = $parentDefinition->getParent();
$parentDefinition = $container->findDefinition($parentId);
} while ($parentDefinition instanceof ChildDefinition);
switch ($adapter) {
case 'cache.adapter.apcu':
$this->assertSame(ApcuAdapter::class, $parentDefinition->getClass());
break;
case 'cache.adapter.doctrine':
$this->assertSame(DoctrineAdapter::class, $parentDefinition->getClass());
break;
case 'cache.app':
if (ChainAdapter::class === $parentDefinition->getClass()) {
break;
}
2017-09-17 11:10:12 +01:00
// no break
case 'cache.adapter.filesystem':
$this->assertSame(FilesystemAdapter::class, $parentDefinition->getClass());
break;
case 'cache.adapter.psr6':
$this->assertSame(ProxyAdapter::class, $parentDefinition->getClass());
break;
case 'cache.adapter.redis':
$this->assertSame(RedisAdapter::class, $parentDefinition->getClass());
break;
default:
$this->fail('Unresolved adapter: '.$adapter);
}
}
}
/**
* Simulates ReplaceAliasByActualDefinitionPass.
*/
class TestAnnotationsPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$container->setDefinition('annotation_reader', $container->getDefinition('annotations.cached_reader'));
$container->removeDefinition('annotations.cached_reader');
}
}