8000 [Config] Fix checking class existence freshness by nicolas-grekas · Pull Request #23755 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Config] Fix checking class existence freshness #23755

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

Merged
merged 1 commit into from
Aug 2, 2017
Merged
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 @@ -65,7 +65,7 @@ public function isFresh($timestamp)
{
$loaded = class_exists($this->resource, false) || interface_exists($this->resource, false) || trait_exists($this->resource, false);

if (null !== $exists = &self::$existsCache[$this->resource]) {
if (null !== $exists = &self::$existsCache[(int) (0 >= $timestamp)][$this->resource]) {
$exists = $exists || $loaded;
} elseif (!$exists = $loaded) {
if (!self::$autoloadLevel++) {
Expand All @@ -76,6 +76,11 @@ public function isFresh($timestamp)

try {
$exists = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false);
} catch (\ReflectionException $e) {
if (0 >= $timestamp) {
unset(self::$existsCache[1][$this->resource]);
throw $e;
}
} finally {
self::$autoloadedClass = $autoloadedClass;
if (!--self::$autoloadLevel) {
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/Config/Tests/Fixtures/BadParent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Component\Config\Tests\Fixtures;

class BadParent extends MissingParent
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\ClassExistenceResource;
use Symfony\Component\Config\Tests\Fixtures\Resource\ConditionalClass;
use Symfony\Component\Config\Tests\Fixtures\BadParent;

class ClassExistenceResourceTest extends TestCase
{
Expand Down Expand Up @@ -74,6 +75,22 @@ public function testExistsKo()
}
}

public function testBadParentWithTimestamp()
{
$res = new ClassExistenceResource(BadParent::class, false);
$this->assertTrue($res->isFresh(time()));
}

/**
* @expectedException \ReflectionException
* @expectedExceptionMessage Class Symfony\Component\Config\Tests\Fixtures\MissingParent not found
*/
public function testBadParentWithNoTimestamp()
{
$res = new ClassExistenceResource(BadParent::class, false);
$res->isFresh(0);
}

public function testConditionalClass()
{
$res = new ClassExistenceResource(ConditionalClass::class, false);
Expand Down
0