|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Validator\Tests\Mapping\Factory;
|
13 | 13 |
|
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\Cache\Exception\InvalidArgumentException; |
14 | 16 | use Symfony\Component\Validator\Constraints\Callback;
|
| 17 | +use Symfony\Component\Validator\Exception\NoSuchMetadataException; |
15 | 18 | use Symfony\Component\Validator\Mapping\ClassMetadata;
|
16 | 19 | use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
|
17 | 20 | use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
|
18 | 21 | use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
19 | 22 |
|
20 |
| -class LazyLoadingMetadataFactoryTest extends \PHPUnit_Framework_TestCase |
| 23 | +class LazyLoadingMetadataFactoryTest extends TestCase |
21 | 24 | {
|
22 | 25 | const CLASS_NAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
|
23 | 26 | const PARENT_CLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
|
@@ -166,7 +169,48 @@ public function testMetadataCacheWithRuntimeConstraint()
|
166 | 169 | $metadata = $factory->getMetadataFor(self::PARENT_CLASS);
|
167 | 170 | $metadata->addConstraint(new Callback(function () {}));
|
168 | 171 |
|
| 172 | + $this->assertCount(3, $metadata->getConstraints()); |
| 173 | + |
169 | 174 | $metadata = $factory->getMetadataFor(self::CLASS_NAME);
|
| 175 | + |
| 176 | + $this->assertCount(6, $metadata->getConstraints()); |
| 177 | + } |
| 178 | + |
| 179 | + public function testGroupsFromParent() |
| 180 | + { |
| 181 | + $reader = new \Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader(); |
| 182 | + $factory = new LazyLoadingMetadataFactory($reader); |
| 183 | + $metadata = $factory->getMetadataFor('Symfony\Component\Validator\Tests\Fixtures\EntityStaticCarTurbo'); |
| 184 | + $groups = array(); |
| 185 | + |
| 186 | + foreach ($metadata->getPropertyMetadata('wheels') as $propertyMetadata) { |
| 187 | + $constraints = $propertyMetadata->getConstraints(); |
| 188 | + $groups = array_replace($groups, $constraints[0]->groups); |
| 189 | + } |
| 190 | + |
| 191 | + $this->assertCount(4, $groups); |
| 192 | + $this->assertContains('Default', $groups); |
| 193 | + $this->assertContains('EntityStaticCarTurbo', $groups); |
| 194 | + $this->assertContains('EntityStaticCar', $groups); |
| 195 | + $this->assertContains('EntityStaticVehicle', $groups); |
| 196 | + } |
| 197 | + |
| 198 | + public function testNonClassNameStringValues() |
| 199 | + { |
| 200 | + $testedValue = 'error@example.com'; |
| 201 | + $loader = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock(); |
| 202 | + $cache = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Cache\CacheInterface')->getMock(); |
| 203 | + $factory = new LazyLoadingMetadataFactory($loader, $cache); |
| 204 | + $cache |
| 205 | + ->method('read') |
| 206 | + ->with($testedValue) |
| 207 | + ->willThrowException(new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters {}()/\@:', $testedValue))); |
| 208 | + $this->expectException(NoSuchMetadataException::class); |
| 209 | + try { |
| 210 | + $factory->getMetadataFor($testedValue); |
| 211 | + } catch (InvalidArgumentException $exception) { |
| 212 | + $this->fail(sprintf('Unexpected %s thrown', InvalidArgumentException::class)); |
| 213 | + } |
170 | 214 | }
|
171 | 215 | }
|
172 | 216 |
|
|
0 commit comments