Skip to content

Commit

Permalink
[Config] Fix checking class existence freshness
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Aug 2, 2017
1 parent 468b44a commit a63ab77
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Component\Config\Tests\Fixtures;

class BadParent extends MissingParent
{
}
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 comments on commit a63ab77

Please sign in to comment.