123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <?php
- namespace spec\Gaufrette\Adapter;
- use PhpSpec\ObjectBehavior;
- class RackspaceCloudfilesSpec extends ObjectBehavior
- {
- /**
- * @param \CF_Container $container
- */
- function let($container)
- {
- $this->beConstructedWith($container);
- }
- function it_is_adapter()
- {
- $this->shouldHaveType('Gaufrette\Adapter');
- }
- function it_is_checksum_calculator()
- {
- $this->shouldHaveType('Gaufrette\Adapter\ChecksumCalculator');
- }
- /**
- * @param \CF_Container $container
- * @param \CF_Object $object
- */
- function it_reads_file($container, $object)
- {
- $object->read()->willReturn('some content');
- $container->get_object('filename')->willReturn($object);
- $this->read('filename')->shouldReturn('some content');
- }
- /**
- * @param \CF_Container $container
- * @param \CF_Object $object
- */
- function it_does_not_mask_exception_when_read($container, $object)
- {
- $object->read()->willThrow(new \RuntimeException('read'));
- $container->get_object('filename')->willReturn($object);
- $this->shouldThrow(new \RuntimeException('read'))->duringRead('filename');
- }
- /**
- * @param \CF_Container $container
- * @param \CF_Object $object
- */
- function it_does_check_if_file_exists($container, $object)
- {
- $container
- ->get_object('filename')
- ->willReturn($object)
- ;
- $container
- ->get_object('filename2')
- ->willReturn(false)
- ;
- $container
- ->get_object('filename3')
- ->willThrow(new \NoSuchObjectException)
- ;
- $this->exists('filename')->shouldReturn(true);
- $this->exists('filename2')->shouldReturn(false);
- $this->exists('filename3')->shouldReturn(false);
- }
- /**
- * @param \CF_Container $container
- * @param \CF_Object $object
- */
- function it_does_not_mask_exception_when_check_if_exists($container, $object)
- {
- $container->get_object('filename')->willThrow(new \RuntimeException('exists'));
- $this->shouldThrow(new \RuntimeException('exists'))->duringRead('filename');
- }
- /**
- * @param \CF_Container $container
- * @param \CF_Object $object
- */
- function it_should_write_file($container, $object)
- {
- $object
- ->write('some content')
- ->shouldBeCalled()
- ->willReturn(true)
- ;
- $container
- ->get_object('filename')
- ->shouldBeCalled()
- ->willReturn($object)
- ;
- $this->write('filename', 'some content')->shouldReturn(12);
- }
- /**
- * @param \CF_Container $container
- * @param \CF_Object $object
- */
- function it_does_not_write_file($container, $object)
- {
- $object
- ->write('some content')
- ->shouldBeCalled()
- ->willReturn(false)
- ;
- $container
- ->get_object('filename')
- ->shouldBeCalled()
- ->willReturn($object)
- ;
- $this->write('filename', 'some content')->shouldReturn(false);
- }
- /**
- * @param \CF_Container $container
- */
- function it_does_not_mask_exception_when_write($container)
- {
- $container->get_object('filename')->willThrow(new \RuntimeException('write'));
- $this->shouldThrow(new \RuntimeException('write'))->duringWrite('filename', 'some content');
- }
- /**
- * @param \CF_Container $container
- * @param \CF_Object $object
- */
- function it_creates_object_when_write($container, $object)
- {
- $object
- ->write('some content')
- ->shouldBeCalled()
- ->willReturn(true)
- ;
- $container
- ->get_object('filename')
- ->shouldBeCalled()
- ->willReturn(false)
- ;
- $container
- ->create_object('filename')
- ->shouldBeCalled()
- ->willReturn($object)
- ;
- $this->write('filename', 'some content')->shouldReturn(12);
- }
- /**
- * @param \CF_Container $container
- * @param \CF_Object $fromObject
- * @param \CF_Object $toObject
- */
- function it_renames_file($container, $fromObject, $toObject)
- {
- $fromObject
- ->read()
- ->willReturn('some content')
- ;
- $toObject
- ->write('some content')
- ->willReturn(true)
- ;
- $container
- ->delete_object('filename')
- ->shouldBeCalled()
- ;
- $container
- ->get_object('filename')
- ->willReturn($fromObject)
- ;
- $container
- ->get_object('filename1')
- ->willReturn($toObject)
- ;
- $this->rename('filename', 'filename1')->shouldReturn(true);
- }
- /**
- * @param \CF_Container $container
- */
- function it_does_not_mask_exception_when_rename($container)
- {
- $container->get_object('filename')->willThrow(new \RuntimeException('rename'));
- $this->shouldThrow(new \RuntimeException('rename'))->duringRename('filename', 'fromFilename');
- }
- /**
- * @param \CF_Container $container
- */
- function it_fetches_keys($container)
- {
- $container->list_objects(0, null, null)->willReturn(array('filename2', 'filename1'));
- $this->keys()->shouldReturn(array('filename1', 'filename2'));
- }
- /**
- * @param \CF_Container $container
- */
- function it_does_not_mask_exception_when_get_keys($container)
- {
- $container->list_objects(0, null, null)->willThrow(new \RuntimeException('keys'));
- $this->shouldThrow(new \RuntimeException('keys'))->duringKeys();
- }
- function it_does_not_support_mtime()
- {
- $this->mtime('filename')->shouldBe(false);
- $this->mtime('filename2')->shouldBe(false);
- }
- /**
- * @param \CF_Container $container
- * @param \CF_Object $object
- */
- function it_calculates_checksum($container, $object)
- {
- $object->getETag()->willReturn('123m5');
- $container->get_object('filename')->willReturn($object);
- $this->checksum('filename')->shouldReturn('123m5');
- }
- /**
- * @param \CF_Container $container
- */
- function it_does_not_mask_exception_when_calculate_checksum($container)
- {
- $container->get_object('filename')->willThrow(new \RuntimeException('checksum'));
- $this->shouldThrow(new \RuntimeException('checksum'))->duringChecksum('filename');
- }
- /**
- * @param \CF_Container $container
- */
- function it_deletes_file($container)
- {
- $container->delete_object('filename')->shouldBeCalled();
- $this->delete('filename')->shouldReturn(true);
- }
- /**
- * @param \CF_Container $container
- */
- function it_does_not_delete_file_if_not_found($container)
- {
- $container->delete_object('filename')->willThrow(new \NoSuchObjectException);
- $this->delete('filename')->shouldReturn(false);
- }
- /**
- * @param \CF_Container $container
- */
- function it_does_not_mask_exception_when_delete($container)
- {
- $container->delete_object('filename')->willThrow(new \RuntimeException('delete'));
- $this->shouldThrow(new \RuntimeException('delete'))->duringDelete('filename');
- }
- function it_does_not_support_directory()
- {
- $this->isDirectory('filename')->shouldReturn(false);
- }
- }
|