File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
src/Symfony/Component/Validator Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments