Skip to content

Commit 4158baa

Browse files
committed
minor #13515 [Form] fixed form tests when using 2.7 deps (fabpot)
This PR was merged into the 2.6 branch. Discussion ---------- [Form] fixed form tests when using 2.7 deps | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a This PR allows tests to pass for the Form subtree-split when using any version of the Validator component. The build was broken because the 2.4 API works in the same way as the 2.5 one in Symfony 2.7, so the cause is set. Testing the implementation of the context allows to know whether to expect the cause more reliably. Commits ------- a55f5c8 [Form] fixed form tests when using 2.7 deps
2 parents c32c775 + 67effa6 commit 4158baa

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

Tests/Extension/Validator/Constraints/FormValidatorTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Form\Extension\Validator\Constraints\Form;
1919
use Symfony\Component\Form\Extension\Validator\Constraints\FormValidator;
2020
use Symfony\Component\Form\SubmitButtonBuilder;
21+
use Symfony\Component\Validator\Context\ExecutionContextInterface;
2122
use Symfony\Component\Validator\Constraints\NotNull;
2223
use Symfony\Component\Validator\Constraints\NotBlank;
2324
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
@@ -224,14 +225,12 @@ function () { throw new TransformationFailedException(); }
224225

225226
$this->validator->validate($form, new Form());
226227

227-
$is2Dot4Api = Validation::API_VERSION_2_4 === $this->getApiVersion();
228-
229228
$this->buildViolation('invalid_message_key')
230229
->setParameter('{{ value }}', 'foo')
231230
->setParameter('{{ foo }}', 'bar')
232231
->setInvalidValue('foo')
233232
->setCode(Form::NOT_SYNCHRONIZED_ERROR)
234-
->setCause($is2Dot4Api ? null : $form->getTransformationFailure())
233+
->setCause($this->context instanceof ExecutionContextInterface ? $form->getTransformationFailure() : null)
235234
->assertRaised();
236235
}
237236

@@ -261,14 +260,12 @@ function () { throw new TransformationFailedException(); }
261260

262261
$this->validator->validate($form, new Form());
263262

264-
$is2Dot4Api = Validation::API_VERSION_2_4 === $this->getApiVersion();
265-
266263
$this->buildViolation('invalid_message_key')
267264
->setParameter('{{ value }}', 'foo')
268265
->setParameter('{{ foo }}', 'bar')
269266
->setInvalidValue('foo')
270267
->setCode(Form::NOT_SYNCHRONIZED_ERROR)
271-
->setCause($is2Dot4Api ? null : $form->getTransformationFailure())
268+
->setCause($this->context instanceof ExecutionContextInterface ? $form->getTransformationFailure() : null)
272269
->assertRaised();
273270
}
274271

@@ -298,13 +295,11 @@ function () { throw new TransformationFailedException(); }
298295

299296
$this->validator->validate($form, new Form());
300297

301-
$is2Dot4Api = Validation::API_VERSION_2_4 === $this->getApiVersion();
302-
303298
$this->buildViolation('invalid_message_key')
304299
->setParameter('{{ value }}', 'foo')
305300
->setInvalidValue('foo')
306301
->setCode(Form::NOT_SYNCHRONIZED_ERROR)
307-
->setCause($is2Dot4Api ? null : $form->getTransformationFailure())
302+
->setCause($this->context instanceof ExecutionContextInterface ? $form->getTransformationFailure() : null)
308303
->assertRaised();
309304
}
310305

0 commit comments

Comments
 (0)