LazyRackspaceCloudfilesSpec.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace spec\Gaufrette\Adapter;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. class LazyRackspaceCloudfilesSpec extends ObjectBehavior
  6. {
  7. /**
  8. * @param \Gaufrette\Adapter\RackspaceCloudfiles\ConnectionFactoryInterface $connectionFactory
  9. * @param \CF_Connection $connection
  10. */
  11. function let($connectionFactory, $connection)
  12. {
  13. $connectionFactory->create()->willReturn($connection);
  14. $this->beConstructedWith($connectionFactory, 'my_container');
  15. }
  16. function it_is_rackspace_adapter()
  17. {
  18. $this->shouldHaveType('\Gaufrette\Adapter\RackspaceCloudfiles');
  19. }
  20. /**
  21. * @param \CF_Container $container
  22. * @param \CF_Object $object
  23. */
  24. function it_lazily_fetches_container_before_read($connection, $container, $object)
  25. {
  26. $connection->get_container('my_container')->willReturn($container)->shouldBeCalledTimes(1);
  27. $connection->create_container(Argument::cetera())->shouldNotBeCalled();
  28. $object->read()->willReturn('some content');
  29. $container->get_object('filename')->willReturn($object);
  30. $container->get_object('filename1')->willReturn($object);
  31. $this->read('filename')->shouldReturn('some content');
  32. //get_container() should not be called second time
  33. $this->read('filename1')->shouldReturn('some content');
  34. }
  35. /**
  36. * @param \CF_Container $container
  37. * @param \CF_Object $object
  38. */
  39. function it_lazily_creates_container_before_read($connectionFactory, $connection, $container, $object)
  40. {
  41. $this->beConstructedWith($connectionFactory, 'my_container', true);
  42. $connection->get_container(Argument::any())->shouldNotBeCalled();
  43. $connection->create_container('my_container')->willReturn($container)->shouldBeCalled();
  44. $object->read()->willReturn('some content');
  45. $container->get_object('filename')->willReturn($object);
  46. $this->read('filename')->shouldReturn('some content');
  47. }
  48. /**
  49. * @param \CF_Container $container
  50. * @param \CF_Object $object
  51. */
  52. function it_lazily_fetches_container_before_write($connection, $container, $object)
  53. {
  54. $connection->get_container('my_container')->willReturn($container)->shouldBeCalled();
  55. $object
  56. ->write('some content')
  57. ->shouldBeCalled()
  58. ->willReturn(true)
  59. ;
  60. $container
  61. ->get_object('filename')
  62. ->shouldBeCalled()
  63. ->willReturn($object)
  64. ;
  65. $this->write('filename', 'some content')->shouldReturn(12);
  66. }
  67. /**
  68. * @param \CF_Container $container
  69. * @param \CF_Object $object
  70. */
  71. function it_lazily_fetches_container_before_exists($connection, $container, $object)
  72. {
  73. $connection->get_container('my_container')->willReturn($container)->shouldBeCalled();
  74. $container
  75. ->get_object('filename')
  76. ->willReturn($object)
  77. ;
  78. $this->exists('filename')->shouldReturn(true);
  79. }
  80. /**
  81. * @param \CF_Container $container
  82. */
  83. function it_lazily_fetches_container_before_keys($connection, $container)
  84. {
  85. $connection->get_container('my_container')->willReturn($container)->shouldBeCalled();
  86. $container->list_objects(0, null, null)->willReturn(array('filename2', 'filename1'));
  87. $this->keys()->shouldReturn(array('filename1', 'filename2'));
  88. }
  89. /**
  90. * @param \CF_Container $container
  91. * @param \CF_Object $object
  92. */
  93. function it_lazily_fetches_container_before_checksum($connection, $container, $object)
  94. {
  95. $connection->get_container('my_container')->willReturn($container)->shouldBeCalled();
  96. $object->getETag()->willReturn('123m5');
  97. $container->get_object('filename')->willReturn($object);
  98. $this->checksum('filename')->shouldReturn('123m5');
  99. }
  100. /**
  101. * @param \CF_Container $container
  102. */
  103. function it_lazily_fetches_container_before_delete($connection, $container)
  104. {
  105. $connection->get_container('my_container')->willReturn($container)->shouldBeCalled();
  106. $container->delete_object('filename')->shouldBeCalled();
  107. $this->delete('filename')->shouldReturn(true);
  108. }
  109. }