File tree 2 files changed +17
-4
lines changed
src/Symfony/Component/Validator
2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -90,17 +90,17 @@ public function getMetadataFor($value)
90
90
return $ this ->loadedClasses [$ class ];
91
91
}
92
92
93
+ if (!class_exists ($ class ) && !interface_exists ($ class )) {
94
+ throw new NoSuchMetadataException (sprintf ('The class or interface "%s" does not exist. ' , $ class ));
95
+ }
96
+
93
97
if (null !== $ this ->cache && false !== ($ metadata = $ this ->cache ->read ($ class ))) {
94
98
// Include constraints from the parent class
95
99
$ this ->mergeConstraints ($ metadata );
96
100
97
101
return $ this ->loadedClasses [$ class ] = $ metadata ;
98
102
}
99
103
100
- if (!class_exists ($ class ) && !interface_exists ($ class )) {
101
- throw new NoSuchMetadataException (sprintf ('The class or interface "%s" does not exist. ' , $ class ));
102
- }
103
-
104
104
$ metadata = new ClassMetadata ($ class );
105
105
106
106
if (null !== $ this ->loader ) {
Original file line number Diff line number Diff line change @@ -149,6 +149,19 @@ public function testReadMetadataFromCache()
149
149
$ this ->assertEquals ($ metadata , $ factory ->getMetadataFor (self ::PARENT_CLASS ));
150
150
}
151
151
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
+
152
165
public function testMetadataCacheWithRuntimeConstraint ()
153
166
{
154
167
$ cache = $ this ->getMockBuilder ('Symfony\Component\Validator\Mapping\Cache\CacheInterface ' )->getMock ();
You can’t perform that action at this time.
0 commit comments