protected function setUp()
{
- $this->file = realpath(sys_get_temp_dir()).'/tmp.xml';
+ $this->file = sys_get_temp_dir().'/tmp.xml';
$this->time = time();
touch($this->file, $this->time);
$this->resource = new FileResource($this->file);
protected function tearDown()
{
+ if (!file_exists($this->file)) {
+ return;
+ }
+
unlink($this->file);
}
$this->assertSame(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
}
+ public function testGetResourceWithScheme()
+ {
+ $resource = new FileResource('file://'.$this->file);
+ $this->assertSame('file://'.$this->file, $resource->getResource(), '->getResource() returns the path to the schemed resource');
+ }
+
public function testToString()
{
$this->assertSame(realpath($this->file), (string) $this->resource);
}
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessageRegExp /The file ".*" does not exist./
+ */
+ public function testResourceDoesNotExist()
+ {
+ $resource = new FileResource('/____foo/foobar'.mt_rand(1, 999999));
+ }
+
public function testIsFresh()
{
$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'.mt_rand(1, 999999));
- $this->assertFalse($resource->isFresh($this->time), '->isFresh() returns false if the resource does not exist');
+ public function testIsFreshForDeletedResources()
+ {
+ unlink($this->file);
+
+ $this->assertFalse($this->resource->isFresh($this->time), '->isFresh() returns false if the resource does not exist');
}
public function testSerializeUnserialize()