-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MineAdmin. | ||
* | ||
* @link https://www.mineadmin.com | ||
* @document https://doc.mineadmin.com | ||
* @contact root@imoi.cn | ||
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
*/ | ||
use Mine\Support\Filesystem; | ||
use Nette\Utils\FileSystem as BaseFileSystem; | ||
|
||
describe('copy', function () { | ||
beforeEach(function () { | ||
$this->sourceDir = sys_get_temp_dir() . '/source_' . uniqid(); | ||
Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.0.3
Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.1.2
Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.1.2
Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-master
Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-master
Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.0.3
Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-master
Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-v5.1.2
|
||
$this->targetDir = sys_get_temp_dir() . '/target_' . uniqid(); | ||
Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.0.3
Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.1.2
Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.1.2
Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-master
Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-master
Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.0.3
Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-master
Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-v5.1.2
|
||
|
||
BaseFileSystem::createDir($this->sourceDir); | ||
Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.0.3
Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.1.2
Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.1.2
Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-master
Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-master
Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.0.3
Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-master
Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-v5.1.2
|
||
BaseFileSystem::createDir($this->targetDir); | ||
Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.0.3
Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.1.2
Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.1.2
Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-master
Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-master
Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.0.3
Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-master
Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-v5.1.2
|
||
}); | ||
|
||
afterEach(function () { | ||
BaseFileSystem::delete($this->sourceDir); | ||
Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.0.3
Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.1.2
Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.1.2
Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-master
Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-master
Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.0.3
Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-master
Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-v5.1.2
|
||
BaseFileSystem::delete($this->targetDir); | ||
Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.0.3
Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.1.2
Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.1.2
Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-master
Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-master
Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.0.3
Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-master
Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-v5.1.2
|
||
}); | ||
|
||
it('can copy nested directories while preserving existing files', function () { | ||
BaseFileSystem::createDir($this->sourceDir . '/subDir'); | ||
Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.0.3
Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.1.2
Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.1.2
Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-master
Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-master
Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.0.3
Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-master
Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-v5.1.2
|
||
file_put_contents($this->sourceDir . '/file1.txt', 'content1'); | ||
Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.0.3
Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.1.2
Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.1.2
Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-master
Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-master
Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.0.3
Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-master
Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-v5.1.2
|
||
file_put_contents($this->sourceDir . '/subDir/file2.txt', 'content2'); | ||
Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.0.3
Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.1.2
Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.1.2
Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-master
Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-master
Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.0.3
Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-master
Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-v5.1.2
|
||
|
||
BaseFileSystem::createDir($this->targetDir . '/subDir'); | ||
Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.0.3
Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-v5.1.2
Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.1.2
Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.2 Swoole-master
Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-master
Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-v5.0.3
Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.1 Swoole-master
Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php GitHub Actions / Test on PHP8.3 Swoole-v5.1.2
|
||
file_put_contents($this->targetDir . '/subDir/existing.txt', 'existing content'); | ||
|
||
Filesystem::copy($this->sourceDir, $this->targetDir); | ||
|
||
expect($this->targetDir . '/subDir')->toBeDirectory() | ||
->and($this->targetDir . '/file1.txt')->toBeFile() | ||
->and($this->targetDir . '/subDir/file2.txt')->toBeFile() | ||
->and($this->targetDir . '/subDir/existing.txt')->toBeFile() | ||
->and(file_get_contents($this->targetDir . '/file1.txt'))->toBe('content1') | ||
->and(file_get_contents($this->targetDir . '/subDir/file2.txt'))->toBe('content2') | ||
->and(file_get_contents($this->targetDir . '/subDir/existing.txt'))->toBe('existing content') | ||
->and($this->sourceDir)->not->toBeDirectory(); | ||
}); | ||
|
||
it('can copy without deleting source directory', function () { | ||
file_put_contents($this->sourceDir . '/test.txt', 'test content'); | ||
|
||
Filesystem::copy($this->sourceDir, $this->targetDir, false); | ||
|
||
expect($this->sourceDir)->toBeDirectory() | ||
->and($this->sourceDir . '/test.txt')->toBeFile() | ||
->and($this->targetDir . '/test.txt')->toBeFile() | ||
->and(file_get_contents($this->targetDir . '/test.txt'))->toBe('test content'); | ||
}); | ||
}); |