8000 [Validator] Refactored the Validator for use in Drupal by webmozart · Pull Request #6096 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Refactored the Validator for use in Drupal #6096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\Doctrine\Tests\Validator\Constraints;

use Symfony\Bridge\Doctrine\Tests\DoctrineOrmTestCase;
use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleIdentEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIdentEntity;
Expand Down Expand Up @@ -93,17 +94,6 @@ protected function createEntityManagerMock($repositoryMock)
return $em;
}

protected function createMetadataFactoryMock($metadata)
{
$metadataFactory = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface');
$metadataFactory->expects($this->any())
->method('getClassMetadata')
->with($this->equalTo($metadata->name))
->will($this->returnValue($metadata));

return $metadataFactory;
}

protected function createValidatorFactory($uniqueValidator)
{
$validatorFactory = $this->getMock('Symfony\Component\Validator\ConstraintValidatorFactoryInterface');
Expand Down Expand Up @@ -138,7 +128,8 @@ public function createValidator($entityManagerName, $em, $validateClass = null,
));
$metadata->addConstraint($constraint);

$metadataFactory = $this->createMetadataFactoryMock($metadata);
$metadataFactory = new FakeMetadataFactory();
$metadataFactory->addMetadata($metadata);
$validatorFactory = $this->createValidatorFactory($uniqueValidator);

return new Validator($metadataFactory, $validatorFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,12 @@ public function validate($form, Constraint $constraint)

if ($form->isSynchronized()) {
// Validate the form data only if transformation succeeded
$path = $this->context->getPropertyPath();
$graphWalker = $this->context->getGraphWalker();
$groups = self::getValidationGroups($form);

if (!empty($path)) {
$path .= '.';
}

// Validate the data against its own constraints
if (self::allowDataWalking($form)) {
foreach ($groups as $group) {
$graphWalker->walkReference($form->getData(), $group, $path . 'data', true);
$this->context->validate($form->getData(), 'data', $group, true);
}
}

Expand All @@ -72,7 +66,7 @@ public function validate($form, Constraint $constraint)
foreach ($constraints as $constraint) {
foreach ($groups as $group) {
if (in_array($group, $constraint->groups)) {
$graphWalker->walkConstraint($constraint, $form->getData(), $group, $path . 'data');
$this->context->validateValue($form->getData(), $constraint, 'data', $group);

// Prevent duplicate validation
continue 2;
Expand Down
Loading
0