Created
May 29, 2015 10:10
-
-
Save mpdude/a123e0233dba164ef896 to your computer and use it in GitHub Desktop.
Proposal: Test for https://github.com/symfony/symfony/pull/14773
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This file is part of the Symfony package. | |
* | |
* (c) Fabien Potencier <fabien@symfony.com> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace Symfony\Component\Config\Tests\Resource; | |
use Symfony\Component\Config\Resource\FileExistenceResource; | |
class FileExistenceResourceTest extends \PHPUnit_Framework_TestCase | |
{ | |
protected $resource; | |
protected $file; | |
protected $time; | |
protected function setUp() | |
{ | |
$this->file = realpath(sys_get_temp_dir()).'/tmp.xml'; | |
$this->time = time(); | |
$this->resource = new FileExistenceResource($this->file); | |
} | |
protected function tearDown() | |
{ | |
if (file_exists($this->file)) { | |
unlink($this->file); | |
} | |
} | |
public function testToString() | |
{ | |
$this->assertSame($this->file, (string) $this->resource); | |
} | |
public function testGetResource() | |
{ | |
$this->assertSame($this->file, $this->resource->getResource(), '->getResource() returns the path to the resource'); | |
} | |
public function testIsFreshWithExistingResource() | |
{ | |
touch($this->file, $this->time); | |
$serialized = serialize(new FileExistenceResource($this->file)); | |
$resource = unserialize($serialized); | |
$this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource is still present'); | |
unlink($this->file); | |
$resource = unserialize($serialized); | |
$this->assertFalse($this->resource->isFresh($this->time), '->isFresh() returns false if the resource has been deleted'); | |
} | |
public function testIsFreshWithAbsentResource() | |
{ | |
$serialized = serialize(new FileExistenceResource($this->file)); | |
$resource = unserialize($serialized); | |
$this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource is still absent'); | |
touch($this->file, $this->time); | |
$resource = unserialize($serialized); | |
$this->assertFalse($this->resource->isFresh($this->time), '->isFresh() returns false if the resource has been created'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This test closely follows how the resource is supposed to be used in real life.