bug #13744 minor #13377 [Console] Change greater by greater or equal for isFresh in FileResource (bijibox)

This PR was merged into the 2.3 branch.

Discussion
----------

minor #13377 [Console] Change greater by greater or equal for isFresh in FileResource

| Q             | A
| ------------- | ---
| Fixed tickets | #13377
| License       | MIT

FileResource and tests update

Commits
-------

87800ae minor #13377 [Console] Change greater by greater or equal for isFresh in FileResource
This commit is contained in:
Fabien Potencier 2015-02-25 12:39:01 +01:00
commit e0ba4d65af
3 changed files with 9 additions and 6 deletions

View File

@ -60,7 +60,7 @@ class FileResource implements ResourceInterface, \Serializable
return false; return false;
} }
return filemtime($this->resource) < $timestamp; return filemtime($this->resource) <= $timestamp;
} }
public function serialize() public function serialize()

View File

@ -128,7 +128,7 @@ class ConfigCacheTest extends \PHPUnit_Framework_TestCase
private function makeCacheStale() private function makeCacheStale()
{ {
touch($this->cacheFile, time() - 3600); touch($this->cacheFile, filemtime($this->resourceFile) - 3600);
} }
private function generateMetaFile() private function generateMetaFile()

View File

@ -17,11 +17,13 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
{ {
protected $resource; protected $resource;
protected $file; protected $file;
protected $time;
protected function setUp() protected function setUp()
{ {
$this->file = realpath(sys_get_temp_dir()).'/tmp.xml'; $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); $this->resource = new FileResource($this->file);
} }
@ -42,11 +44,12 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
public function testIsFresh() public function testIsFresh()
{ {
$this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed'); $this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second');
$this->assertFalse($this->resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated'); $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)); $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() public function testSerializeUnserialize()