[Config] Added tests for the FileResource and DirectoryResource.
This commit is contained in:
parent
c5dda79778
commit
804b1829ef
@ -50,13 +50,11 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
rmdir($directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\DirectoryResource::getResource
|
||||
*/
|
||||
public function testGetResource()
|
||||
{
|
||||
$resource = new DirectoryResource($this->directory);
|
||||
$this->assertEquals($this->directory, $resource->getResource(), '->getResource() returns the path to the resource');
|
||||
$this->assertSame($this->directory, $resource->getResource(), '->getResource() returns the path to the resource');
|
||||
$this->assertSame($this->directory, (string) $resource, '->__toString() returns the path to the resource');
|
||||
}
|
||||
|
||||
public function testGetPattern()
|
||||
@ -65,9 +63,6 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('bar', $resource->getPattern());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
|
||||
*/
|
||||
public function testIsFresh()
|
||||
{
|
||||
$resource = new DirectoryResource($this->directory);
|
||||
@ -78,9 +73,6 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the resource does not exist');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
|
||||
*/
|
||||
public function testIsFreshUpdateFile()
|
||||
{
|
||||
$resource = new DirectoryResource($this->directory);
|
||||
@ -88,9 +80,6 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if an existing file is modified');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
|
||||
*/
|
||||
public function testIsFreshNewFile()
|
||||
{
|
||||
$resource = new DirectoryResource($this->directory);
|
||||
@ -98,9 +87,6 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if a new file is added');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
|
||||
*/
|
||||
public function testIsFreshDeleteFile()
|
||||
{
|
||||
$resource = new DirectoryResource($this->directory);
|
||||
@ -108,9 +94,6 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if an existing file is removed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
|
||||
*/
|
||||
public function testIsFreshDeleteDirectory()
|
||||
{
|
||||
$resource = new DirectoryResource($this->directory);
|
||||
@ -118,9 +101,6 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the whole resource is removed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
|
||||
*/
|
||||
public function testIsFreshCreateFileInSubdirectory()
|
||||
{
|
||||
$subdirectory = $this->directory.'/subdirectory';
|
||||
@ -133,9 +113,6 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if a new file in a subdirectory is added');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
|
||||
*/
|
||||
public function testIsFreshModifySubdirectory()
|
||||
{
|
||||
$resource = new DirectoryResource($this->directory);
|
||||
@ -147,9 +124,6 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if a subdirectory is modified (e.g. a file gets deleted)');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
|
||||
*/
|
||||
public function testFilterRegexListNoMatch()
|
||||
{
|
||||
$resource = new DirectoryResource($this->directory, '/\.(foo|xml)$/');
|
||||
@ -158,9 +132,6 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($resource->isFresh(time() + 10), '->isFresh() returns true if a new file not matching the filter regex is created');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
|
||||
*/
|
||||
public function testFilterRegexListMatch()
|
||||
{
|
||||
$resource = new DirectoryResource($this->directory, '/\.(foo|xml)$/');
|
||||
@ -168,4 +139,14 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
touch($this->directory.'/new.xml', time() + 20);
|
||||
$this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if an new file matching the filter regex is created ');
|
||||
}
|
||||
|
||||
public function testSerializeUnserialize()
|
||||
{
|
||||
$resource = new DirectoryResource($this->directory, '/\.(foo|xml)$/');
|
||||
|
||||
$unserialized = unserialize(serialize($resource));
|
||||
|
||||
$this->assertSame($this->directory, $resource->getResource());
|
||||
$this->assertSame('/\.(foo|xml)$/', $resource->getPattern());
|
||||
}
|
||||
}
|
||||
|
@ -30,17 +30,16 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
|
||||
unlink($this->file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\FileResource::getResource
|
||||
*/
|
||||
public function testGetResource()
|
||||
{
|
||||
$this->assertEquals(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
|
||||
$this->assertSame(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->assertSame(realpath($this->file), (string) $this->resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\Config\Resource\FileResource::isFresh
|
||||
*/
|
||||
public function testIsFresh()
|
||||
{
|
||||
$this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed');
|
||||
@ -49,4 +48,11 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
|
||||
$resource = new FileResource('/____foo/foobar'.rand(1, 999999));
|
||||
$this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the resource does not exist');
|
||||
}
|
||||
|
||||
public function testSerializeUnserialize()
|
||||
{
|
||||
$unserialized = unserialize(serialize($this->resource));
|
||||
|
||||
$this->assertSame($this->file, $this->resource->getResource());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user