/**
  * @dataProvider dataGetMetadataFromIndexWorks
  * @param array $files
  * @param string $directory
  * @param bool $recursive
  * @param array $expected
  */
 public function testGetMetadataFromIndexWorks($files, $directory, $recursive, $expected)
 {
     foreach ($files as $file) {
         $this->fileSystem->write($file, null);
     }
     $this->assertArrayEquals($expected, array_map(function ($v) {
         return $v["path"];
     }, $this->fileSystem->listContents($directory, $recursive)));
 }
 /**
  * @dataProvider performanceIsNotIntrusiveDataProvider
  * @param FileSystem $fileSystem
  * @param int $from
  * @param int $to
  */
 public function testPerformanceIsNotIntrusive(FileSystem $fileSystem, $from, $to)
 {
     $profilerWasEnabled = SimpleProfiler::start();
     if (!$profilerWasEnabled) {
         SimpleProfiler::enable();
     }
     #region Build storage
     for ($i = $from; $i < $to; $i++) {
         $file = "/file_{$i}.tmp";
         #region Create file
         SimpleProfiler::start();
         $fileSystem->write($file, null);
         $profile = SimpleProfiler::finish();
         $this->assertLessThanOrEqual(5, $profile->absoluteDuration);
         #endregion
         #region Write content
         SimpleProfiler::start();
         $fileSystem->update($file, sha1($i, true));
         $fileSystem->update($file, md5($i, true), ["append" => true]);
         $profile = SimpleProfiler::finish();
         $this->assertLessThanOrEqual(10, $profile->absoluteDuration);
         #endregion
         #region Read content
         SimpleProfiler::start();
         $fileSystem->read($file);
         $profile = SimpleProfiler::finish();
         $this->assertLessThanOrEqual(5, $profile->absoluteDuration);
         #endregion
     }
     #endregion
     #region Iterate all files
     SimpleProfiler::start();
     /** @noinspection PhpUnusedLocalVariableInspection */
     foreach ($fileSystem->listContents() as $unused) {
     }
     $profile = SimpleProfiler::finish();
     $this->assertLessThanOrEqual(5 * $to, $profile->absoluteDuration);
     #endregion
     if (!$profilerWasEnabled) {
         SimpleProfiler::disable();
     }
     SimpleProfiler::finish();
 }
 /**
  * Lists contents backward (storage lookup first)
  *
  * @param string $directory
  * @param bool $recursive
  * @return \Generator
  */
 private function getMetadataFromIndexBackward($directory, $recursive)
 {
     Expect::that($directory)->equals("/");
     Expect::that($recursive)->equals(true);
     $index = ["targetDirname" => null, "content" => null];
     foreach ($this->getInnerFileSystem()->listContents("/", false) as $directory) {
         if ("/{$directory["path"]}" == self::PATH_TO_INDEXES) {
             continue;
         }
         foreach ($this->getInnerFileSystem()->listContents("/{$directory["path"]}", true) as $content) {
             if (strlen($content["basename"]) == 2) {
                 continue;
             }
             if ($index["targetDirname"] != $content["dirname"]) {
                 $index["targetDirname"] = $content["dirname"];
                 $index["content"] = $this->readIndex(self::PATH_TO_INDEXES . "/{$content["dirname"]}/" . self::INDEX_FILE);
             }
             foreach ($index["content"][self::INDEX_FILE__DATA] as $knownPath => $unused) {
                 if ("/{$content["path"]}" == FileSystem::getInnerPath($knownPath)) {
                     (yield $this->getOuterFileSystem()->getMetadata($knownPath));
                     break;
                 }
             }
         }
     }
 }
 /**
  * @dataProvider getInnerPathWorksDataProvider
  * @param string $expectedInnerPath
  * @param string $path
  */
 public function testGetInnerPathWorks($expectedInnerPath, $path)
 {
     $this->assertEquals($expectedInnerPath, FileSystem::getInnerPath($path));
 }