HttpDownloaderMock.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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\HttpDownloader;
  13. use Composer\Util\Http\Response;
  14. use Composer\Downloader\TransportException;
  15. class HttpDownloaderMock extends HttpDownloader
  16. {
  17. protected $contentMap;
  18. /**
  19. * @param array $contentMap associative array of locations and content
  20. */
  21. public function __construct(array $contentMap)
  22. {
  23. $this->contentMap = $contentMap;
  24. }
  25. public function get($fileUrl, $options = array())
  26. {
  27. if (!empty($this->contentMap[$fileUrl])) {
  28. return new Response(array('url' => $fileUrl), 200, array(), $this->contentMap[$fileUrl]);
  29. }
  30. throw new TransportException('The "'.$fileUrl.'" file could not be downloaded (NOT FOUND)', 404);
  31. }
  32. }