8000 [Validator] Improves the exception message for invalid normalizers · symfony/symfony@afacc2b · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit afacc2b

Browse files
committed
[Validator] Improves the exception message for invalid normalizers
1 parent 99aac0f commit afacc2b

File tree

14 files changed

+77
-14
lines changed

14 files changed

+77
-14
lines changed

src/Symfony/Component/Validator/Constraints/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function __construct($options = null)
101101
}
102102

103103
if (null !== $this->normalizer && !\is_callable($options['normalizer'])) {
104-
throw new \InvalidArgumentException('The "normalizer" parameter value is not a valid callable.');
104+
throw new \InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', is_object($this->normalizer) ? get_class($this->normalizer) : gettype($this->normalizer)));
105105
}
106106
}
107107
}

src/Symfony/Component/Validator/Constraints/Ip.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function __construct($options = null)
8686
}
8787

8888
if (null !== $this->normalizer && !\is_callable($options['normalizer'])) {
89-
throw new \InvalidArgumentException('The "normalizer" parameter value is not a valid callable.');
89+
throw new \InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', is_object($this->normalizer) ? get_class($this->normalizer) : gettype($this->normalizer)));
9090
}
9191
}
9292
}

src/Symfony/Component/Validator/Constraints/Length.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct($options = null)
5757
}
5858

5959
if (null !== $this->normalizer && !\is_callable($options['normalizer'])) {
60-
throw new \InvalidArgumentException('The "normalizer" parameter value is not a valid callable.');
60+
throw new \InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', is_object($this->normalizer) ? get_class($this->normalizer) : gettype($this->normalizer)));
6161
}
6262
}
6363
}

src/Symfony/Component/Validator/Constraints/NotBlank.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct($options = null)
3737
parent::__construct($options);
3838

3939
if (null !== $this->normalizer && !\is_callable($options['normalizer'])) {
40-
throw new \InvalidArgumentException('The "normalizer" parameter value is not a valid callable.');
40+
throw new \InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', is_object($this->normalizer) ? get_class($this->normalizer) : gettype($this->normalizer)));
4141
}
4242
}
4343
}

src/Symfony/Component/Validator/Constraints/Regex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct($options = null)
3838
parent::__construct($options);
3939

4040
if (null !== $this->normalizer && !\is_callable($options['normalizer'])) {
41-
throw new \InvalidArgumentException('The "normalizer" parameter value is not a valid callable.');
41+
throw new \InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', is_object($this->normalizer) ? get_class($this->normalizer) : gettype($this->normalizer)));
4242
}
4343
}
4444

src/Symfony/Component/Validator/Constraints/Url.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function __construct($options = null)
121121
parent::__construct($options);
122122

123123
if (null !== $this->normalizer && !\is_callable($options['normalizer'])) {
124-
throw new \InvalidArgumentException('The "normalizer" parameter value is not a valid callable.');
124+
throw new \InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', is_object($this->normalizer) ? get_class($this->normalizer) : gettype($this->normalizer)));
125125
}
126126
}
127127
}

src/Symfony/Component/Validator/Constraints/Uuid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function __construct($options = null)
8282
parent::__construct($options);
8383

8484
if (null !== $this->normalizer && !\is_callable($options['normalizer'])) {
85-
throw new \InvalidArgumentException('The "normalizer" parameter value is not a valid callable.');
85+
throw new \InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', is_object($this->normalizer) ? get_class($this->normalizer) : gettype($this->normalizer)));
8686
}
8787
}
8888
}

src/Symfony/Component/Validator/Tests/Constraints/EmailTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,19 @@ public function testNormalizerCanBeSet()
5252

5353
/**
5454
* @expectedException \InvalidArgumentException
55-
* @expectedExceptionMessage The "normalizer" parameter value is not a valid callable.
55+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("string" given).
5656
*/
5757
public function testInvalidNormalizerThrowsException()
5858
{
5959
new Email(array('normalizer' => 'Unknown Callable'));
6060
}
61+
62+
/**
63+
* @expectedException \InvalidArgumentException
64+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("stdClass" given).
65+
*/
66+
public function testInvalidNormalizerObjectThrowsException()
67+
{
68+
new Email(array('normalizer' => new \stdClass()));
69+
}
6170
}

src/Symfony/Component/Validator/Tests/Constraints/IpTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@ public function testNormalizerCanBeSet()
2828

2929
/**
3030
* @expectedException \InvalidArgumentException
31-
* @expectedExceptionMessage The "normalizer" parameter value is not a valid callable.
31+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("string" given).
3232
*/
3333
public function testInvalidNormalizerThrowsException()
3434
{
3535
new Ip(array('normalizer' => 'Unknown Callable'));
3636
}
37+
38+
/**
39+
* @expectedException \InvalidArgumentException
40+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("stdClass" given).
41+
*/
42+
public function testInvalidNormalizerObjectThrowsException()
43+
{
44+
new Ip(array('normalizer' => new \stdClass()));
45+
}
3746
}

src/Symfony/Component/Validator/Tests/Constraints/LengthTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@ public function testNormalizerCanBeSet()
2828

2929
/**
3030
* @expectedException \InvalidArgumentException
31-
* @expectedExceptionMessage The "normalizer" parameter value is not a valid callable.
31+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("string" given).
3232
*/
3333
public function testInvalidNormalizerThrowsException()
3434
{
3535
new Length(array('min' => 0, 'max' => 10, 'normalizer' => 'Unknown Callable'));
3636
}
37+
38+
/**
39+
* @expectedException \InvalidArgumentException
40+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("stdClass" given).
41+
*/
42+
public function testInvalidNormalizerObjectThrowsException()
43+
{
44+
new Length(array('min' => 0, 'max' => 10, 'normalizer' => new \stdClass()));
45+
}
3746
}

src/Symfony/Component/Validator/Tests/Constraints/NotBlankTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@ public function testNormalizerCanBeSet()
2828

2929
/**
3030
* @expectedException \InvalidArgumentException
31-
* @expectedExceptionMessage The "normalizer" parameter value is not a valid callable.
31+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("string" given).
3232
*/
3333
public function testInvalidNormalizerThrowsException()
3434
{
3535
new NotBlank(array('normalizer' => 'Unknown Callable'));
3636
}
37+
38+
/**
39+
* @expectedException \InvalidArgumentException
40+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("stdClass" given).
41+
*/
42+
public function testInvalidNormalizerObjectThrowsException()
43+
{
44+
new NotBlank(array('normalizer' => new \stdClass()));
45+
}
3746
}

src/Symfony/Component/Validator/Tests/Constraints/RegexTest.php

Copy file name to clipboard
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,19 @@ public function testNormalizerCanBeSet()
9595

9696
/**
9797
* @expectedException \InvalidArgumentException
98-
* @expectedExceptionMessage The "normalizer" parameter value is not a valid callable.
98+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("string" given).
9999
*/
100100
public function testInvalidNormalizerThrowsException()
101101
{
102102
new Regex(array('pattern' => '/^[0-9]+$/', 'normalizer' => 'Unknown Callable'));
103103
}
104+
105+
/**
106+
* @expectedException \InvalidArgumentException
107+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("stdClass" given).
108+
*/
109+
public function testInvalidNormalizerObjectThrowsException()
110+
{
111+
new Regex(array('pattern' => '/^[0-9]+$/', 'normalizer' => new \stdClass()));
112+
}
104113
}

src/Symfony/Component/Validator/Tests/Constraints/UrlTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@ public function testNormalizerCanBeSet()
2828

2929
/**
3030
* @expectedException \InvalidArgumentException
31-
* @expectedExceptionMessage The "normalizer" parameter value is not a valid callable.
31+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("string" given).
3232
*/
3333
public function testInvalidNormalizerThrowsException()
3434
{
3535
new Url(array('normalizer' => 'Unknown Callable'));
3636
}
37+
38+
/**
39+
* @expectedException \InvalidArgumentException
40+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("stdClass" given).
41+
*/
42+
public function testInvalidNormalizerObjectThrowsException()
43+
{
44+
new Url(array('normalizer' => new \stdClass()));
45+
}
3746
}

src/Symfony/Component/Validator/Tests/Constraints/UuidTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@ public function testNormalizerCanBeSet()
2828

2929
/**
3030
* @expectedException \InvalidArgumentException
31-
* @expectedExceptionMessage The "normalizer" parameter value is not a valid callable.
31+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("string" given).
3232
*/
3333
public function testInvalidNormalizerThrowsException()
3434
{
3535
new Uuid(array('normalizer' => 'Unknown Callable'));
3636
}
37+
38+
/**
39+
* @expectedException \InvalidArgumentException
40+
* @expectedExceptionMessage The "normalizer" option must be a valid callable ("stdClass" given).
41+
*/
42+
public function testInvalidNormalizerObjectThrowsException()
43+
{
44+
new Uuid(array('normalizer' => new \stdClass()));
45+
}
3746
}

0 commit comments

Comments
 (0)
0