-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Change FormTypeValidatorExtension construct signature #49502
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
base: 7.4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\Component\Form\Tests\Extension\Validator; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; | ||
use Symfony\Component\Form\Extension\Validator\Constraints\Form as FormConstraint; | ||
use Symfony\Component\Form\Extension\Validator\ValidatorExtension; | ||
use Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser; | ||
|
@@ -24,8 +25,15 @@ | |
|
||
class ValidatorExtensionTest extends TestCase | ||
{ | ||
public function test2Dot5ValidationApi() | ||
use ExpectDeprecationTrait; | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testLegacy2Dot5ValidationApi() | ||
{ | ||
$this->expectDeprecation('Since symfony/form 6.3: The signature of "Symfony\Component\Form\Extension\Validator\ValidatorExtension" constructor requires 3 arguments: "ValidatorInterface $validator, FormRendererInterface $formRenderer = null, TranslatorInterface $translator = null". Passing argument $legacyErrorMessages is deprecated.'); | ||
|
||
$metadata = new ClassMetadata(Form::class); | ||
|
||
$metadataFactory = new FakeMetadataFactory(); | ||
|
@@ -46,4 +54,67 @@ public function test2Dot5ValidationApi() | |
$this->assertSame(TraversalStrategy::NONE, $metadata->traversalStrategy); | ||
$this->assertCount(0, $metadata->getPropertyMetadata('children')); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testLegacyWithBadFormRendererType() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the legacy signature, but the new one though, as you don't pass the boolean. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. But when type hint will be set in 7.0. Args checking will be drop and tests must also be dropped. I can keep |
||
{ | ||
$metadata = new ClassMetadata(Form::class); | ||
|
||
$metadataFactory = new FakeMetadataFactory(); | ||
$metadataFactory->addMetadata($metadata); | ||
|
||
$validator = Validation::createValidatorBuilder() | ||
->setMetadataFactory($metadataFactory) | ||
->getValidator(); | ||
|
||
$this->expectException(\TypeError::class); | ||
$this->expectExceptionMessage('Argument 2 passed to "Symfony\Component\Form\Extension\Validator\ValidatorExtension::__construct()" must be an instance of "Symfony\Component\Form\FormRendererInterface" or null, "stdClass" given.'); | ||
|
||
new ValidatorExtension($validator, new \stdClass()); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testLegacyWithBadTranslatorType() | ||
{ | ||
$metadata = new ClassMetadata(Form::class); | ||
|
||
$metadataFactory = new FakeMetadataFactory(); | ||
$metadataFactory->addMetadata($metadata); | ||
|
||
$validator = Validation::createValidatorBuilder() | ||
->setMetadataFactory($metadataFactory) | ||
->getValidator(); | ||
|
||
$this->expectException(\TypeError::class); | ||
$this->expectExceptionMessage('Argument 3 passed to "Symfony\Component\Form\Extension\Validator\ValidatorExtension::__construct()" must be an instance of "Symfony\Contracts\Translation\TranslatorInterface" or null, "stdClass" given.'); | ||
|
||
new ValidatorExtension($validator, null, new \stdClass()); | ||
} | ||
|
||
public function test2Dot5ValidationApi() | ||
{ | ||
$metadata = new ClassMetadata(Form::class); | ||
|
||
$metadataFactory = new FakeMetadataFactory(); | ||
$metadataFactory->addMetadata($metadata); | ||
|
||
$validator = Validation::createValidatorBuilder() | ||
->setMetadataFactory($metadataFactory) | ||
->getValidator(); | ||
|
||
$extension = new ValidatorExtension($validator); | ||
|
||
$this->assertInstanceOf(ValidatorTypeGuesser::class, $extension->loadTypeGuesser()); | ||
|
||
$this->assertCount(1, $metadata->getConstraints()); | ||
$this->assertInstanceOf(FormConstraint::class, $metadata->getConstraints()[0]); | ||
|
||
$this->assertSame(CascadingStrategy::NONE, $metadata->cascadingStrategy); | ||
$this->assertSame(TraversalStrategy::NONE, $metadata->traversalStrategy); | ||
$this->assertCount(0, $metadata->getPropertyMetadata('children')); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.