Changeset View
Changeset View
Standalone View
Standalone View
src/filesystem/__tests__/FileFinderTestCase.php
| <?php | <?php | ||||
| final class FileFinderTestCase extends PhutilTestCase { | final class FileFinderTestCase extends PhutilTestCase { | ||||
| protected function getFinder() { | protected function getFinder() { | ||||
| $finder = new FileFinder(dirname(__FILE__).'/data'); | $finder = new FileFinder(dirname(__FILE__).'/data'); | ||||
| $finder->excludePath('./exclude') | $finder->excludePath('./exclude') | ||||
| ->excludePath('subdir.txt'); | ->excludePath('subdir.txt'); | ||||
| return $finder; | return $finder; | ||||
| } | } | ||||
| protected function getModes() { | |||||
| return phutil_is_windows()? array('php') : array('php', 'shell'); | |||||
| } | |||||
| public function testFinderWithChecksums() { | public function testFinderWithChecksums() { | ||||
| foreach (array('php', 'shell') as $mode) { | foreach ($this->getModes() as $mode) { | ||||
| $files = $this->getFinder() | $files = $this->getFinder() | ||||
| ->setGenerateChecksums(true) | ->setGenerateChecksums(true) | ||||
| ->withType('f') | ->withType('f') | ||||
| ->withPath('*') | ->withPath('*') | ||||
| ->withSuffix('txt') | ->withSuffix('txt') | ||||
| ->setForceMode($mode) | ->setForceMode($mode) | ||||
| ->find(); | ->find(); | ||||
| Show All 25 Lines | foreach ($this->getModes() as $mode) { | ||||
| 'b6cfc9ce9afe12b258ee1c19c235aa27'); | 'b6cfc9ce9afe12b258ee1c19c235aa27'); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| $files['include_dir.txt/subdir.txt/alsoinclude.txt'], | $files['include_dir.txt/subdir.txt/alsoinclude.txt'], | ||||
| '91e5c1ad76ff229c6456ac92e74e1d9f'); | '91e5c1ad76ff229c6456ac92e74e1d9f'); | ||||
| } | } | ||||
| } | } | ||||
| public function testFinderWithoutChecksums() { | public function testFinderWithoutChecksums() { | ||||
| foreach (array('php', 'shell') as $mode) { | foreach ($this->getModes() as $mode) { | ||||
| $files = $this->getFinder() | $files = $this->getFinder() | ||||
| ->withType('f') | ->withType('f') | ||||
| ->withPath('*') | ->withPath('*') | ||||
| ->withSuffix('txt') | ->withSuffix('txt') | ||||
| ->setForceMode($mode) | ->setForceMode($mode) | ||||
| ->find(); | ->find(); | ||||
| // Test whether correct files were found. | // Test whether correct files were found. | ||||
| $this->assertTrue(in_array('test.txt', $files)); | $this->assertTrue(in_array('test.txt', $files)); | ||||
| $this->assertTrue(in_array('file.txt', $files)); | $this->assertTrue(in_array('file.txt', $files)); | ||||
| $this->assertTrue(in_array('.hidden.txt', $files)); | $this->assertTrue(in_array('.hidden.txt', $files)); | ||||
| $this->assertTrue( | $this->assertTrue( | ||||
| in_array('include_dir.txt/subdir.txt/alsoinclude.txt', $files)); | in_array('include_dir.txt/subdir.txt/alsoinclude.txt', $files)); | ||||
| $this->assertFalse(in_array('test', $files)); | $this->assertFalse(in_array('test', $files)); | ||||
| $this->assertFalse(in_array('exclude/file.txt', $files)); | $this->assertFalse(in_array('exclude/file.txt', $files)); | ||||
| $this->assertFalse(in_array('include_dir.txt', $files)); | $this->assertFalse(in_array('include_dir.txt', $files)); | ||||
| foreach ($files as $file => $checksum) { | foreach ($files as $file => $checksum) { | ||||
| $this->assertFalse(is_dir($file)); | $this->assertFalse(is_dir($file)); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| public function testFinderWithDirectories() { | public function testFinderWithDirectories() { | ||||
| foreach (array('php', 'shell') as $mode) { | foreach ($this->getModes() as $mode) { | ||||
| $files = $this->getFinder() | $files = $this->getFinder() | ||||
| ->setGenerateChecksums(true) | ->setGenerateChecksums(true) | ||||
| ->withPath('*') | ->withPath('*') | ||||
| ->withSuffix('txt') | ->withSuffix('txt') | ||||
| ->setForceMode($mode) | ->setForceMode($mode) | ||||
| ->find(); | ->find(); | ||||
| // Test whether the correct files were found. | // Test whether the correct files were found. | ||||
| Show All 11 Lines | foreach ($this->getModes() as $mode) { | ||||
| // Test checksums. | // Test checksums. | ||||
| $this->assertEqual($files['test.txt'], | $this->assertEqual($files['test.txt'], | ||||
| 'aea46212fa8b8d0e0e6aa34a15c9e2f5'); | 'aea46212fa8b8d0e0e6aa34a15c9e2f5'); | ||||
| $this->assertEqual($files['include_dir.txt'], null); | $this->assertEqual($files['include_dir.txt'], null); | ||||
| } | } | ||||
| } | } | ||||
| public function testFinderWithPath() { | public function testFinderWithPath() { | ||||
| foreach (array('php', 'shell') as $mode) { | foreach ($this->getModes() as $mode) { | ||||
| $files = $this->getFinder() | $files = $this->getFinder() | ||||
| ->setGenerateChecksums(true) | ->setGenerateChecksums(true) | ||||
| ->withType('f') | ->withType('f') | ||||
| ->withPath('*/include_dir.txt/subdir.txt/alsoinclude.txt') | ->withPath('*/include_dir.txt/subdir.txt/alsoinclude.txt') | ||||
| ->withSuffix('txt') | ->withSuffix('txt') | ||||
| ->setForceMode($mode) | ->setForceMode($mode) | ||||
| ->find(); | ->find(); | ||||
| // Test whether the correct files were found. | // Test whether the correct files were found. | ||||
| $this->assertTrue( | $this->assertTrue( | ||||
| array_key_exists( | array_key_exists( | ||||
| 'include_dir.txt/subdir.txt/alsoinclude.txt', | 'include_dir.txt/subdir.txt/alsoinclude.txt', | ||||
| $files)); | $files)); | ||||
| // Ensure that only the one file was found. | // Ensure that only the one file was found. | ||||
| $this->assertEqual(1, count($files)); | $this->assertEqual(1, count($files)); | ||||
| } | } | ||||
| } | } | ||||
| public function testFinderWithNames() { | public function testFinderWithNames() { | ||||
| foreach (array('php', 'shell') as $mode) { | foreach ($this->getModes() as $mode) { | ||||
| $files = $this->getFinder() | $files = $this->getFinder() | ||||
| ->withType('f') | ->withType('f') | ||||
| ->withPath('*') | ->withPath('*') | ||||
| ->withName('test') | ->withName('test') | ||||
| ->setForceMode($mode) | ->setForceMode($mode) | ||||
| ->find(); | ->find(); | ||||
| // Test whether the correct files were found. | // Test whether the correct files were found. | ||||
| Show All 9 Lines | |||||