Skip to content
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
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/ConstraintViolation.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __toString()
$class .= '.';
}

if ('' !== $code = $this->code) {
if ('' !== $code = (string) $this->code) {
$code = ' (code '.$code.')';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ public function testToStringOmitsEmptyCodes()
$this->assertSame($expected, (string) $violation);
}

/**
* @group legacy
* @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.
*/
public function testNonStringCode()
{
$violation = new ConstraintViolation(
Expand All @@ -126,6 +122,6 @@ public function testNonStringCode()
42
);

self::assertSame(42, $violation->getCode());
self::assertSame('42', $violation->getCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@

class ConstraintViolationBuilderTest extends TestCase
{
/**
* @group legacy
* @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.
* @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.
*/
public function testNonStringCode()
{
$constraintViolationList = new ConstraintViolationList();
(new ConstraintViolationBuilder($constraintViolationList, new ConstraintA(), 'invalid message', [], null, 'foo', 'baz', new IdentityTranslator()))
->setCode(42)
->addViolation();

self::assertSame(42, $constraintViolationList->get(0)->getCode());
self::assertSame('42', $constraintViolationList->get(0)->getCode());
}
}