| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace Test\Michel\FileSystem;
- use Michel\FileSystem\Tools\FileExplorer;
- use Michel\UniTester\TestCase;
- class FileExplorerTest extends TestCase
- {
- protected function setUp(): void
- {
- // TODO: Implement setUp() method.
- }
- protected function tearDown(): void
- {
- // TODO: Implement tearDown() method.
- }
- protected function execute(): void
- {
- $this->testListAll();
- $this->testSearchByPattern();
- $this->testSearchByExtension();
- }
- public function testListAll()
- {
- $explorer = new FileExplorer(__DIR__ . '/resources/syncsource');
- $files = $explorer->listAll(true);
- $this->assertCount(3, $files);
- $foldersCount = 0;
- $filesCount = 0;
- foreach ($files as $file) {
- if ($file['is_directory']) {
- $foldersCount++;
- $this->assertTrue(is_array($file['files']));
- $this->assertCount(2, $file['files']);
- }else{
- $filesCount++;
- }
- $this->assertArrayHasKey('path', $file);
- $this->assertArrayHasKey('name', $file);
- $this->assertArrayHasKey('is_directory', $file);
- $this->assertArrayHasKey('size', $file);
- $this->assertArrayHasKey('modified_time', $file);
- }
- $this->assertEquals(1, $foldersCount);
- $this->assertEquals(2, $filesCount);
- }
- public function testSearchByPattern()
- {
- $explorer = new FileExplorer(__DIR__ . '/resources');
- $files = $explorer->searchByPattern('*.html', true);
- $this->assertCount(2, $files);
- $files = $explorer->searchByPattern('*.txt', true);
- $this->assertCount(4, $files);
- $files = $explorer->searchByPattern('*.txt');
- $this->assertCount(2, $files);
- }
- public function testSearchByExtension()
- {
- $explorer = new FileExplorer(__DIR__ . '/resources');
- $files = $explorer->searchByExtension('html', true);
- $this->assertCount(2, $files);
- }
- }
|