2
0

FileExplorerTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Test\Michel\FileSystem;
  3. use Michel\FileSystem\Tools\FileExplorer;
  4. use Michel\UniTester\TestCase;
  5. class FileExplorerTest extends TestCase
  6. {
  7. protected function setUp(): void
  8. {
  9. // TODO: Implement setUp() method.
  10. }
  11. protected function tearDown(): void
  12. {
  13. // TODO: Implement tearDown() method.
  14. }
  15. protected function execute(): void
  16. {
  17. $this->testListAll();
  18. $this->testSearchByPattern();
  19. $this->testSearchByExtension();
  20. }
  21. public function testListAll()
  22. {
  23. $explorer = new FileExplorer(__DIR__ . '/resources/syncsource');
  24. $files = $explorer->listAll(true);
  25. $this->assertCount(3, $files);
  26. $foldersCount = 0;
  27. $filesCount = 0;
  28. foreach ($files as $file) {
  29. if ($file['is_directory']) {
  30. $foldersCount++;
  31. $this->assertTrue(is_array($file['files']));
  32. $this->assertCount(2, $file['files']);
  33. }else{
  34. $filesCount++;
  35. }
  36. $this->assertArrayHasKey('path', $file);
  37. $this->assertArrayHasKey('name', $file);
  38. $this->assertArrayHasKey('is_directory', $file);
  39. $this->assertArrayHasKey('size', $file);
  40. $this->assertArrayHasKey('modified_time', $file);
  41. }
  42. $this->assertEquals(1, $foldersCount);
  43. $this->assertEquals(2, $filesCount);
  44. }
  45. public function testSearchByPattern()
  46. {
  47. $explorer = new FileExplorer(__DIR__ . '/resources');
  48. $files = $explorer->searchByPattern('*.html', true);
  49. $this->assertCount(2, $files);
  50. $files = $explorer->searchByPattern('*.txt', true);
  51. $this->assertCount(4, $files);
  52. $files = $explorer->searchByPattern('*.txt');
  53. $this->assertCount(2, $files);
  54. }
  55. public function testSearchByExtension()
  56. {
  57. $explorer = new FileExplorer(__DIR__ . '/resources');
  58. $files = $explorer->searchByExtension('html', true);
  59. $this->assertCount(2, $files);
  60. }
  61. }