Skip to content

Commit

Permalink
Fixes #62 - Test for file manager to ignore files
Browse files Browse the repository at this point in the history
  • Loading branch information
bmitch committed Aug 24, 2017
1 parent 5cf8720 commit 181c574
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Managers/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Churn\Values\File;
use SplFileInfo;

class FileManager
{
Expand Down Expand Up @@ -34,13 +35,31 @@ public function getPhpFiles(string $path): FileCollection
continue;
}

if (in_array($file->getPathname(), $this->config->getFilesToIgnore())) {
if ($this->fileShouldBeIgnored($file)) {
continue;
}


$files->push(new File(['displayPath' => $file->getPathName(), 'fullPath' => $file->getRealPath()]));
}

return $files;
}

/**
* Determines if a file should be ignored.
* @param \SplFileInfo $file File.
* @return boolean
*/
private function fileShouldBeIgnored(SplFileInfo $file): bool
{
foreach ($this->config->getFilesToIgnore() as $fileToIgnore) {
$fileToIgnore = str_replace('/', '\/', $fileToIgnore);
if (preg_match("/{$fileToIgnore}/", $file->getPathName())) {
return true;
}
}

return false;
}
}
7 changes: 7 additions & 0 deletions tests/Unit/Managers/FileManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public function it_can_get_the_php_files_in_a_filter()
$this->assertCount(3, $this->fileManager->getPhpFiles(__DIR__ . '/../Assets'));
}

/** @test **/
public function it_ignores_files_specified_to_ignore_in_the_config()
{
$fileManager = new FileManager(new Config(['filesToIgnore' => ['Assets/Baz.php']]));
$this->assertCount(2, $fileManager->getPhpFiles(__DIR__ . '/../Assets'));
}

public function setup()
{
$this->fileManager = new FileManager(new Config);
Expand Down

0 comments on commit 181c574

Please sign in to comment.