RequestMapperTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Alchemy\Zippy\Tests\Resource;
  3. use Alchemy\Zippy\Tests\TestCase;
  4. use Alchemy\Zippy\Resource\RequestMapper;
  5. class RequestMapperTest extends TestCase
  6. {
  7. /**
  8. * @covers Alchemy\Zippy\Resource\RequestMapper::map
  9. */
  10. public function testMap()
  11. {
  12. $locator = $this->getMockBuilder('Alchemy\Zippy\Resource\TargetLocator')
  13. ->disableOriginalConstructor()
  14. ->getMock();
  15. $locator->expects($this->any())
  16. ->method('locate')
  17. ->will($this->returnValue('computed-location'));
  18. $mapper = new RequestMapper($locator);
  19. $collection = $mapper->map(__DIR__, array(
  20. __DIR__ . '/input/path/to/local/file.ext',
  21. __DIR__ . '/input/path/to/local/file2.ext',
  22. 'here' => __DIR__ . '/input/path/to/local/file3.ext',
  23. ));
  24. $this->assertInstanceOf('Alchemy\Zippy\Resource\ResourceCollection', $collection);
  25. $this->assertCount(3, $collection);
  26. $firstFound = $secondFound = $thirdFound = false;
  27. foreach ($collection as $resource) {
  28. $this->assertInstanceOf('Alchemy\Zippy\Resource\Resource', $resource);
  29. if (__DIR__ . '/input/path/to/local/file.ext' === $resource->getOriginal()) {
  30. $firstFound = true;
  31. $this->assertEquals('computed-location', $resource->getTarget());
  32. } elseif (__DIR__ . '/input/path/to/local/file2.ext' === $resource->getOriginal()) {
  33. $secondFound = true;
  34. $this->assertEquals('computed-location', $resource->getTarget());
  35. } elseif (__DIR__ . '/input/path/to/local/file3.ext' === $resource->getOriginal()) {
  36. $thirdFound = true;
  37. $this->assertEquals('here', $resource->getTarget());
  38. } else {
  39. $this->fail('Unexpected content');
  40. }
  41. }
  42. if (!$firstFound || !$secondFound) {
  43. $this->fail('Unable to find all of the input in the output');
  44. }
  45. }
  46. /**
  47. * @covers Alchemy\Zippy\Resource\RequestMapper::create
  48. */
  49. public function testCreate()
  50. {
  51. $mapper = RequestMapper::create();
  52. $this->assertInstanceOf('Alchemy\Zippy\Resource\RequestMapper', $mapper);
  53. }
  54. }