File tree 2 files changed +24
-4
lines changed
src/Symfony/Component/Validator 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -99,17 +99,17 @@ public function getMetadataFor($value)
99
99
return $ this ->loadedClasses [$ class ];
100
100
}
101
101
102
+ if (!class_exists ($ class ) && !interface_exists ($ class )) {
103
+ throw new NoSuchMetadataException (sprintf ('The class or interface "%s" does not exist. ' , $ class ));
104
+ }
105
+
102
106
if (null !== $ this ->cache && false !== ($ metadata = $ this ->cache ->read ($ class ))) {
103
107
// Include constraints from the parent class
104
108
$ this ->mergeConstraints ($ metadata );
105
109
106
110
return $ this ->loadedClasses [$ class ] = $ metadata ;
107
111
}
108
112
109
- if (!class_exists ($ class ) && !interface_exists ($ class )) {
110
- throw new NoSuchMetadataException (sprintf ('The class or interface "%s" does not exist. ' , $ class ));
111
- }
112
-
113
113
$ metadata = new ClassMetadata ($ class );
114
114
115
115
if (null !== $ this ->loader ) {
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \Validator \Tests \Mapping \Factory ;
13
13
14
+ use Symfony \Component \Cache \Exception \InvalidArgumentException ;
14
15
use Symfony \Component \Validator \Constraints \Callback ;
16
+ use Symfony \Component \Validator \Exception \NoSuchMetadataException ;
15
17
use Symfony \Component \Validator \Mapping \ClassMetadata ;
16
18
use Symfony \Component \Validator \Mapping \Factory \LazyLoadingMetadataFactory ;
17
19
use Symfony \Component \Validator \Mapping \Loader \LoaderInterface ;
@@ -168,6 +170,24 @@ public function testMetadataCacheWithRuntimeConstraint()
168
170
169
171
$ metadata = $ factory ->getMetadataFor (self ::CLASS_NAME );
170
172
}
173
+
174
+ public function testNonClassNameStringValues ()
175
+ {
176
+ $ testedValue = 'error@example.com ' ;
177
+ $ loader = $ this ->getMockBuilder ('Symfony\Component\Validator\Mapping\Loader\LoaderInterface ' )->getMock ();
178
+ $ cache = $ this ->getMockBuilder ('Symfony\Component\Validator\Mapping\Cache\CacheInterface ' )->getMock ();
179
+ $ factory = new LazyLoadingMetadataFactory ($ loader , $ cache );
180
+ $ cache
181
+ ->method ('read ' )
182
+ ->with ($ testedValue )
183
+ ->willThrowException (new InvalidArgumentException (sprintf ('Cache key "%s" contains reserved characters {}()/\@: ' , $ testedValue )));
184
+ $ this ->expectException (NoSuchMetadataException::class);
185
+ try {
186
+ $ factory ->getMetadataFor ($ testedValue );
187
+ } catch (InvalidArgumentException $ exception ) {
188
+ $ this ->fail (sprintf ('Unexpected %s thrown ' , InvalidArgumentException::class));
189
+ }
190
+ }
171
191
}
172
192
173
193
class TestLoader implements LoaderInterface
You can’t perform that action at this time.
0 commit comments