From 8f16c2e39e8392f5033ebd3848f70dd241626faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 22 Feb 2018 18:18:05 +0100 Subject: [PATCH 01/22] [Security][Profiler] Display the original expression in 'Access decision log' --- .../Resources/views/Collector/security.html.twig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig b/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig index 7d993fb1f5..096fadd0f8 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig +++ b/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig @@ -317,7 +317,14 @@ {% if decision.attributes|length == 1 %} - {{ decision.attributes|first }} + {% set attribute = decision.attributes|first %} + {% if attribute.expression is defined %} + Expression:
{{ attribute.expression }}
+ {% elseif attribute.type == 'string' %} + {{ attribute }} + {% else %} + {{ profiler_dump(attribute) }} + {% endif %} {% else %} {{ profiler_dump(decision.attributes) }} {% endif %} From 5b4354f46c250a6c1ca7710ffff9d333050db12f Mon Sep 17 00:00:00 2001 From: Daniel STANCU Date: Mon, 5 Mar 2018 15:16:24 +0200 Subject: [PATCH 02/22] Readd 'form_label_errors' block to disable errors on form labels --- .../Twig/Resources/views/Form/bootstrap_4_layout.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig index a3484d9036..d12e0d8c1e 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig @@ -203,7 +203,7 @@ {% set label = name|humanize %} {%- endif -%} {%- endif -%} - <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{{- form_errors(form) -}} + <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %} {%- endif -%} {%- endblock form_label %} From b010f4ffee938e513a4ae5d10baac20b3ef8fef6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 5 Mar 2018 11:40:57 -0800 Subject: [PATCH 03/22] updated CHANGELOG for 3.4.6 --- CHANGELOG-3.4.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG-3.4.md b/CHANGELOG-3.4.md index e8f584e496..e735c49d84 100644 --- a/CHANGELOG-3.4.md +++ b/CHANGELOG-3.4.md @@ -7,6 +7,14 @@ in 3.4 minor versions. To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v3.4.0...v3.4.1 +* 3.4.6 (2018-03-05) + + * bug #26393 [DI] Skip resource tracking if disabled (chalasr) + * bug #26355 [DI] Fix missing "id" normalization when dumping the container (nicolas-grekas) + * bug #26368 [WebProfilerBundle] Fix Debug toolbar breaks app (xkobal) + * bug #26369 Use fill instead of style for svg colors (rpkamp) + * bug #26358 [FrameworkBundle] Silence "Failed to remove directory" on cache:clear (nicolas-grekas) + * 3.4.5 (2018-03-01) * bug #26327 [Form][WCAG] Errors sign for people that do not see colors (Nyholm) From 932c275e651f4de51ae0e95f08f961bb2e50e2d3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 5 Mar 2018 11:41:07 -0800 Subject: [PATCH 04/22] updated VERSION for 3.4.6 --- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 26236e2d22..156a0f511f 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -67,12 +67,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private $requestStackSize = 0; private $resetServices = false; - const VERSION = '3.4.6-DEV'; + const VERSION = '3.4.6'; const VERSION_ID = 30406; const MAJOR_VERSION = 3; const MINOR_VERSION = 4; const RELEASE_VERSION = 6; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '11/2020'; const END_OF_LIFE = '11/2021'; From d6fd5798ea3ff482d61d1c4fee426d86770b3396 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 5 Mar 2018 14:26:20 -0800 Subject: [PATCH 05/22] bumped Symfony version to 3.4.7 --- src/Symfony/Component/HttpKernel/Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 156a0f511f..f5b8cb7213 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -67,12 +67,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private $requestStackSize = 0; private $resetServices = false; - const VERSION = '3.4.6'; - const VERSION_ID = 30406; + const VERSION = '3.4.7-DEV'; + const VERSION_ID = 30407; const MAJOR_VERSION = 3; const MINOR_VERSION = 4; - const RELEASE_VERSION = 6; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 7; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '11/2020'; const END_OF_LIFE = '11/2021'; From dff88d44be7f480ba2ec15ab88e597475d7eec56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Pr=C3=A9vot?= Date: Sun, 22 Oct 2017 13:38:09 -1000 Subject: [PATCH 06/22] [Config] Add characters to the regex This allow paths containing ~ and + (as used in version number in Debian for example) to be used while running the testsuite. --- src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php index 00a7901f3a..9d61c9cd83 100644 --- a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php +++ b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php @@ -55,7 +55,7 @@ class XmlUtilsTest extends TestCase XmlUtils::loadFile($fixtures.'valid.xml', array($mock, 'validate')); $this->fail(); } catch (\InvalidArgumentException $e) { - $this->assertRegExp('/The XML file "[\w:\/\\\.-]+" is not valid\./', $e->getMessage()); + $this->assertRegExp('/The XML file "[\w:\/\\\.~+-]+" is not valid\./', $e->getMessage()); } $this->assertInstanceOf('DOMDocument', XmlUtils::loadFile($fixtures.'valid.xml', array($mock, 'validate'))); From 44b4fc8db56e891ec261b4ad5351a640aac945d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Pr=C3=A9vot?= Date: Mon, 5 Mar 2018 15:41:45 -1000 Subject: [PATCH 07/22] [SecurityBundle] Make extra character non mandatory in regex The extra character was introduced in 5f9471e, and breaks the testsuite in native php 7.2. --- .../Tests/Functional/UserPasswordEncoderCommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php index 01b2ce303a..163aa5ccb4 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php @@ -86,7 +86,7 @@ class UserPasswordEncoderCommandTest extends WebTestCase $this->assertContains('Password encoding succeeded', $output); $encoder = new Argon2iPasswordEncoder(); - preg_match('# Encoded password\s+(\$argon2id\$[\w\d,=\$+\/]+={0,2})\s+#', $output, $matches); + preg_match('# Encoded password\s+(\$argon2id?\$[\w\d,=\$+\/]+={0,2})\s+#', $output, $matches); $hash = $matches[1]; $this->assertTrue($encoder->isPasswordValid($hash, 'password', null)); } From d00746987717125b13222214daffcbda43001e36 Mon Sep 17 00:00:00 2001 From: Alessandro Loffredo Date: Wed, 7 Mar 2018 14:52:09 +0100 Subject: [PATCH 08/22] fix the updating of timestamp in the MemcachedSessionHandler --- .../Session/Storage/Handler/MemcachedSessionHandler.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php index 9f4ef7028e..dd37eae14e 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php @@ -80,7 +80,9 @@ class MemcachedSessionHandler extends AbstractSessionHandler */ public function updateTimestamp($sessionId, $data) { - return $this->memcached->touch($this->prefix.$sessionId, time() + $this->ttl); + $this->memcached->touch($this->prefix.$sessionId, time() + $this->ttl); + + return true; } /** From 0beb64a77c208ed0a159c4a4c967998dcc94af72 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Tue, 6 Mar 2018 12:22:04 +0100 Subject: [PATCH 09/22] fix regression when extending the Container class without a constructor regression introduced in https://github.com/symfony/symfony/commit/c026ec63e33c696c422f3d72c99c8fe64f091376#diff-f7b23d463cba27ac5e4cb677f2be7623R985 --- .../Component/DependencyInjection/Dumper/PhpDumper.php | 10 +++++++--- .../Fixtures/Container/NoConstructorContainer.php | 4 +++- ...m_container_class_constructor_without_arguments.php | 1 + ...ainer_class_with_optional_constructor_arguments.php | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index f4aa0582f7..4f2c4a15cb 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -981,9 +981,13 @@ EOF; if ($this->container->isCompiled()) { if (Container::class !== $baseClassWithNamespace) { $r = $this->container->getReflectionClass($baseClassWithNamespace, false); - - if (null !== $r && (null !== $constructor = $r->getConstructor()) && 0 === $constructor->getNumberOfRequiredParameters()) { - $code .= " parent::__construct();\n\n"; + if (null !== $r + && (null !== $constructor = $r->getConstructor()) + && 0 === $constructor->getNumberOfRequiredParameters() + && Container::class !== $constructor->getDeclaringClass()->name + ) { + $code .= " parent::__construct();\n"; + $code .= " \$this->parameterBag = null;\n\n"; } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Container/NoConstructorContainer.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Container/NoConstructorContainer.php index 7514cc7c1b..b14b013f1f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Container/NoConstructorContainer.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Container/NoConstructorContainer.php @@ -2,6 +2,8 @@ namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container; -class NoConstructorContainer +use Symfony\Component\DependencyInjection\Container; + +class NoConstructorContainer extends Container { } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_constructor_without_arguments.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_constructor_without_arguments.php index 3020602b89..0a443f3a79 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_constructor_without_arguments.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_constructor_without_arguments.php @@ -24,6 +24,7 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tes public function __construct() { parent::__construct(); + $this->parameterBag = null; $this->services = array(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php index d65ac7dfbc..6bf3c90613 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php @@ -24,6 +24,7 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tes public function __construct() { parent::__construct(); + $this->parameterBag = null; $this->services = array(); From 5b0d9340d7b8cc2a714847be9dc7e2cfaf9f367a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sun, 4 Feb 2018 17:33:12 +0100 Subject: [PATCH 10/22] Display the Welcome Page when there is no homepage defined --- .../Component/HttpKernel/Resources/welcome.html.php | 2 +- .../Routing/Matcher/Dumper/PhpMatcherDumper.php | 9 ++++----- src/Symfony/Component/Routing/Matcher/UrlMatcher.php | 2 +- .../Routing/Tests/Fixtures/dumper/url_matcher1.php | 4 ++++ .../Routing/Tests/Fixtures/dumper/url_matcher2.php | 4 ++++ .../Routing/Tests/Fixtures/dumper/url_matcher3.php | 4 ++++ .../Routing/Tests/Fixtures/dumper/url_matcher4.php | 4 ++++ .../Routing/Tests/Fixtures/dumper/url_matcher5.php | 4 ++++ .../Routing/Tests/Fixtures/dumper/url_matcher6.php | 4 ++++ .../Routing/Tests/Fixtures/dumper/url_matcher7.php | 4 ++++ 10 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Resources/welcome.html.php b/src/Symfony/Component/HttpKernel/Resources/welcome.html.php index d8c37beb56..caac7fd6eb 100644 --- a/src/Symfony/Component/HttpKernel/Resources/welcome.html.php +++ b/src/Symfony/Component/HttpKernel/Resources/welcome.html.php @@ -76,7 +76,7 @@

- You're seeing this message because you have debug mode enabled and you haven't configured any URLs. + You're seeing this page because debug mode is enabled and you haven't configured any homepage URL.

diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index b74ff8a9d7..78b37d744f 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -153,11 +153,10 @@ EOF; } } - if ('' === $code) { - $code .= " if ('/' === \$pathinfo) {\n"; - $code .= " throw new Symfony\Component\Routing\Exception\NoConfigurationException();\n"; - $code .= " }\n"; - } + // used to display the Welcome Page in apps that don't define a homepage + $code .= " if ('/' === \$pathinfo) {\n"; + $code .= " throw new Symfony\Component\Routing\Exception\NoConfigurationException();\n"; + $code .= " }\n"; return $code; } diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index 3cba7e66f8..597dea0795 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -76,7 +76,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface return $ret; } - if (0 === count($this->routes) && '/' === $pathinfo) { + if ('/' === $pathinfo) { throw new NoConfigurationException(); } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php index d1bb74ec1d..89ab95fdcf 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php @@ -305,6 +305,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } + if ('/' === $pathinfo) { + throw new Symfony\Component\Routing\Exception\NoConfigurationException(); + } + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); } } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php index 662c2cb9a7..6099ec4e42 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php @@ -357,6 +357,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec return $ret; } + if ('/' === $pathinfo) { + throw new Symfony\Component\Routing\Exception\NoConfigurationException(); + } + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); } } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php index 40edb4386f..2be0c5dedc 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php @@ -46,6 +46,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher return array('_route' => 'with-condition'); } + if ('/' === $pathinfo) { + throw new Symfony\Component\Routing\Exception\NoConfigurationException(); + } + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); } } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher4.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher4.php index 89f2b10e22..451a8b7591 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher4.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher4.php @@ -97,6 +97,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } + if ('/' === $pathinfo) { + throw new Symfony\Component\Routing\Exception\NoConfigurationException(); + } + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); } } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher5.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher5.php index f88ecaf15f..825e260218 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher5.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher5.php @@ -200,6 +200,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } + if ('/' === $pathinfo) { + throw new Symfony\Component\Routing\Exception\NoConfigurationException(); + } + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); } } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher6.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher6.php index 91079fcef7..77d48f5480 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher6.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher6.php @@ -192,6 +192,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } + if ('/' === $pathinfo) { + throw new Symfony\Component\Routing\Exception\NoConfigurationException(); + } + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); } } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher7.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher7.php index a9c3fd2b5f..407ca13b35 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher7.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher7.php @@ -248,6 +248,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } + if ('/' === $pathinfo) { + throw new Symfony\Component\Routing\Exception\NoConfigurationException(); + } + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); } } From e85151483ccd9e2c002ba8e6808d3598056a5851 Mon Sep 17 00:00:00 2001 From: andrey1s Date: Mon, 5 Mar 2018 11:57:35 +0300 Subject: [PATCH 11/22] [Config] ReflectionClassResource check abstract ServiceSubscriberInterface and EventSubscriberInterface --- .../Component/Config/Resource/ReflectionClassResource.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Config/Resource/ReflectionClassResource.php b/src/Symfony/Component/Config/Resource/ReflectionClassResource.php index 149789aa36..822b78568d 100644 --- a/src/Symfony/Component/Config/Resource/ReflectionClassResource.php +++ b/src/Symfony/Component/Config/Resource/ReflectionClassResource.php @@ -155,12 +155,16 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali } } - if ($class->isSubclassOf(EventSubscriberInterface::class)) { + if ($class->isAbstract() || $class->isInterface() || $class->isTrait()) { + return; + } + + if (interface_exists(EventSubscriberInterface::class, false) && $class->isSubclassOf(EventSubscriberInterface::class)) { yield EventSubscriberInterface::class; yield print_r(\call_user_func(array($class->name, 'getSubscribedEvents')), true); } - if ($class->isSubclassOf(ServiceSubscriberInterface::class)) { + if (interface_exists(ServiceSubscriberInterface::class, false) && $class->isSubclassOf(ServiceSubscriberInterface::class)) { yield ServiceSubscriberInterface::class; yield print_r(\call_user_func(array($class->name, 'getSubscribedServices')), true); } From 6ca8b4beeb2d44e4dd821446092c709ffeb97666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 12 Mar 2018 14:37:54 +0100 Subject: [PATCH 12/22] [DomCrawler] FormField: remove an useless return statement --- src/Symfony/Component/DomCrawler/Field/FormField.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Symfony/Component/DomCrawler/Field/FormField.php b/src/Symfony/Component/DomCrawler/Field/FormField.php index 567164d046..33c0bbeac0 100644 --- a/src/Symfony/Component/DomCrawler/Field/FormField.php +++ b/src/Symfony/Component/DomCrawler/Field/FormField.php @@ -75,8 +75,6 @@ abstract class FormField if ($labels->length > 0) { return $labels->item(0); } - - return; } /** From 77e643d0baa2b0cbf3132a14daaf2ed2fd238ed4 Mon Sep 17 00:00:00 2001 From: amcastror Date: Sat, 10 Mar 2018 15:48:33 -0300 Subject: [PATCH 13/22] [PhpUnitBridge] Ability to use different composer.json file --- src/Symfony/Bridge/PhpUnit/bin/simple-phpunit | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit index 2f97e32e11..a549cd7da4 100755 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit @@ -26,8 +26,13 @@ if (PHP_VERSION_ID >= 70200) { $PHPUNIT_VERSION = '4.8'; } +if ('composer.json' !== $COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json') { + putenv('COMPOSER=composer.json'); + $_SERVER['COMPOSER'] = $_ENV['COMPOSER'] = 'composer.json'; +} + $root = __DIR__; -while (!file_exists($root.'/composer.json') || file_exists($root.'/DeprecationErrorHandler.php')) { +while (!file_exists($root.'/'.$COMPOSER_JSON) || file_exists($root.'/DeprecationErrorHandler.php')) { if ($root === dirname($root)) { break; } From 5d7b13110b9136e390af82df7b4e81c61db0e57b Mon Sep 17 00:00:00 2001 From: Jean Ragouin Date: Tue, 13 Mar 2018 18:00:05 +0800 Subject: [PATCH 14/22] Update Client.php --- src/Symfony/Component/BrowserKit/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 63d4be77cf..e9e0d1963f 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -78,7 +78,7 @@ abstract class Client } /** - * Sets the maximum number of requests that crawler can follow. + * Sets the maximum number of redirects that crawler can follow. * * @param int $maxRedirects */ @@ -89,7 +89,7 @@ abstract class Client } /** - * Returns the maximum number of requests that crawler can follow. + * Returns the maximum number of redirects that crawler can follow. * * @return int */ From 25312c4671bedb40b4a07c8bfe5127c182fea4c0 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Thu, 15 Mar 2018 20:08:29 +0100 Subject: [PATCH 15/22] [Serializer] Remove const override --- .../Component/Serializer/Normalizer/AbstractObjectNormalizer.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php index 08fbc5fa3f..25d6ff6a9d 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php @@ -31,7 +31,6 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer { const ENABLE_MAX_DEPTH = 'enable_max_depth'; const DEPTH_KEY_PATTERN = 'depth_%s::%s'; - const ALLOW_EXTRA_ATTRIBUTES = 'allow_extra_attributes'; const DISABLE_TYPE_ENFORCEMENT = 'disable_type_enforcement'; private $propertyTypeExtractor; From 83c4f4c7f072aff6db39d2b22cac0605173ba831 Mon Sep 17 00:00:00 2001 From: okorneliuk Date: Thu, 15 Mar 2018 18:53:08 +0200 Subject: [PATCH 16/22] Extra line to bootstrap 3 horizontal layout This file ends with no newline character. It won't render properly on a terminal, and it's considered a bad practice. --- .../views/Form/bootstrap_3_horizontal_layout.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig index f0c4626daf..d6b08f7637 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig @@ -62,4 +62,4 @@ col-sm-10 {{- form_errors(form) -}} {#--#} -{%- endblock checkbox_row %} \ No newline at end of file +{%- endblock checkbox_row %} From 47a3d7a08454200acc5a9c37fdd0478bb653c6da Mon Sep 17 00:00:00 2001 From: David Maicher Date: Fri, 16 Mar 2018 19:07:30 +0100 Subject: [PATCH 17/22] [TwigBundle] document TwigRenderer BC break in UPGRADE-3.4 --- UPGRADE-3.4.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/UPGRADE-3.4.md b/UPGRADE-3.4.md index 2638d84c80..38891caf76 100644 --- a/UPGRADE-3.4.md +++ b/UPGRADE-3.4.md @@ -410,6 +410,14 @@ TwigBridge * deprecated the `Symfony\Bridge\Twig\Form\TwigRenderer` class, use the `FormRenderer` class from the Form component instead + + * the service `twig.form.renderer` is now an instance of `FormRenderer`. + So you might have to adjust your type-hints to `FormRendererInterface` if you are still relying on + the `TwigRendererInterface` which was deprecated in Symfony 3.2 + + * retrieving the Renderer runtime from the twig environment via + `$twig->getRuntime('Symfony\Bridge\Twig\Form\TwigRenderer')` is not working anymore + and should be replaced with `$twig->getRuntime('Symfony\Component\Form\FormRenderer')` instead * deprecated `Symfony\Bridge\Twig\Command\DebugCommand::set/getTwigEnvironment` and the ability to pass a command name as first argument From f36cfd4fc8b4dac845dbcbbb71767a88ccb50489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Sat, 17 Mar 2018 13:20:09 +0100 Subject: [PATCH 18/22] [HttpKernel] Allow generators in registerBundle --- src/Symfony/Component/HttpKernel/KernelInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/KernelInterface.php b/src/Symfony/Component/HttpKernel/KernelInterface.php index b341e3e9fc..9ec4e7a9fc 100644 --- a/src/Symfony/Component/HttpKernel/KernelInterface.php +++ b/src/Symfony/Component/HttpKernel/KernelInterface.php @@ -27,7 +27,7 @@ interface KernelInterface extends HttpKernelInterface, \Serializable /** * Returns an array of bundles to register. * - * @return BundleInterface[] An array of bundle instances + * @return iterable|BundleInterface[] An iterable of bundle instances */ public function registerBundles(); From 5dcaaadb5e8c01148b67d009c95a5118849f9a55 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 18 Mar 2018 15:29:46 +0100 Subject: [PATCH 19/22] Make sure form errors is valid HTML --- .../views/Form/bootstrap_4_layout.html.twig | 14 ++++---- ...AbstractBootstrap4HorizontalLayoutTest.php | 14 ++++---- .../Tests/AbstractBootstrap4LayoutTest.php | 36 ++++++++----------- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig index a3484d9036..6b5183592e 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig @@ -261,12 +261,12 @@ {% block form_errors -%} {%- if errors|length > 0 -%} -
-
    - {%- for error in errors -%} -
  • {{ 'Error'|trans({}, 'validators') }} {{ error.message }}
  • - {%- endfor -%} -
-
+ + {%- for error in errors -%} + + {{ 'Error'|trans({}, 'validators') }} {{ error.message }} + + {%- endfor -%} + {%- endif %} {%- endblock form_errors %} diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php index e8ede167b3..c906c6549a 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php @@ -32,14 +32,12 @@ abstract class AbstractBootstrap4HorizontalLayoutTest extends AbstractBootstrap4 [ ./label[@for="name"] [ - ./div[ - ./ul - [./li - [./span[.="[trans]Error[/trans]"]] - [./span[.="[trans]Error![/trans]"]] - ] - [count(./li)=1] - ] + ./span[@class="alert alert-danger"] + [./span[@class="mb-0 d-block"] + [./span[.="[trans]Error[/trans]"]] + [./span[.="[trans]Error![/trans]"]] + ] + [count(./span)=1] ] /following-sibling::div[./input[@id="name"]] ] diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php index ec97577818..aa0600e58f 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php @@ -32,14 +32,12 @@ abstract class AbstractBootstrap4LayoutTest extends AbstractBootstrap3LayoutTest [ ./label[@for="name"] [ - ./div[ - ./ul - [./li - [./span[.="[trans]Error[/trans]"]] - [./span[.="[trans]Error![/trans]"]] - ] - [count(./li)=1] - ] + ./span[@class="alert alert-danger"] + [./span[@class="mb-0 d-block"] + [./span[.="[trans]Error[/trans]"]] + [./span[.="[trans]Error![/trans]"]] + ] + [count(./span)=1] ] /following-sibling::input[@id="name"] ] @@ -162,22 +160,18 @@ abstract class AbstractBootstrap4LayoutTest extends AbstractBootstrap3LayoutTest $html = $this->renderErrors($view); $this->assertMatchesXpath($html, -'/div +'/span [@class="alert alert-danger"] [ - ./ul - [@class="list-unstyled mb-0"] - [ - ./li - [./span[.="[trans]Error[/trans]"]] - [./span[.="[trans]Error 1[/trans]"]] - - /following-sibling::li - [./span[.="[trans]Error[/trans]"]] - [./span[.="[trans]Error 2[/trans]"]] - ] - [count(./li)=2] + ./span[@class="mb-0 d-block"] + [./span[.="[trans]Error[/trans]"]] + [./span[.="[trans]Error 1[/trans]"]] + + /following-sibling::span[@class="mb-0 d-block"] + [./span[.="[trans]Error[/trans]"]] + [./span[.="[trans]Error 2[/trans]"]] ] + [count(./span)=2] ' ); } From d8f3de91d5907df505281803c482fd7edb2b5eb7 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 18 Mar 2018 15:50:20 +0100 Subject: [PATCH 20/22] Make sure we always render errors. Eventhough labels are disabled --- .../Resources/views/Form/bootstrap_4_layout.html.twig | 6 ++++++ .../Form/Tests/AbstractBootstrap4LayoutTest.php | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig index a3484d9036..e2061c29ba 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig @@ -204,6 +204,12 @@ {%- endif -%} {%- endif -%} <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{{- form_errors(form) -}} + {%- else -%} + {%- if errors|length > 0 -%} +
+ {{- form_errors(form) -}} +
+ {%- endif -%} {%- endif -%} {%- endblock form_label %} diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php index ec97577818..b9e8a38e0f 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php @@ -182,6 +182,16 @@ abstract class AbstractBootstrap4LayoutTest extends AbstractBootstrap3LayoutTest ); } + public function testErrorWithNoLabel() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', array('label'=>false)); + $form->addError(new FormError('[trans]Error 1[/trans]')); + $view = $form->createView(); + $html = $this->renderLabel($view); + + $this->assertMatchesXpath($html, '//span[.="[trans]Error[/trans]"]'); + } + public function testCheckedCheckbox() { $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', true); From 6b6fdab562eb3aca282d1966551e8d4d2cc07bf0 Mon Sep 17 00:00:00 2001 From: Jake Bishop Date: Fri, 16 Mar 2018 13:42:48 +0100 Subject: [PATCH 21/22] [Bridge\PhpUnit] Fix #26430 Cannot autoload listeners --- src/Symfony/Bridge/PhpUnit/CoverageListener.php | 6 ++++++ src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/Symfony/Bridge/PhpUnit/CoverageListener.php b/src/Symfony/Bridge/PhpUnit/CoverageListener.php index 79333fbd00..d41c26968f 100644 --- a/src/Symfony/Bridge/PhpUnit/CoverageListener.php +++ b/src/Symfony/Bridge/PhpUnit/CoverageListener.php @@ -18,3 +18,9 @@ if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Ve } else { class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListenerForV7', 'Symfony\Bridge\PhpUnit\CoverageListener'); } + +if (false) { + class CoverageListener + { + } +} diff --git a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php index d46a79e00e..a753525b76 100644 --- a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php +++ b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php @@ -18,3 +18,9 @@ if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Ve } else { class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener'); } + +if (false) { + class SymfonyTestsListener + { + } +} From 2992bb3fd322de866f22e1aacf6552e87fccd917 Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Thu, 15 Mar 2018 13:20:27 +0200 Subject: [PATCH 22/22] [DI] Add tests for EnvVarProcessor --- .../Tests/EnvVarProcessorTest.php | 304 ++++++++++++++++++ 1 file changed, 304 insertions(+) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php diff --git a/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php b/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php new file mode 100644 index 0000000000..b1ee044e9e --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php @@ -0,0 +1,304 @@ +setParameter('env(foo)', $value); + $container->compile(); + + $processor = new EnvVarProcessor($container); + + $result = $processor->getEnv('string', 'foo', function () { + $this->fail('Should not be called'); + }); + + $this->assertSame($processed, $result); + } + + public function validStrings() + { + return array( + array('hello', 'hello'), + array('true', 'true'), + array('false', 'false'), + array('null', 'null'), + array('1', '1'), + array('0', '0'), + array('1.1', '1.1'), + array('1e1', '1e1'), + ); + } + + /** + * @dataProvider validBools + */ + public function testGetEnvBool($value, $processed) + { + $processor = new EnvVarProcessor(new Container()); + + $result = $processor->getEnv('bool', 'foo', function ($name) use ($value) { + $this->assertSame('foo', $name); + + return $value; + }); + + $this->assertSame($processed, $result); + } + + public function validBools() + { + return array( + array('true', true), + array('false', false), + array('null', false), + array('1', true), + array('0', false), + array('1.1', true), + array('1e1', true), + ); + } + + /** + * @dataProvider validInts + */ + public function testGetEnvInt($value, $processed) + { + $processor = new EnvVarProcessor(new Container()); + + $result = $processor->getEnv('int', 'foo', function ($name) use ($value) { + $this->assertSame('foo', $name); + + return $value; + }); + + $this->assertSame($processed, $result); + } + + public function validInts() + { + return array( + array('1', 1), + array('1.1', 1), + array('1e1', 10), + ); + } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionMessage Non-numeric env var + * @dataProvider invalidInts + */ + public function testGetEnvIntInvalid($value) + { + $processor = new EnvVarProcessor(new Container()); + + $processor->getEnv('int', 'foo', function ($name) use ($value) { + $this->assertSame('foo', $name); + + return $value; + }); + } + + public function invalidInts() + { + return array( + array('foo'), + array('true'), + array('null'), + ); + } + + /** + * @dataProvider validFloats + */ + public function testGetEnvFloat($value, $processed) + { + $processor = new EnvVarProcessor(new Container()); + + $result = $processor->getEnv('float', 'foo', function ($name) use ($value) { + $this->assertSame('foo', $name); + + return $value; + }); + + $this->assertSame($processed, $result); + } + + public function validFloats() + { + return array( + array('1', 1.0), + array('1.1', 1.1), + array('1e1', 10.0), + ); + } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionMessage Non-numeric env var + * @dataProvider invalidFloats + */ + public function testGetEnvFloatInvalid($value) + { + $processor = new EnvVarProcessor(new Container()); + + $processor->getEnv('float', 'foo', function ($name) use ($value) { + $this->assertSame('foo', $name); + + return $value; + }); + } + + public function invalidFloats() + { + return array( + array('foo'), + array('true'), + array('null'), + ); + } + + /** + * @dataProvider validConsts + */ + public function testGetEnvConst($value, $processed) + { + $processor = new EnvVarProcessor(new Container()); + + $result = $processor->getEnv('const', 'foo', function ($name) use ($value) { + $this->assertSame('foo', $name); + + return $value; + }); + + $this->assertSame($processed, $result); + } + + public function validConsts() + { + return array( + array('Symfony\Component\DependencyInjection\Tests\EnvVarProcessorTest::TEST_CONST', self::TEST_CONST), + array('E_ERROR', E_ERROR), + ); + } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionMessage undefined constant + * @dataProvider invalidConsts + */ + public function testGetEnvConstInvalid($value) + { + $processor = new EnvVarProcessor(new Container()); + + $processor->getEnv('const', 'foo', function ($name) use ($value) { + $this->assertSame('foo', $name); + + return $value; + }); + } + + public function invalidConsts() + { + return array( + array('Symfony\Component\DependencyInjection\Tests\EnvVarProcessorTest::UNDEFINED_CONST'), + array('UNDEFINED_CONST'), + ); + } + + public function testGetEnvBase64() + { + $processor = new EnvVarProcessor(new Container()); + + $result = $processor->getEnv('base64', 'foo', function ($name) { + $this->assertSame('foo', $name); + + return base64_encode('hello'); + }); + + $this->assertSame('hello', $result); + } + + public function testGetEnvJson() + { + $processor = new EnvVarProcessor(new Container()); + + $result = $processor->getEnv('json', 'foo', function ($name) { + $this->assertSame('foo', $name); + + return json_encode(array(1)); + }); + + $this->assertSame(array(1), $result); + } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionMessage Syntax error + */ + public function testGetEnvInvalidJson() + { + $processor = new EnvVarProcessor(new Container()); + + $processor->getEnv('json', 'foo', function ($name) { + $this->assertSame('foo', $name); + + return 'invalid_json'; + }); + } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionMessage Invalid JSON env var + * @dataProvider otherJsonValues + */ + public function testGetEnvJsonOther($value) + { + $processor = new EnvVarProcessor(new Container()); + + $processor->getEnv('json', 'foo', function ($name) use ($value) { + $this->assertSame('foo', $name); + + return json_encode($value); + }); + } + + public function otherJsonValues() + { + return array( + array(1), + array(1.1), + array(true), + array(false), + ); + } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionMessage Unsupported env var prefix + */ + public function testGetEnvUnknown() + { + $processor = new EnvVarProcessor(new Container()); + + $processor->getEnv('unknown', 'foo', function ($name) { + $this->assertSame('foo', $name); + + return 'foo'; + }); + } +}