From d3eb9b7041e08492b83eedd8e5aad60986d0654e Mon Sep 17 00:00:00 2001 From: Venu Date: Thu, 4 Jul 2013 23:18:29 +0530 Subject: [PATCH 1/6] [Validator] Fixed groups argument misplace for validateValue method from validator class --- src/Symfony/Component/Validator/Validator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Validator.php b/src/Symfony/Component/Validator/Validator.php index 2b7bacef51..c90f48213c 100644 --- a/src/Symfony/Component/Validator/Validator.php +++ b/src/Symfony/Component/Validator/Validator.php @@ -186,7 +186,7 @@ class Validator implements ValidatorInterface ); } - $context->validateValue($value, $constraint, $groups); + $context->validateValue($value, $constraint, '', $groups); } return $context->getViolations(); From 485d53aeadcb2fff19a44719c2cb85b094d5d19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Sun, 21 Jul 2013 11:38:59 +0200 Subject: [PATCH 2/6] [DependencyInjection] Fix Container::camelize to convert beginning and ending chars To convert a service ID exactly like Container::get --- .../DependencyInjection/Container.php | 2 +- .../Tests/ContainerTest.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 8a2c1b3a1e..3c3ad425ce 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -471,7 +471,7 @@ class Container implements IntrospectableContainerInterface */ public static function camelize($id) { - return preg_replace_callback('/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); }, $id); + return strtr(ucwords(strtr($id, array('_' => ' ', '.' => '_ '))), array(' ' => '')); } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index 23c13c5094..f762e7afec 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -30,6 +30,29 @@ class ContainerTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('foo' => 'bar'), $sc->getParameterBag()->all(), '__construct() takes an array of parameters as its first argument'); } + /** + * @dataProvider dataForTestCamelize + */ + public function testCamelize($id, $expected) + { + $this->assertEquals($expected, Container::camelize($id), sprintf('Container::camelize("%s")', $id)); + } + + public function dataForTestCamelize() + { + return array( + array('foo_bar', 'FooBar'), + array('foo.bar', 'Foo_Bar'), + array('foo.bar_baz', 'Foo_BarBaz'), + array('foo._bar', 'Foo_Bar'), + array('foo_.bar', 'Foo_Bar'), + array('_foo', 'Foo'), + array('.foo', '_Foo'), + array('foo_', 'Foo'), + array('foo.', 'Foo_'), + ); + } + /** * @covers Symfony\Component\DependencyInjection\Container::compile */ From a2eca45051cb6246c267ff7ebc402a2370b2b922 Mon Sep 17 00:00:00 2001 From: Patrick Allaert Date: Tue, 9 Jul 2013 15:42:15 +0200 Subject: [PATCH 3/6] Fixed #8455: PhpExecutableFinder::find() does not always return the correct binary --- src/Symfony/Component/Process/PhpExecutableFinder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Process/PhpExecutableFinder.php b/src/Symfony/Component/Process/PhpExecutableFinder.php index 8f63c2dd32..6c9b8a1149 100644 --- a/src/Symfony/Component/Process/PhpExecutableFinder.php +++ b/src/Symfony/Component/Process/PhpExecutableFinder.php @@ -34,7 +34,7 @@ class PhpExecutableFinder public function find() { // PHP_BINARY return the current sapi executable - if (defined('PHP_BINARY') && PHP_BINARY && ('cli' === PHP_SAPI)) { + if (defined('PHP_BINARY') && PHP_BINARY && ('cli' === PHP_SAPI) && is_file(PHP_BINARY)) { return PHP_BINARY; } From 9852b92da9b40e4ac19cc5246d9ce9b087e1fe15 Mon Sep 17 00:00:00 2001 From: Thomas Rothe Date: Tue, 9 Jul 2013 11:45:08 +0200 Subject: [PATCH 4/6] added missing comments to WebTestCase --- src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php index 37cf41c8eb..caf8a593db 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Test; use Symfony\Bundle\FrameworkBundle\Client; use Symfony\Component\Finder\Finder; -use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\KernelInterface; /** * WebTestCase is the base class for functional tests. @@ -23,6 +23,10 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; abstract class WebTestCase extends \PHPUnit_Framework_TestCase { protected static $class; + + /** + * @var KernelInterface + */ protected static $kernel; /** @@ -147,7 +151,7 @@ abstract class WebTestCase extends \PHPUnit_Framework_TestCase * * @param array $options An array of options * - * @return HttpKernelInterface A HttpKernelInterface instance + * @return KernelInterface A KernelInterface instance */ protected static function createKernel(array $options = array()) { From 890934d33d381bb14a95feb97cb79dc0f36c9338 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 4 May 2013 13:44:31 +0200 Subject: [PATCH 5/6] handle Optional and Required constraints from XML or YAML sources correctly --- .../Validator/Constraints/Collection.php | 6 +++ .../Tests/Constraints/CollectionTest.php | 39 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/Symfony/Component/Validator/Constraints/Collection.php b/src/Symfony/Component/Validator/Constraints/Collection.php index b618b41cc0..35e81037b1 100644 --- a/src/Symfony/Component/Validator/Constraints/Collection.php +++ b/src/Symfony/Component/Validator/Constraints/Collection.php @@ -47,6 +47,12 @@ class Collection extends Constraint } foreach ($this->fields as $fieldName => $field) { + // the XmlFileLoader and YamlFileLoader pass the field Optional + // and Required constraint as an array with exactly one element + if (is_array($field) && count($field) == 1) { + $this->fields[$fieldName] = $field = $field[0]; + } + if (!$field instanceof Optional && !$field instanceof Required) { $this->fields[$fieldName] = $field = new Required($field); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php index a0e121bba9..563b9dd659 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php @@ -14,6 +14,7 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Collection; use Symfony\Component\Validator\Constraints\Collection\Required; use Symfony\Component\Validator\Constraints\Collection\Optional; +use Symfony\Component\Validator\Constraints\Email; use Symfony\Component\Validator\Constraints\Valid; /** @@ -70,4 +71,42 @@ class CollectionTest extends \PHPUnit_Framework_TestCase 'foo' => new Required(new Valid()), )); } + + public function testAcceptOptionalConstraintAsOneElementArray() + { + $collection1 = new Collection(array( + "fields" => array( + "alternate_email" => array( + new Optional(new Email()), + ), + ), + )); + + $collection2 = new Collection(array( + "fields" => array( + "alternate_email" => new Optional(new Email()), + ), + )); + + $this->assertEquals($collection1, $collection2); + } + + public function testAcceptRequiredConstraintAsOneElementArray() + { + $collection1 = new Collection(array( + "fields" => array( + "alternate_email" => array( + new Required(new Email()), + ), + ), + )); + + $collection2 = new Collection(array( + "fields" => array( + "alternate_email" => new Required(new Email()), + ), + )); + + $this->assertEquals($collection1, $collection2); + } } From 28e070974ab510c04a8c78cd0fcf42d4298ed5f1 Mon Sep 17 00:00:00 2001 From: Venu Date: Thu, 4 Jul 2013 22:44:23 +0530 Subject: [PATCH 6/6] [Validator] fixed ConstraintViolation:: incorrect when nested --- .../Validator/ConstraintValidatorFactory.php | 2 +- .../Validator/Tests/ExecutionContextTest.php | 22 +++++++++++++++++++ .../Validator/Tests/GraphWalkerTest.php | 15 +++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/ConstraintValidatorFactory.php b/src/Symfony/Component/Validator/ConstraintValidatorFactory.php index f297cc8758..88b5cefdc2 100644 --- a/src/Symfony/Component/Validator/ConstraintValidatorFactory.php +++ b/src/Symfony/Component/Validator/ConstraintValidatorFactory.php @@ -32,7 +32,7 @@ class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface { $className = $constraint->validatedBy(); - if (!isset($this->validators[$className])) { + if (!isset($this->validators[$className]) || $className === 'Symfony\Component\Validator\Constraints\CollectionValidator') { $this->validators[$className] = new $className(); } diff --git a/src/Symfony/Component/Validator/Tests/ExecutionContextTest.php b/src/Symfony/Component/Validator/Tests/ExecutionContextTest.php index 0cd92f711f..abdf6de985 100644 --- a/src/Symfony/Component/Validator/Tests/ExecutionContextTest.php +++ b/src/Symfony/Component/Validator/Tests/ExecutionContextTest.php @@ -16,6 +16,10 @@ use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\ExecutionContext; +use Symfony\Component\Validator\Constraints\Collection; +use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; +use Symfony\Component\Validator\ValidationVisitor; +use Symfony\Component\Validator\ConstraintValidatorFactory; class ExecutionContextTest extends \PHPUnit_Framework_TestCase { @@ -410,6 +414,24 @@ class ExecutionContextTest extends \PHPUnit_Framework_TestCase $this->assertEquals('bam.baz', $this->context->getPropertyPath('bam.baz')); } + + public function testGetPropertyPathWithNestedCollectionsMixed() + { + $constraints = new Collection(array( + 'foo' => new Collection(array( + 'foo' => new ConstraintA(), + 'bar' => new ConstraintA(), + )), + 'name' => new ConstraintA() + )); + + $visitor = new ValidationVisitor('Root', $this->metadataFactory, new ConstraintValidatorFactory(), $this->translator); + $context = new ExecutionContext($visitor, $this->translator, self::TRANS_DOMAIN); + $context->validateValue(array('foo' => array('foo' => 'VALID')), $constraints); + $violations = $context->getViolations(); + + $this->assertEquals('[name]', $violations[1]->getPropertyPath()); + } } class ExecutionContextTest_TestClass diff --git a/src/Symfony/Component/Validator/Tests/GraphWalkerTest.php b/src/Symfony/Component/Validator/Tests/GraphWalkerTest.php index cafcc7aa50..d9419f1967 100644 --- a/src/Symfony/Component/Validator/Tests/GraphWalkerTest.php +++ b/src/Symfony/Component/Validator/Tests/GraphWalkerTest.php @@ -581,6 +581,21 @@ class GraphWalkerTest extends \PHPUnit_Framework_TestCase $violations = $this->walker->getViolations(); $this->assertEquals('collection[foo][bar]', $violations[0]->getPropertyPath()); } + + public function testWalkObjectUsesCorrectPropertyPathInViolationsWhenUsingNestedMixedCollections() + { + $constraint = new Collection(array( + 'foo' => new Collection(array( + 'foo' => new ConstraintA(), + 'bar' => new ConstraintA(), + )), + 'name' => new ConstraintA() + )); + + $this->walker->walkConstraint($constraint, array('foo' => array('foo' => 'VALID')), 'Default', 'collection'); + $violations = $this->walker->getViolations(); + $this->assertEquals('collection[name]', $violations[1]->getPropertyPath()); + } protected function getProperty($property) {