Skip to content

Commit

Permalink
bug #23755 [Config] Fix checking class existence freshness (nicolas-g…
Browse files Browse the repository at this point in the history
…rekas)

This PR was merged into the 3.3 branch.

Discussion
----------

[Config] Fix checking class existence freshness

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23753
| License       | MIT
| Doc PR        | -

Commits
-------

a63ab77 [Config] Fix checking class existence freshness
  • Loading branch information
ogizanagi committed Aug 2, 2017
2 parents 468b44a + a63ab77 commit b98a4a3
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 b98a4a3

Please sign in to comment.