Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14088678
D18980.id45514.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
D18980.id45514.diff
View Options
diff --git a/src/filesystem/FileFinder.php b/src/filesystem/FileFinder.php
--- a/src/filesystem/FileFinder.php
+++ b/src/filesystem/FileFinder.php
@@ -94,6 +94,10 @@
return $this;
}
+ public function getGenerateChecksums() {
+ return $this->generateChecksums;
+ }
+
/**
* @task config
* @param string Either "php", "shell", or the empty string.
diff --git a/src/filesystem/__tests__/FileFinderTestCase.php b/src/filesystem/__tests__/FileFinderTestCase.php
--- a/src/filesystem/__tests__/FileFinderTestCase.php
+++ b/src/filesystem/__tests__/FileFinderTestCase.php
@@ -2,180 +2,145 @@
final class FileFinderTestCase extends PhutilTestCase {
- protected function getFinder() {
- $finder = new FileFinder(dirname(__FILE__).'/data');
- $finder->excludePath('./exclude')
+ private function newFinder() {
+ return id(new FileFinder(dirname(__FILE__).'/data'))
+ ->excludePath('./exclude')
->excludePath('subdir.txt');
- return $finder;
}
public function testFinderWithChecksums() {
- foreach (array('php', 'shell') as $mode) {
- $files = $this->getFinder()
+ $this->assertFinder(
+ pht('Basic Checksums'),
+ $this->newFinder()
->setGenerateChecksums(true)
->withType('f')
->withPath('*')
- ->withSuffix('txt')
- ->setForceMode($mode)
- ->find();
-
- // Test whether correct files were found.
- $this->assertTrue(array_key_exists('test.txt', $files));
- $this->assertTrue(array_key_exists('file.txt', $files));
- $this->assertTrue(
- array_key_exists(
- 'include_dir.txt/subdir.txt/alsoinclude.txt',
- $files));
- $this->assertFalse(array_key_exists('test', $files));
- $this->assertTrue(array_key_exists('.hidden.txt', $files));
- $this->assertFalse(array_key_exists('exclude/file.txt', $files));
- $this->assertFalse(array_key_exists('include_dir.txt', $files));
-
- foreach ($files as $file => $checksum) {
- $this->assertFalse(is_dir($file));
- }
-
- // Test checksums.
- $this->assertEqual(
- $files['test.txt'],
- 'aea46212fa8b8d0e0e6aa34a15c9e2f5');
- $this->assertEqual(
- $files['file.txt'],
- '725130ba6441eadb4e5d807898e0beae');
- $this->assertEqual(
- $files['.hidden.txt'],
- 'b6cfc9ce9afe12b258ee1c19c235aa27');
- $this->assertEqual(
- $files['include_dir.txt/subdir.txt/alsoinclude.txt'],
- '91e5c1ad76ff229c6456ac92e74e1d9f');
- }
+ ->withSuffix('txt'),
+ array(
+ '.hidden.txt' =>
+ 'b6cfc9ce9afe12b258ee1c19c235aa27',
+ 'file.txt' =>
+ '725130ba6441eadb4e5d807898e0beae',
+ 'include_dir.txt/anotherfile.txt' =>
+ '91e5c1ad76ff229c6456ac92e74e1d9f',
+ 'include_dir.txt/subdir.txt/alsoinclude.txt' =>
+ '91e5c1ad76ff229c6456ac92e74e1d9f',
+ 'test.txt' =>
+ 'aea46212fa8b8d0e0e6aa34a15c9e2f5',
+ ));
}
public function testFinderWithoutChecksums() {
- foreach (array('php', 'shell') as $mode) {
- $files = $this->getFinder()
+ $this->assertFinder(
+ pht('Basic No Checksums'),
+ $this->newFinder()
->withType('f')
->withPath('*')
- ->withSuffix('txt')
- ->setForceMode($mode)
- ->find();
-
- // Test whether correct files were found.
- $this->assertTrue(in_array('test.txt', $files));
- $this->assertTrue(in_array('file.txt', $files));
- $this->assertTrue(in_array('.hidden.txt', $files));
- $this->assertTrue(
- in_array('include_dir.txt/subdir.txt/alsoinclude.txt', $files));
- $this->assertFalse(in_array('test', $files));
- $this->assertFalse(in_array('exclude/file.txt', $files));
- $this->assertFalse(in_array('include_dir.txt', $files));
-
- foreach ($files as $file => $checksum) {
- $this->assertFalse(is_dir($file));
- }
- }
+ ->withSuffix('txt'),
+ array(
+ '.hidden.txt',
+ 'file.txt',
+ 'include_dir.txt/anotherfile.txt',
+ 'include_dir.txt/subdir.txt/alsoinclude.txt',
+ 'test.txt',
+ ));
}
public function testFinderWithFilesAndDirectories() {
- foreach (array('php', 'shell') as $mode) {
- $files = $this->getFinder()
+ $this->assertFinder(
+ pht('With Files And Directories'),
+ $this->newFinder()
->setGenerateChecksums(true)
->withPath('*')
- ->withSuffix('txt')
- ->setForceMode($mode)
- ->find();
-
- // Test whether the correct files were found.
- $this->assertTrue(array_key_exists('test.txt', $files));
- $this->assertTrue(array_key_exists('file.txt', $files));
- $this->assertTrue(
- array_key_exists(
- 'include_dir.txt/subdir.txt/alsoinclude.txt',
- $files));
- $this->assertFalse(array_key_exists('test', $files));
- $this->assertTrue(array_key_exists('.hidden.txt', $files));
- $this->assertFalse(array_key_exists('exclude/file.txt', $files));
- $this->assertTrue(array_key_exists('include_dir.txt', $files));
-
- // Test checksums.
- $this->assertEqual($files['test.txt'],
- 'aea46212fa8b8d0e0e6aa34a15c9e2f5');
- $this->assertEqual($files['include_dir.txt'], null);
- }
+ ->withSuffix('txt'),
+ array(
+ '.hidden.txt' =>
+ 'b6cfc9ce9afe12b258ee1c19c235aa27',
+ 'file.txt' =>
+ '725130ba6441eadb4e5d807898e0beae',
+ 'include_dir.txt' => null,
+ 'include_dir.txt/anotherfile.txt' =>
+ '91e5c1ad76ff229c6456ac92e74e1d9f',
+ 'include_dir.txt/subdir.txt' => null,
+ 'include_dir.txt/subdir.txt/alsoinclude.txt' =>
+ '91e5c1ad76ff229c6456ac92e74e1d9f',
+ 'test.txt' =>
+ 'aea46212fa8b8d0e0e6aa34a15c9e2f5',
+ ));
}
public function testFinderWithDirectories() {
- foreach (array('php', 'shell') as $mode) {
- $directories = $this->getFinder()
- ->withType('d')
- ->setForceMode($mode)
- ->find();
-
- sort($directories);
- $directories = array_values($directories);
-
- $this->assertEqual(
- array(
- 'include_dir.txt',
- 'include_dir.txt/subdir.txt',
- ),
- $directories,
- pht('FileFinder of directories in "%s" mode', $mode));
- }
+ $this->assertFinder(
+ pht('Just Directories'),
+ $this->newFinder()
+ ->withType('d'),
+ array(
+ 'include_dir.txt',
+ 'include_dir.txt/subdir.txt',
+ ));
}
public function testFinderWithPath() {
- foreach (array('php', 'shell') as $mode) {
- $files = $this->getFinder()
+ $this->assertFinder(
+ pht('With Path'),
+ $this->newFinder()
->setGenerateChecksums(true)
->withType('f')
->withPath('*/include_dir.txt/subdir.txt/alsoinclude.txt')
- ->withSuffix('txt')
- ->setForceMode($mode)
- ->find();
-
- // Test whether the correct files were found.
- $this->assertTrue(
- array_key_exists(
- 'include_dir.txt/subdir.txt/alsoinclude.txt',
- $files));
- // Ensure that only the one file was found.
- $this->assertEqual(1, count($files));
- }
+ ->withSuffix('txt'),
+ array(
+ 'include_dir.txt/subdir.txt/alsoinclude.txt' =>
+ '91e5c1ad76ff229c6456ac92e74e1d9f',
+ ));
}
public function testFinderWithNames() {
- foreach (array('php', 'shell') as $mode) {
- $files = $this->getFinder()
+ $this->assertFinder(
+ pht('With Names'),
+ $this->newFinder()
->withType('f')
->withPath('*')
- ->withName('test')
- ->setForceMode($mode)
- ->find();
-
- // Test whether the correct files were found.
- $this->assertTrue(in_array('test', $files));
- $this->assertFalse(in_array('exclude/test', $files));
- $this->assertTrue(in_array('include_dir.txt/test', $files));
- $this->assertTrue(in_array('include_dir.txt/subdir.txt/test', $files));
- $this->assertEqual(3, count($files));
- }
+ ->withName('test'),
+ array(
+ 'include_dir.txt/subdir.txt/test',
+ 'include_dir.txt/test',
+ 'test',
+ ));
}
public function testFinderWithNameAndSuffix() {
- foreach (array('php', 'shell') as $mode) {
- $files = $this->getFinder()
+ $this->assertFinder(
+ pht('With Name and Suffix'),
+ $this->newFinder()
->withType('f')
->withName('alsoinclude.txt')
- ->withSuffix('txt')
+ ->withSuffix('txt'),
+ array(
+ 'include_dir.txt/subdir.txt/alsoinclude.txt',
+ ));
+ }
+
+ private function assertFinder($label, FileFinder $finder, $expect) {
+ $modes = array(
+ 'php',
+ 'shell',
+ );
+ foreach ($modes as $mode) {
+ $actual = id(clone $finder)
->setForceMode($mode)
->find();
+ if ($finder->getGenerateChecksums()) {
+ ksort($actual);
+ } else {
+ sort($actual);
+ }
+
$this->assertEqual(
- array(
- 'include_dir.txt/subdir.txt/alsoinclude.txt',
- ),
- $files);
+ $expect,
+ $actual,
+ pht('Test Case "%s" in Mode "%s"', $label, $mode));
}
}
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 5:35 AM (20 h, 47 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6785044
Default Alt Text
D18980.id45514.diff (9 KB)
Attached To
Mode
D18980: Rewrite FileFinder tests to actually show why they break
Attached
Detach File
Event Timeline
Log In to Comment