Skip to content

Commit

Permalink
minor #13377 [Console] Change greater by greater or equal for isFresh…
Browse files Browse the repository at this point in the history
… in FileResource
  • Loading branch information
bijibox committed Feb 19, 2015
1 parent 19aa6dc commit 87800ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Resource/FileResource.php
Expand Up @@ -60,7 +60,7 @@ public function isFresh($timestamp)
return false;
}

return filemtime($this->resource) < $timestamp;
return filemtime($this->resource) <= $timestamp;
}

public function serialize()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Tests/ConfigCacheTest.php
Expand Up @@ -128,7 +128,7 @@ private function makeCacheFresh()

private function makeCacheStale()
{
touch($this->cacheFile, time() - 3600);
touch($this->cacheFile, filemtime($this->resourceFile) - 3600);
}

private function generateMetaFile()
Expand Down
11 changes: 7 additions & 4 deletions src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php
Expand Up @@ -17,11 +17,13 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
{
protected $resource;
protected $file;
protected $time;

protected function setUp()
{
$this->file = realpath(sys_get_temp_dir()).'/tmp.xml';
touch($this->file);
$this->time = time();
touch($this->file, $this->time);
$this->resource = new FileResource($this->file);
}

Expand All @@ -42,11 +44,12 @@ public function testToString()

public function testIsFresh()
{
$this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed');
$this->assertFalse($this->resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated');
$this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second');
$this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed');
$this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated');

$resource = new FileResource('/____foo/foobar'.rand(1, 999999));
$this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the resource does not exist');
$this->assertFalse($resource->isFresh($this->time), '->isFresh() returns false if the resource does not exist');
}

public function testSerializeUnserialize()
Expand Down

0 comments on commit 87800ae

Please sign in to comment.