Skip to content

Commit

Permalink
Merge branch '4.1' into 4.2
Browse files Browse the repository at this point in the history
* 4.1:
  fix cs
  [Validator] Allow `ConstraintViolation::__toString()` to expose codes that are not null or emtpy strings
  fix type for $value in DocBlock
  [WebProfilerBundle] Fix title case
  Fix wrapped loop of event listener
  [DI] fix edge case in InlineServiceDefinitionsPass
  undeprecate the single-colon notation for controllers
  Update HttpKernel.php
  • Loading branch information
nicolas-grekas committed Dec 1, 2018
2 parents ad13cdf + ba6e80f commit 81e0f38
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ConstraintViolation.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public function __toString()
}

$propertyPath = (string) $this->propertyPath;
$code = $this->code;
$code = (string) $this->code;

if ('' !== $propertyPath && '[' !== $propertyPath[0] && '' !== $class) {
$class .= '.';
}

if (!empty($code)) {
if ('' !== $code) {
$code = ' (code '.$code.')';
}

Expand Down
55 changes: 55 additions & 0 deletions Tests/ConstraintViolationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,59 @@ public function testToStringHandlesArrayRoots()

$this->assertSame($expected, (string) $violation);
}

public function testToStringHandlesCodes()
{
$violation = new ConstraintViolation(
'42 cannot be used here',
'this is the message template',
array(),
array('some_value' => 42),
'some_value',
null,
null,
0
);

$expected = <<<'EOF'
Array.some_value:
42 cannot be used here (code 0)
EOF;

$this->assertSame($expected, (string) $violation);
}

public function testToStringOmitsEmptyCodes()
{
$expected = <<<'EOF'
Array.some_value:
42 cannot be used here
EOF;

$violation = new ConstraintViolation(
'42 cannot be used here',
'this is the message template',
array(),
array('some_value' => 42),
'some_value',
null,
null,
null
);

$this->assertSame($expected, (string) $violation);

$violation = new ConstraintViolation(
'42 cannot be used here',
'this is the message template',
array(),
array('some_value' => 42),
'some_value',
null,
null,
''
);

$this->assertSame($expected, (string) $violation);
}
}

0 comments on commit 81e0f38

Please sign in to comment.