8000 [Validator] Fix LazyLoadingMetadataFactory with PSR6Cache for non cla… · symfony/symfony@712ae7b · GitHub
[go: up one dir, main page]

Skip to content

Commit 712ae7b

Browse files
author
Pascal Montoya
committed
[Validator] Fix LazyLoadingMetadataFactory with PSR6Cache for non classname if tested values isn't existing class
1 parent c415e4c commit 712ae7b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,17 @@ public function getMetadataFor($value)
9090
return $this->loadedClasses[$class];
9191
}
9292

93+
if (!class_exists($class) && !interface_exists($class)) {
94+
throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
95+
}
96+
9397
if (null !== $this->cache && false !== ($metadata = $this->cache->read($class))) {
9498
// Include constraints from the parent class
9599
$this->mergeConstraints($metadata);
96100

97101
return $this->loadedClasses[$class] = $metadata;
98102
}
99103

100-
if (!class_exists($class) && !interface_exists($class)) {
101-
throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
102-
}
103-
104104
$metadata = new ClassMetadata($class);
105105

106106
if (null !== $this->loader) {

src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ public function testReadMetadataFromCache()
149149
$this->assertEquals($metadata, $factory->getMetadataFor(self::PARENT_CLASS));
150150
}
151151

152+
public function testNonClassNameStringValues()
153+
{
154+
$testedValue = 'error@example.com';
155+
$loader = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock();
156+
$cache = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Cache\CacheInterface')->getMock();
157+
$factory = new LazyLoadingMetadataFactory($loader, $cache);
158+
$cache
159+
->expects($this->never())
160+
->method('read');
161+
$this->expectException('Symfony\Component\Validator\Exception\NoSuchMetadataException');
162+
$factory->getMetadataFor($testedValue);
163+
}
164+
152165
public function testMetadataCacheWithRuntimeConstraint()
153166
{
154167
$cache = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Cache\CacheInterface')->getMock();

0 commit comments

Comments
 (0)
0