From a5a41b2f216c8a40361c84461e9343bf5f4fd6b5 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Wed, 22 Apr 2015 16:59:03 +0200 Subject: [PATCH 1/3] [Validator] Fixed Choice when an empty array is used in the "choices" option --- .../Validator/Constraints/ChoiceValidator.php | 2 +- .../Tests/Constraints/ChoiceValidatorTest.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php index cf5774c63d19..51fb46738428 100644 --- a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php @@ -36,7 +36,7 @@ public function validate($value, Constraint $constraint) throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Choice'); } - if (!$constraint->choices && !$constraint->callback) { + if (!is_array($constraint->choices) && !$constraint->callback) { throw new ConstraintDefinitionException('Either "choices" or "callback" must be specified on constraint Choice'); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php index 579d6aa90863..b515b843584a 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php @@ -150,6 +150,23 @@ public function testInvalidChoice() ->assertRaised(); } + public function testInvalidChoiceEmptyChoices() + { + $constraint = new Choice(array( + // May happen when the choices are provided dynamically, e.g. from + // the DB or the model + 'choices' => array(), + 'message' => 'myMessage', + )); + + $this->validator->validate('baz', $constraint); + + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"baz"') + ->setCode(Choice::NO_SUCH_CHOICE_ERROR) + ->assertRaised(); + } + public function testInvalidChoiceMultiple() { $constraint = new Choice(array( From 10c5ffbdd09eee6dec8a2e71dd60a96e7e9b549b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 24 Apr 2015 09:21:43 +0200 Subject: [PATCH 2/3] Revert "[HttpKernel] Throw a LogicException when kernel.exception does not led to a Response" This partially reverts commit 22f480752209e1877b9b47f486edad464ad079a4. --- src/Symfony/Component/HttpKernel/HttpKernel.php | 4 ---- src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/HttpKernel.php b/src/Symfony/Component/HttpKernel/HttpKernel.php index 1fed81e7a78b..473f780ca3cb 100644 --- a/src/Symfony/Component/HttpKernel/HttpKernel.php +++ b/src/Symfony/Component/HttpKernel/HttpKernel.php @@ -229,10 +229,6 @@ private function handleException(\Exception $e, $request, $type) if (!$event->hasResponse()) { $this->finishRequest($request, $type); - if ($this->dispatcher->hasListeners(KernelEvents::EXCEPTION)) { - throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e); - } - throw $e; } diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php index b793cf0f9e7e..242edeaa40e8 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php @@ -151,7 +151,7 @@ public function testHandleWhenNoControllerIsFound() $dispatcher = new EventDispatcher(); $kernel = new HttpKernel($dispatcher, $this->getResolver(false)); - $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false); + $kernel->handle(new Request()); } /** From 4a6100a6f2307a47f5676ed4001afc96d77780c6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 24 Apr 2015 12:55:28 +0200 Subject: [PATCH 3/3] [Debug] Fix deprecated use of DebugClassLoader --- .../DependencyInjection/Compiler/DumpDataCollectorPass.php | 2 +- .../FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/DebugBundle/DependencyInjection/Compiler/DumpDataCollectorPass.php b/src/Symfony/Bundle/DebugBundle/DependencyInjection/Compiler/DumpDataCollectorPass.php index 7562e7d44b3a..fae3177dfe4e 100644 --- a/src/Symfony/Bundle/DebugBundle/DependencyInjection/Compiler/DumpDataCollectorPass.php +++ b/src/Symfony/Bundle/DebugBundle/DependencyInjection/Compiler/DumpDataCollectorPass.php @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; /** - * Registers the file link format for the {@link \Symfony\Component\HttpKernel\DataCollector\DumpDataCollector\DumpDataCollector}. + * Registers the file link format for the {@link \Symfony\Component\HttpKernel\DataCollector\DumpDataCollector}. * * @author Christian Flothmann */ diff --git a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php index c4b35fd2f7ef..4a34a33f8351 100644 --- a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php @@ -98,7 +98,7 @@ public function provideClassNotFoundData() $symfonyAutoloader = new SymfonyClassLoader(); $symfonyAutoloader->addPrefixes($prefixes); - $debugClassLoader = new DebugClassLoader($symfonyAutoloader); + $debugClassLoader = new DebugClassLoader(array($symfonyAutoloader, 'loadClass')); return array( array(