Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FrameworkBundle] Validator cache fails with annotations #21102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,40 @@ public function testWarmUp()
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author', $values);
}

public function testWarmUpWithAnnotations()
{
$validatorBuilder = new ValidatorBuilder();
$validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/categories.yml');
$validatorBuilder->enableAnnotationMapping();

$file = sys_get_temp_dir().'/cache-validator-with-annotations.php';
@unlink($file);

$fallbackPool = new ArrayAdapter();

$warmer = new ValidatorCacheWarmer($validatorBuilder, $file, $fallbackPool);
$warmer->warmUp(dirname($file));

$this->assertFileExists($file);

$values = require $file;

$this->assertInternalType('array', $values);
$this->assertCount(2, $values);
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category', $values);
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.SubCategory', $values);

// Simple check to make sure that at least one constraint is actually cached, in this case the "id" property Type.
$this->assertContains('"int"', $values['Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category']);

$values = $fallbackPool->getValues();

$this->assertInternalType('array', $values);
$this->assertCount(2, $values);
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category', $values);
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.SubCategory', $values);
}

public function testWarmUpWithoutLoader()
{
$validatorBuilder = new ValidatorBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation;

class Category
{
const NAME_PATTERN = '/\w+/';

public $id;

/**
* @Assert\Type(self::NAME_PATTERN)
*/
public $name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\Category:
properties:
id:
- Type: int

Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\SubCategory:
properties:
id:
- Type: int
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation;

use Symfony\Component\Validator\Constraints as Assert;

class SubCategory extends Category
{
/**
* @Assert\Type(Category::class)
*/
public $main;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ public function getMetadataFor($value)
return $this->loadedClasses[$class];
}

if (null !== $this->cache && false !== ($this->loadedClasses[$class] = $this->cache->read($class))) {
return $this->loadedClasses[$class];
if (null !== $this->cache) {
$cached = $this->cache->read($class);

if (false !== $cached) {
return $this->loadedClasses[$class] = $cached;
}
}

if (!class_exists($class) && !interface_exists($class)) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.