8000 [Config] additions from ResourceWatcher by everzet · Pull Request #4619 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Config] additions from ResourceWatcher #4619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 20, 2012
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Config] updated DirectoryResource tests
  • Loading branch information
everzet committed Jun 20, 2012
commit 45a45baf2f0cd4eb052640ed394a45385d3b4a8b
27 changes: 12 additions & 15 deletions src/Symfony/Component/Config/Resource/DirectoryResource.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getFilteredChilds()
$childs = array();
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) {
// if regex filtering is enabled only return matching files
if (!$this->isFileMatchesFilters($file)) {
if ($file->isFile() && !$this->isFileMatchesPattern($file)) {
continue;
}

Expand Down Expand Up @@ -71,7 +71,7 @@ public function getFilteredChildResources()
$resources = array();
foreach ($iterator as $file) {
// if regex filtering is enabled only return matching files
if (!$this->isFileMatchesFilters($file)) {
if ($file->isFile() && !$this->isFileMatchesPattern($file)) {
continue;
}

Expand Down Expand Up @@ -109,6 +109,11 @@ public function getResource()
return $this->resource;
}

/**
* Returns check pattern.
*
* @return mixed
*/
public function getPattern()
{
return $this->pattern;
Expand Down Expand Up @@ -145,7 +150,7 @@ public function isFresh($timestamp)
return false;
}

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

/**
Expand All @@ -155,7 +160,7 @@ public function isFresh($timestamp)
*/
public function exists()
{
return file_exists($this->resource);
return is_dir($this->resource);
}

public function serialize()
Expand All @@ -175,18 +180,10 @@ public function unserialize($serialized)
*
* @return Boolean
*/
private function isFileMatchesFilters(\SplFileInfo $file)
private function isFileMatchesPattern(\SplFileInfo $file)
{
if (isset($this->filterRegexList) && $file->isFile()) {
$regexMatched = false;
foreach ($this->filterRegexList as $regex) {
if (preg_match($regex, (string) $file)) {
$regexMatched = true;
}
}
if (!$regexMatched) {
return false;
}
if ($this->pattern) {
return preg_match($this->pattern, $file->getBasename());
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,8 @@ public function testIsFreshDeleteDirectory()
$this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the whole resource is removed');
}

/**
* @covers Symfony\Component\Config\Resource\DirectoryResource::exists
*/
public function testExists()
{
$this->assertTrue($this->resource->exists(), '->exists() returns true if the directory still exist');

$this->removeDirectory($this->directory);
$this->assertFalse($this->resource->exists(), '->exists() returns false if the directory does not exist');
}

/**
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
* @covers Symfony\Component\Config\Resource\DirectoryResource::getModificationTime
*/
public function testIsFreshCreateFileInSubdirectory()
{
Expand Down Expand Up @@ -161,7 +149,6 @@ public function testIsFreshModifySubdirectory()

/**
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
* @covers Symfony\Component\Config\Resource\DirectoryResource::getFilteredChilds
*/
public function testFilterRegexListNoMatch()
{
Expand All @@ -181,4 +168,36 @@ public function testFilterRegexListMatch()
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 ');
}

/**
* @covers Symfony\Component\Config\Resource\DirectoryResource::exists
*/
public function testDirectoryExists()
{
$resource = new DirectoryResource($this->directory);

$this->assertTrue($resource->exists(), '->exists() returns true if directory exists ');

unlink($this->directory.'/tmp.xml');
rmdir($this->directory);

$this->assertFalse($resource->exists(), '->exists() returns false if directory does not exists');
}

/**
* @covers Symfony\Component\Config\Resource\DirectoryResource::getModificationTime
*/
public function testGetModificationTime()
{
$resource = new DirectoryResource($this->directory, '/\.(foo|xml)$/');

touch($this->directory.'/new.xml', $time = time() + 20);
$this->assertSame($time, $resource->getModificationTime(), '->getModificationTime() returns time of the last modificated resource');

touch($this->directory.'/some', time() + 60);
$this->assertSame($time, $resource->getModificationTime(), '->getModificationTime() returns time of last modificated resource, that only matches pattern');

touch($this->directory, $time2 = time() + 90);
$this->assertSame($time2, $resource->getModificationTime(), '->getModificationTime() returns modification time of the directory itself');
}
}
0