Skip to content

Commit

Permalink
Fix exception messages and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Mar 29, 2019
1 parent 39439ff commit b04345d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/Symfony/Component/Validator/Constraint.php
Expand Up @@ -115,7 +115,7 @@ public function __construct($options = null)

if (\is_array($options) && isset($options['value']) && !property_exists($this, 'value')) {
if (null === $defaultOption) {
throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint %s', \get_class($this)));
throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint "%s".', \get_class($this)));
}

$options[$defaultOption] = $options['value'];
Expand All @@ -136,7 +136,7 @@ public function __construct($options = null)
}
} elseif (null !== $options && !(\is_array($options) && 0 === \count($options))) {
if (null === $defaultOption) {
throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint %s', \get_class($this)));
throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint "%s".', \get_class($this)));
}

if (\array_key_exists($defaultOption, $knownOptions)) {
Expand All @@ -148,11 +148,11 @@ public function __construct($options = null)
}

if (\count($invalidOptions) > 0) {
throw new InvalidOptionsException(sprintf('The options "%s" do not exist in constraint %s', implode('", "', $invalidOptions), \get_class($this)), $invalidOptions);
throw new InvalidOptionsException(sprintf('The options "%s" do not exist in constraint "%s".', implode('", "', $invalidOptions), \get_class($this)), $invalidOptions);
}

if (\count($missingOptions) > 0) {
throw new MissingOptionsException(sprintf('The options "%s" must be set for constraint %s', implode('", "', array_keys($missingOptions)), \get_class($this)), array_keys($missingOptions));
throw new MissingOptionsException(sprintf('The options "%s" must be set for constraint "%s".', implode('", "', array_keys($missingOptions)), \get_class($this)), array_keys($missingOptions));
}
}

Expand All @@ -176,7 +176,7 @@ public function __set($option, $value)
return;
}

throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, \get_class($this)), [$option]);
throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint "%s".', $option, \get_class($this)), [$option]);
}

/**
Expand All @@ -202,7 +202,7 @@ public function __get($option)
return $this->groups;
}

throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, \get_class($this)), [$option]);
throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint "%s".', $option, \get_class($this)), [$option]);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Tests/ConstraintTest.php
Expand Up @@ -225,7 +225,7 @@ public function testOptionsAsDefaultOption()

/**
* @expectedException \Symfony\Component\Validator\Exception\InvalidOptionsException
* @expectedExceptionMessage The options "0", "5" do not exist
* @expectedExceptionMessage The options "0", "5" do not exist in constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintA".
*/
public function testInvalidOptions()
{
Expand All @@ -245,7 +245,7 @@ public function testOptionsWithInvalidInternalPointer()

/**
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
* @expectedExceptionMessage No default option is configured for constraint Symfony\Component\Validator\Tests\Fixtures\ConstraintB
* @expectedExceptionMessage No default option is configured for constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintB".
*/
public function testAnnotationSetUndefinedDefaultOption()
{
Expand Down

0 comments on commit b04345d

Please sign in to comment.