/spec/Gaufrette/Adapter/Local.php

https://bitbucket.org/ajalovec/gaufrette · PHP · 143 lines · 118 code · 24 blank · 1 comment · 0 complexity · bd32f2f0e23af9490399751ecb2fe579 MD5 · raw file

  1. <?php
  2. namespace spec\Gaufrette\Adapter;
  3. //hack - mock php built-in functions
  4. require_once 'functions.php';
  5. use PHPSpec2\ObjectBehavior;
  6. class Local extends ObjectBehavior
  7. {
  8. function let()
  9. {
  10. $this->beConstructedWith('/home/somedir');
  11. }
  12. function letgo()
  13. {
  14. global $iteratorToArray;
  15. $iteratorToArray = array();
  16. }
  17. function it_should_be_initializable()
  18. {
  19. $this->shouldHaveType('Gaufrette\Adapter\Local');
  20. }
  21. function it_should_read_file()
  22. {
  23. $this->read('filename')->shouldReturn('/home/somedir/filename content');
  24. }
  25. function it_should_write_file()
  26. {
  27. $this->write('filename', 'some content')->shouldReturn(12);
  28. }
  29. function it_should_rename_file()
  30. {
  31. $this->rename('filename', 'aaa/filename2')->shouldReturn('/home/somedir/filename to /home/somedir/aaa/filename2');
  32. }
  33. function it_should_check_if_file_exists()
  34. {
  35. $this->exists('filename')->shouldReturn(true);
  36. $this->exists('filename1')->shouldReturn(false);
  37. }
  38. function it_should_get_keys()
  39. {
  40. global $iteratorToArray;
  41. $iteratorToArray = array('/home/somedir/filename', '/home/somedir/filename1', '/home/somedir/aaa/filename');
  42. $this->keys()->shouldReturn(array('aaa', 'aaa/filename', 'filename', 'filename1'));
  43. }
  44. function it_should_get_mtime()
  45. {
  46. $this->mtime('filename')->shouldReturn(12345);
  47. }
  48. function it_should_delete_file()
  49. {
  50. $this->delete('filename')->shouldReturn(true);
  51. $this->delete('filename1')->shouldReturn(false);
  52. }
  53. function it_should_check_if_key_is_dir()
  54. {
  55. $this->isDirectory('dir')->shouldReturn(true);
  56. $this->isDirectory('filename')->shouldReturn(false);
  57. }
  58. function it_should_create_local_stream()
  59. {
  60. $this->createStream('filename')->shouldReturnAnInstanceOf('Gaufrette\Stream\Local');
  61. }
  62. function it_should_accepts_symbolic_links()
  63. {
  64. $this->beConstructedWith('symbolicLink');
  65. $this->read('filename')->shouldReturn('/home/somedir/filename content');
  66. }
  67. function it_should_not_allow_to_read_path_above_main_file_directory()
  68. {
  69. $this
  70. ->shouldThrow(new \OutOfBoundsException('The path "/home/filename" is out of the filesystem.'))
  71. ->duringRead('../filename');
  72. $this
  73. ->shouldThrow(new \OutOfBoundsException('The path "/home/filename" is out of the filesystem.'))
  74. ->duringExists('../filename');
  75. }
  76. function it_should_fail_when_directory_does_not_exists()
  77. {
  78. $this->beConstructedWith('/home/other');
  79. $this
  80. ->shouldThrow(new \RuntimeException('The directory "/home/other" does not exist.'))
  81. ->duringRead('filename');
  82. $this
  83. ->shouldThrow(new \RuntimeException('The directory "/home/other" does not exist.'))
  84. ->duringWrite('filename', 'some content');
  85. $this
  86. ->shouldThrow(new \RuntimeException('The directory "/home/other" does not exist.'))
  87. ->duringRename('filename', 'otherFilename');
  88. $this
  89. ->shouldThrow(new \RuntimeException('The directory "/home/other" does not exist.'))
  90. ->duringExists('filename');
  91. $this
  92. ->shouldThrow(new \RuntimeException('The directory "/home/other" does not exist.'))
  93. ->duringKeys();
  94. $this
  95. ->shouldThrow(new \RuntimeException('The directory "/home/other" does not exist.'))
  96. ->duringMtime('filename');
  97. $this
  98. ->shouldThrow(new \RuntimeException('The directory "/home/other" does not exist.'))
  99. ->duringDelete('filename');
  100. $this
  101. ->shouldThrow(new \RuntimeException('The directory "/home/other" does not exist.'))
  102. ->duringIsDirectory('filename');
  103. $this
  104. ->shouldThrow(new \RuntimeException('The directory "/home/other" does not exist.'))
  105. ->duringCreateStream('filename');
  106. $this
  107. ->shouldThrow(new \RuntimeException('The directory "/home/other" does not exist.'))
  108. ->duringChecksum('filename');
  109. }
  110. function it_should_create_directory_when_does_not_exists()
  111. {
  112. $this->beConstructedWith('/home/other', true);
  113. $this->read('filename')->shouldReturn('/home/other/filename content');
  114. }
  115. function it_should_be_able_to_calculate_checksum()
  116. {
  117. $this->shouldHaveType('Gaufrette\Adapter\ChecksumCalculator');
  118. }
  119. }