Filesystem.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\TestFramework\App;
  7. class Filesystem extends \Magento\Framework\Filesystem
  8. {
  9. /**
  10. * Overridden paths
  11. *
  12. * @var string[]
  13. */
  14. private $paths = [];
  15. /**
  16. * {@inheritdoc}
  17. */
  18. protected function getDirPath($code)
  19. {
  20. return $this->getOverriddenPath($code, parent::getDirPath($code));
  21. }
  22. /**
  23. * Overrides a path to directory for testing purposes
  24. *
  25. * @param string $code
  26. * @param string $value
  27. * @return void
  28. */
  29. public function overridePath($code, $value)
  30. {
  31. $this->paths[$code] = str_replace('\\', '/', $value);
  32. unset($this->readInstances[$code]);
  33. unset($this->writeInstances[$code]);
  34. }
  35. /**
  36. * Looks up an overridden directory path
  37. *
  38. * @param string $code
  39. * @param string $original
  40. * @return string
  41. */
  42. private function getOverriddenPath($code, $original)
  43. {
  44. if (array_key_exists($code, $this->paths)) {
  45. return $this->paths[$code];
  46. }
  47. return $original;
  48. }
  49. }