ResourceCollectionTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Alchemy\Zippy\Tests\Resource;
  3. use Alchemy\Zippy\Tests\TestCase;
  4. use Alchemy\Zippy\Resource\ResourceCollection;
  5. class ResourceCollectionTest extends TestCase
  6. {
  7. /**
  8. * @covers Alchemy\Zippy\Resource\ResourceCollection::__construct
  9. */
  10. public function testConstructWithoutElements()
  11. {
  12. $collection = new ResourceCollection('supa-context');
  13. $this->assertEquals('supa-context', $collection->getContext());
  14. $this->assertEquals(array(), $collection->toArray());
  15. }
  16. /**
  17. * @covers Alchemy\Zippy\Resource\ResourceCollection::__construct
  18. */
  19. public function testConstructWithElements()
  20. {
  21. $data = array('one', 'two' => 'three');
  22. $collection = new ResourceCollection('supa-context', $data);
  23. $this->assertEquals('supa-context', $collection->getContext());
  24. $this->assertEquals($data, $collection->toArray());
  25. }
  26. /**
  27. * @covers Alchemy\Zippy\Resource\ResourceCollection::getContext
  28. * @covers Alchemy\Zippy\Resource\ResourceCollection::setContext
  29. */
  30. public function testGetSetContext()
  31. {
  32. $collection = new ResourceCollection('supa-context');
  33. $this->assertEquals('supa-context', $collection->getContext());
  34. $collection->setContext('cool context');
  35. $this->assertEquals('cool context', $collection->getContext());
  36. }
  37. /**
  38. * @covers Alchemy\Zippy\Resource\ResourceCollection::isTemporary
  39. * @covers Alchemy\Zippy\Resource\ResourceCollection::setTemporary
  40. */
  41. public function testSetIsTemporary()
  42. {
  43. $collection = new ResourceCollection('supa-context');
  44. $this->assertFalse($collection->isTemporary());
  45. $collection->setTemporary(true);
  46. $this->assertTrue($collection->isTemporary());
  47. $collection->setTemporary(false);
  48. $this->assertFalse($collection->isTemporary());
  49. }
  50. /**
  51. * @covers Alchemy\Zippy\Resource\ResourceCollection::canBeProcessedInPlace
  52. * @dataProvider provideVariousInPlaceResources
  53. */
  54. public function testCanBeProcessedInPlace($expected, $first, $second, $third)
  55. {
  56. $collection = new ResourceCollection('supa-context', array(
  57. $this->getInPlaceResource($first),
  58. $this->getInPlaceResource($second),
  59. $this->getInPlaceResource($third),
  60. ));
  61. $this->assertInternalType('boolean', $collection->canBeProcessedInPlace());
  62. $this->assertEquals($expected, $collection->canBeProcessedInPlace());
  63. }
  64. public function provideVariousInPlaceResources()
  65. {
  66. return array(
  67. array(true, true, true, true),
  68. array(false, true, true, false),
  69. array(false, false, false, false),
  70. array(false, false, false, true),
  71. );
  72. }
  73. private function getInPlaceResource($processInPlace)
  74. {
  75. $resource = $this->getMockBuilder('Alchemy\Zippy\Resource\Resource')
  76. ->disableOriginalConstructor()
  77. ->getMock();
  78. $resource->expects($this->any())
  79. ->method('canBeProcessedInPlace')
  80. ->will($this->returnValue($processInPlace));
  81. return $resource;
  82. }
  83. }