forked from symfony/symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug symfony#11350 [2.5][Form] solved dependency to ValidatorInterface, …
…fix symfony#11036 (Sebastian Blum) This PR was submitted for the master branch but it was merged into the 2.5 branch instead (closes symfony#11350). Discussion ---------- [2.5][Form] solved dependency to ValidatorInterface, fix symfony#11036 | Q | A | ------------- | --- | Bug fix? | [yes] | New feature? | [no] | BC breaks? | [no] | Deprecations? | [no] | Tests pass? | [yes] | Fixed tickets | symfony#11036, symfony#11345 | License | MIT | Doc PR | Since Symfony 2.5 The problem was that the form component has a hardcoded depencency to the deprecated validator component (api Version 2.4) The pull request fixes the dependency to the validator component and supports now both implementations, apiVersion 2.5 and apiVersion 2.4 of the validator component. @symfony Core Members please review the changes https://github.com/sebastianblum/symfony/blob/0a1e9c208f8730219bebf89f6696b246a0c88da7/src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php I'm not sure if it was the right solution Commits ------- 705d67b [2.5][Form] solved dependency to ValidatorInterface, fix symfony#11036
- Loading branch information
Showing
6 changed files
with
189 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Form\Tests\Extension\Validator; | ||
|
||
use Symfony\Component\Form\Extension\Validator\ValidatorExtension; | ||
|
||
class ValidatorExtensionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testValidatorInterfaceSinceSymfony25() | ||
{ | ||
$classMetaData = $this->createClassMetaDataMock(); | ||
|
||
// Mock of ValidatorInterface since apiVersion 2.5 | ||
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface'); | ||
|
||
$validator | ||
->expects($this->once()) | ||
->method('getMetadataFor') | ||
->with($this->identicalTo('Symfony\Component\Form\Form')) | ||
->will($this->returnValue($classMetaData)) | ||
; | ||
|
||
$validatorExtension = new ValidatorExtension($validator); | ||
$this->assertAttributeSame($validator, 'validator', $validatorExtension); | ||
} | ||
|
||
public function testValidatorInterfaceUntilSymfony24() | ||
{ | ||
$classMetaData = $this->createClassMetaDataMock(); | ||
|
||
$metaDataFactory = $this->getMock('Symfony\Component\Validator\MetadataFactoryInterface'); | ||
|
||
$metaDataFactory | ||
->expects($this->once()) | ||
->method('getMetadataFor') | ||
->with($this->identicalTo('Symfony\Component\Form\Form')) | ||
->will($this->returnValue($classMetaData)) | ||
; | ||
|
||
// Mock of ValidatorInterface until apiVersion 2.4 | ||
$validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface'); | ||
|
||
$validator | ||
->expects($this->once()) | ||
->method('getMetadataFactory') | ||
->will($this->returnValue($metaDataFactory)) | ||
; | ||
|
||
$validatorExtension = new ValidatorExtension($validator); | ||
$this->assertAttributeSame($validator, 'validator', $validatorExtension); | ||
} | ||
|
||
/** | ||
* @expectedException \InvalidArgumentException | ||
*/ | ||
public function testInvalidValidatorInterface() | ||
{ | ||
new ValidatorExtension(null); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
private function createClassMetaDataMock() | ||
{ | ||
$classMetaData = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$classMetaData | ||
->expects($this->once()) | ||
->method('addConstraint') | ||
->with($this->isInstanceOf('Symfony\Component\Form\Extension\Validator\Constraints\Form')); | ||
$classMetaData | ||
->expects($this->once()) | ||
->method('addPropertyConstraint') | ||
->with( | ||
$this->identicalTo('children'), | ||
$this->isInstanceOf('Symfony\Component\Validator\Constraints\Valid') | ||
); | ||
|
||
return $classMetaData; | ||
} | ||
} |