Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf6a5b3

Browse files
minor #32372 [Validator] Fix tests (ogizanagi)
This PR was merged into the 5.0-dev branch. Discussion ---------- [Validator] Fix tests | Q | A | ------------- | --- | Branch? | master <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | relates to #32265 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A Fixes the following tests currently failing on master, as well as a bug where a null code was printed: ```diff 1) Symfony\Component\Validator\Tests\ConstraintViolationListTest::testToString Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ 'Root:\n - Error 1\n + Error 1 (code )\n Root.foo.bar:\n - Error 2\n + Error 2 (code )\n Root[baz]:\n - Error 3\n + Error 3 (code )\n foo.bar:\n - Error 4\n + Error 4 (code )\n [baz]:\n - Error 5\n + Error 5 (code )\n 2) Symfony\Component\Validator\Tests\ConstraintViolationTest::testToStringHandlesArrays Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ 'Root.property.path: - Array' + Array (code )' 3) Symfony\Component\Validator\Tests\ConstraintViolationTest::testToStringHandlesArrayRoots Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ 'Array.some_value: - 42 cannot be used here' + 42 cannot be used here (code )' 4) Symfony\Component\Validator\Tests\ConstraintViolationTest::testToStringOmitsEmptyCodes Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ 'Array.some_value: - 42 cannot be used here' + 42 cannot be used here (code )' 5) Symfony\Component\Validator\Tests\ConstraintViolationTest::testNonStringCode Failed asserting that '42' is identical to 42. 6) Symfony\Component\Validator\Tests\Violation\ConstraintViolationBuilderTest::testNonStringCode Failed asserting that '42' is identical to 42. ``` Commits ------- 22c58f5 [Validator] Fix tests
2 parents 155cfb2 + 22c58f5 commit cf6a5b3

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

src/Symfony/Component/Validator/ConstraintViolation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function __toString()
8484
$class .= '.';
8585
}
8686

87-
if ('' !== $code = $this->code) {
87+
if ('' !== $code = (string) $this->code) {
8888
$code = ' (code '.$code.')';
8989
}
9090

src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ public function testToStringOmitsEmptyCodes()
109109
$this->assertSame($expected, (string) $violation);
110110
}
111111

112-
/**
113-
* @group legacy
114-
* @expectedDeprecation Not using a string as the error code in Symfony\Component\Validator\ConstraintViolation::__construct() is deprecated since Symfony 4.4. A type-hint will be added in 5.0.
115-
*/
116112
public function testNonStringCode()
117113
{
118114
$violation = new ConstraintViolation(
@@ -126,6 +122,6 @@ public function testNonStringCode()
126122
42
127123
);
128124

129-
self::assertSame(42, $violation->getCode());
125+
self::assertSame('42', $violation->getCode());
130126
}
131127
}

src/Symfony/Component/Validator/Tests/Violation/ConstraintViolationBuilderTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,13 @@
1919

2020
class ConstraintViolationBuilderTest extends TestCase
2121
{
22-
/**
23-
* @group legacy
24-
* @expectedDeprecation Not using a string as the error code in Symfony\Component\Validator\Violation\ConstraintViolationBuilder::setCode() is deprecated since Symfony 4.4. A type-hint will be added in 5.0.
25-
* @expectedDeprecation Not using a string as the error code in Symfony\Component\Validator\ConstraintViolation::__construct() is deprecated since Symfony 4.4. A type-hint will be added in 5.0.
26-
*/
2722
public function testNonStringCode()
2823
{
2924
$constraintViolationList = new ConstraintViolationList();
3025
(new ConstraintViolationBuilder($constraintViolationList, new ConstraintA(), 'invalid message', [], null, 'foo', 'baz', new IdentityTranslator()))
3126
->setCode(42)
3227
->addViolation();
3328

34-
self::assertSame(42, $constraintViolationList->get(0)->getCode());
29+
self::assertSame('42', $constraintViolationList->get(0)->getCode());
3530
}
3631
}

0 commit comments

Comments
 (0)