Skip to content

Commit 76f090f

Browse files
Merge branch '2.8' into 3.4
* 2.8: [Console] Don't go past exact matches when autocompleting Disable autoloader call on interface_exists check [Validator] Fix LazyLoadingMetadataFactory with PSR6Cache for non classname if tested values isn't an existing class
2 parents 6fa4126 + 87d1f81 commit 76f090f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Mapping/Factory/LazyLoadingMetadataFactory.php

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

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

9599
return $this->loadedClasses[$class] = $metadata;
96100
}
97101

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

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

Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php

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

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

0 commit comments

Comments
 (0)