File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff 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 ) {
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