Skip to content

Commit a266ff7

Browse files
angelkxabbuh
authored andcommitted
added test for staticClassLoader in LazyLoadingMetadatafactory
1 parent d3673a8 commit a266ff7

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Fixtures;
13+
14+
use Symfony\Component\Validator\Mapping\ClassMetadata;
15+
use Symfony\Component\Validator\Constraints\Length;
16+
17+
class EntityStaticCar extends EntityStaticVehicle
18+
{
19+
public static function loadValidatorMetadata(ClassMetadata $metadata)
20+
{
21+
$metadata->addPropertyConstraint('wheels', new Length(array('max' => 99)));
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Fixtures;
13+
14+
use Symfony\Component\Validator\Mapping\ClassMetadata;
15+
use Symfony\Component\Validator\Constraints\Length;
16+
17+
class EntityStaticCarTurbo extends EntityStaticCar
18+
{
19+
public static function loadValidatorMetadata(ClassMetadata $metadata)
20+
{
21+
$metadata->addPropertyConstraint('wheels', new Length(array('max' => 99)));
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Fixtures;
13+
14+
use Symfony\Component\Validator\Mapping\ClassMetadata;
15+
use Symfony\Component\Validator\Constraints\Length;
16+
17+
class EntityStaticVehicle
18+
{
19+
public $wheels;
20+
21+
public static function loadValidatorMetadata(ClassMetadata $metadata)
22+
{
23+
$metadata->addPropertyConstraint('wheels', new Length(array('max' => 99)));
24+
}
25+
}

src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,21 @@ public function testMetadataCacheWithRuntimeConstraint()
168168

169169
$metadata = $factory->getMetadataFor(self::CLASS_NAME);
170170
}
171+
172+
public function testGroupsFromParent()
173+
{
174+
$reader = new \Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader();
175+
$factory = new LazyLoadingMetadataFactory($reader);
176+
$metadata = $factory->getMetadataFor('Symfony\Component\Validator\Tests\Fixtures\EntityStaticCarTurbo');
177+
$classMetaData = $metadata->getPropertyMetadata('wheels');
178+
$constraints = $classMetaData[0]->getConstraints();
179+
$groups = $constraints[0]->groups;
180+
181+
$this->assertContains('Default', $groups);
182+
$this->assertContains('EntityStaticCarTurbo', $groups);
183+
$this->assertContains('EntityStaticCar', $groups);
184+
$this->assertContains('EntityStaticVehicle', $groups);
185+
}
171186
}
172187

173188
class TestLoader implements LoaderInterface

0 commit comments

Comments
 (0)