|
6 | 6 | use InvalidArgumentException; |
7 | 7 | use org\bovigo\vfs\vfsStream; |
8 | 8 |
|
| 9 | +use org\bovigo\vfs\vfsStreamDirectory; |
| 10 | +use org\bovigo\vfs\visitor\vfsStreamStructureVisitor; |
| 11 | + |
9 | 12 | class FilesystemHelperTest extends CIUnitTestCase |
10 | 13 | { |
11 | 14 |
|
@@ -104,6 +107,58 @@ public function testDirectoryMapHandlesNotfound() |
104 | 107 |
|
105 | 108 | //-------------------------------------------------------------------- |
106 | 109 |
|
| 110 | + public function testDirectoryMirror() |
| 111 | + { |
| 112 | + $this->assertTrue(function_exists('directory_mirror')); |
| 113 | + |
| 114 | + // Create a subdirectory |
| 115 | + $this->structure['foo']['bam'] = ['zab' => 'A deep file']; |
| 116 | + |
| 117 | + $vfs = vfsStream::setup('root', null, $this->structure); |
| 118 | + $root = rtrim(vfsStream::url('root') . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
| 119 | + |
| 120 | + directory_mirror($root . 'foo', $root . 'boo'); |
| 121 | + |
| 122 | + $this->assertFileExists($root . 'boo/bar'); |
| 123 | + $this->assertFileExists($root . 'boo/bam/zab'); |
| 124 | + } |
| 125 | + |
| 126 | + public function testDirectoryMirrorOverwrites() |
| 127 | + { |
| 128 | + $this->assertTrue(function_exists('directory_mirror')); |
| 129 | + |
| 130 | + // Create duplicate files |
| 131 | + $this->structure['foo']['far'] = 'all your base'; |
| 132 | + $this->structure['foo']['faz'] = 'are belong to us'; |
| 133 | + |
| 134 | + $vfs = vfsStream::setup('root', null, $this->structure); |
| 135 | + $root = rtrim(vfsStream::url('root') . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
| 136 | + |
| 137 | + directory_mirror($root . 'foo', $root . 'boo', true); |
| 138 | + $result = file_get_contents($root . 'boo/faz'); |
| 139 | + |
| 140 | + $this->assertEquals($this->structure['foo']['faz'], $result); |
| 141 | + } |
| 142 | + |
| 143 | + public function testDirectoryMirrorNotOverwrites() |
| 144 | + { |
| 145 | + $this->assertTrue(function_exists('directory_mirror')); |
| 146 | + |
| 147 | + // Create duplicate files |
| 148 | + $this->structure['foo']['far'] = 'all your base'; |
| 149 | + $this->structure['foo']['faz'] = 'are belong to us'; |
| 150 | + |
| 151 | + $vfs = vfsStream::setup('root', null, $this->structure); |
| 152 | + $root = rtrim(vfsStream::url('root') . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
| 153 | + |
| 154 | + directory_mirror($root . 'foo', $root . 'boo', false); |
| 155 | + $result = file_get_contents($root . 'boo/faz'); |
| 156 | + |
| 157 | + $this->assertEquals($this->structure['boo']['faz'], $result); |
| 158 | + } |
| 159 | + |
| 160 | + //-------------------------------------------------------------------- |
| 161 | + |
107 | 162 | public function testWriteFileSuccess() |
108 | 163 | { |
109 | 164 | $vfs = vfsStream::setup('root'); |
@@ -379,6 +434,49 @@ public function testGetFileNotThereInfo() |
379 | 434 | } |
380 | 435 |
|
381 | 436 | //-------------------------------------------------------------------- |
| 437 | + |
| 438 | + public function testSameFileSame() |
| 439 | + { |
| 440 | + $file1 = SUPPORTPATH . 'Files/able/apple.php'; |
| 441 | + $file2 = SUPPORTPATH . 'Files/able/apple.php'; |
| 442 | + |
| 443 | + $this->assertTrue(same_file($file1, $file2)); |
| 444 | + } |
| 445 | + |
| 446 | + public function testSameFileIdentical() |
| 447 | + { |
| 448 | + $file1 = SUPPORTPATH . 'Files/able/apple.php'; |
| 449 | + $file2 = SUPPORTPATH . 'Files/baker/banana.php'; |
| 450 | + |
| 451 | + $this->assertTrue(same_file($file1, $file2)); |
| 452 | + } |
| 453 | + |
| 454 | + public function testSameFileDifferent() |
| 455 | + { |
| 456 | + $file1 = SUPPORTPATH . 'Files/able/apple.php'; |
| 457 | + $file2 = SUPPORTPATH . 'Images/ci-logo.gif'; |
| 458 | + |
| 459 | + $this->assertFalse(same_file($file1, $file2)); |
| 460 | + } |
| 461 | + |
| 462 | + public function testSameFileOrder() |
| 463 | + { |
| 464 | + $file1 = SUPPORTPATH . 'Files/able/apple.php'; |
| 465 | + $file2 = SUPPORTPATH . 'Images/ci-logo.gif'; |
| 466 | + |
| 467 | + $this->assertFalse(same_file($file2, $file1)); |
| 468 | + } |
| 469 | + |
| 470 | + public function testSameFileDirectory() |
| 471 | + { |
| 472 | + $file1 = SUPPORTPATH . 'Files/able/apple.php'; |
| 473 | + $file2 = SUPPORTPATH . 'Images/'; |
| 474 | + |
| 475 | + $this->assertFalse(same_file($file1, $file2)); |
| 476 | + } |
| 477 | + |
| 478 | + //-------------------------------------------------------------------- |
| 479 | + |
382 | 480 | public function testOctalPermissions() |
383 | 481 | { |
384 | 482 | $this->assertEquals('777', octal_permissions(0777)); |
|
0 commit comments