Skip to content

Commit

Permalink
test(src): add unit tests for Filesystem::copy method.
Browse files Browse the repository at this point in the history
  • Loading branch information
FaiZell committed Dec 9, 2024
1 parent e802a02 commit de810cf
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/Support/tests/Unit/FilesystemTest.php
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

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-master

Undefined variable: $this

Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-master

Undefined variable: $this

Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-master

Undefined variable: $this

Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 17 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / build Code coverage report (ubuntu-latest, 8.1, v5.1.2)

Undefined variable: $this
$this->targetDir = sys_get_temp_dir() . '/target_' . uniqid();

Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-master

Undefined variable: $this

Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-master

Undefined variable: $this

Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-master

Undefined variable: $this

Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 18 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / build Code coverage report (ubuntu-latest, 8.1, v5.1.2)

Undefined variable: $this

BaseFileSystem::createDir($this->sourceDir);

Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-master

Undefined variable: $this

Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-master

Undefined variable: $this

Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-master

Undefined variable: $this

Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 20 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / build Code coverage report (ubuntu-latest, 8.1, v5.1.2)

Undefined variable: $this
BaseFileSystem::createDir($this->targetDir);

Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-master

Undefined variable: $this

Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-master

Undefined variable: $this

Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-master

Undefined variable: $this

Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 21 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / build Code coverage report (ubuntu-latest, 8.1, v5.1.2)

Undefined variable: $this
});

afterEach(function () {
BaseFileSystem::delete($this->sourceDir);

Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-master

Undefined variable: $this

Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-master

Undefined variable: $this

Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-master

Undefined variable: $this

Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 25 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / build Code coverage report (ubuntu-latest, 8.1, v5.1.2)

Undefined variable: $this
BaseFileSystem::delete($this->targetDir);

Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-master

Undefined variable: $this

Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-master

Undefined variable: $this

Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-master

Undefined variable: $this

Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 26 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / build Code coverage report (ubuntu-latest, 8.1, v5.1.2)

Undefined variable: $this
});

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

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-master

Undefined variable: $this

Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-master

Undefined variable: $this

Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-master

Undefined variable: $this

Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 30 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / build Code coverage report (ubuntu-latest, 8.1, v5.1.2)

Undefined variable: $this
file_put_contents($this->sourceDir . '/file1.txt', 'content1');

Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-master

Undefined variable: $this

Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-master

Undefined variable: $this

Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-master

Undefined variable: $this

Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 31 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / build Code coverage report (ubuntu-latest, 8.1, v5.1.2)

Undefined variable: $this
file_put_contents($this->sourceDir . '/subDir/file2.txt', 'content2');

Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-master

Undefined variable: $this

Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-master

Undefined variable: $this

Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-master

Undefined variable: $this

Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 32 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / build Code coverage report (ubuntu-latest, 8.1, v5.1.2)

Undefined variable: $this

BaseFileSystem::createDir($this->targetDir . '/subDir');

Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.2 Swoole-master

Undefined variable: $this

Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-master

Undefined variable: $this

Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-v5.0.3

Undefined variable: $this

Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.1 Swoole-master

Undefined variable: $this

Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / Test on PHP8.3 Swoole-v5.1.2

Undefined variable: $this

Check failure on line 34 in src/Support/tests/Unit/FilesystemTest.php

View workflow job for this annotation

GitHub Actions / build Code coverage report (ubuntu-latest, 8.1, v5.1.2)

Undefined variable: $this
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');
});
});

0 comments on commit de810cf

Please sign in to comment.