|
12 | 12 | namespace Symfony\Component\Validator\Tests\Mapping\Factory;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Component\Cache\Exception\InvalidArgumentException; |
15 | 16 | use Symfony\Component\Validator\Constraints\Callback;
|
| 17 | +use Symfony\Component\Validator\Exception\NoSuchMetadataException; |
16 | 18 | use Symfony\Component\Validator\Mapping\ClassMetadata;
|
17 | 19 | use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
|
18 | 20 | use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
|
@@ -192,6 +194,24 @@ public function testGroupsFromParent()
|
192 | 194 | $this->assertContains('EntityStaticCar', $groups);
|
193 | 195 | $this->assertContains('EntityStaticVehicle', $groups);
|
194 | 196 | }
|
| 197 | + |
| 198 | + public function testNonClassNameStringValues() |
| 199 | + { |
| 200 | + $testedValue = 'error@example.com'; |
| 201 | + $loader = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock(); |
| 202 | + $cache = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Cache\CacheInterface')->getMock(); |
| 203 | + $factory = new LazyLoadingMetadataFactory($loader, $cache); |
| 204 | + $cache |
| 205 | + ->method('read') |
| 206 | + ->with($testedValue) |
| 207 | + ->willThrowException(new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters {}()/\@:', $testedValue))); |
| 208 | + $this->expectException(NoSuchMetadataException::class); |
| 209 | + try { |
| 210 | + $factory->getMetadataFor($testedValue); |
| 211 | + } catch (InvalidArgumentException $exception) { |
| 212 | + $this->fail(sprintf('Unexpected %s thrown', InvalidArgumentException::class)); |
| 213 | + } |
| 214 | + } |
195 | 215 | }
|
196 | 216 |
|
197 | 217 | class TestLoader implements LoaderInterface
|
|
0 commit comments