RemoteFilesystemMock.php 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Mock;
  12. use Composer\Util\RemoteFilesystem;
  13. use Composer\Downloader\TransportException;
  14. /**
  15. * Remote filesystem mock
  16. */
  17. class RemoteFilesystemMock extends RemoteFilesystem
  18. {
  19. protected $contentMap;
  20. /**
  21. * @param array $contentMap associative array of locations and content
  22. */
  23. public function __construct(array $contentMap)
  24. {
  25. $this->contentMap = $contentMap;
  26. }
  27. public function getContents($originUrl, $fileUrl, $progress = true, $options = array())
  28. {
  29. if (!empty($this->contentMap[$fileUrl])) {
  30. return $this->contentMap[$fileUrl];
  31. }
  32. throw new TransportException('The "'.$fileUrl.'" file could not be downloaded (NOT FOUND)', 404);
  33. }
  34. }