Skip to content

Commit 9ee969d

Browse files
mpajunennicolas-grekas
authored andcommitted
[FrameworkBundle] Add annotated validator cache test case
1 parent c60009e commit 9ee969d

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php

+33
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,39 @@ public function testWarmUp()
5151
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author', $values);
5252
}
5353

54+
public function testWarmUpWithAnnotations()
55+
{
56+
$validatorBuilder = new ValidatorBuilder();
57+
$validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/categories.yml');
58+
$validatorBuilder->enableAnnotationMapping();
59+
60+
$file = sys_get_temp_dir().'/cache-validator-with-annotations.php';
61+
@unlink($file);
62+
63+
$fallbackPool = new ArrayAdapter();
64+
65+
$warmer = new ValidatorCacheWarmer($validatorBuilder, $file, $fallbackPool);
66+
$warmer->warmUp(dirname($file));
67+
68+
$this->assertFileExists($file);
69+
70+
$values = require $file;
71+
72+
$this->assertInternalType('array', $values);
73+
$this->assertCount(1, $values);
74+
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category', $values);
75+
76+
// Simple check to make sure that at least one constraint is actually cached, in this case the "id" property Type.
77+
$this->assertContains('"int"', $values['Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category']);
78+
79+
$values = $fallbackPool->getValues();
80+
81+
$this->assertInternalType('array', $values);
82+
$this->assertCount(2, $values);
83+
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category', $values);
84+
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.SubCategory', $values);
85+
}
86+
5487
public function testWarmUpWithoutLoader()
5588
{
5689
$validatorBuilder = new ValidatorBuilder();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation;
4+
5+
use Symfony\Component\Validator\Constraints as Assert;
6+
7+
class Category
8+
{
9+
const NAME_PATTERN = '/\w+/';
10+
11+
public $id;
12+
13+
/**
14+
* @Assert\Type(Category::NAME_PATTERN)
15+
*/
16+
public $name;
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\Category:
2+
properties:
3+
id:
4+
- Type: int
5+
6+
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\SubCategory:
7+
properties:
8+
id:
9+
- Type: int
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation;
4+
5+
// Missing "use" for Assert\Type is on purpose
6+
7+
class SubCategory extends Category
8+
{
9+
/**
10+
* @Assert\Type(Category::class)
11+
*/
12+
public $main;
13+
}

0 commit comments

Comments
 (0)