StreamModeSpec.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace spec\Gaufrette;
  3. use PhpSpec\ObjectBehavior;
  4. class StreamModeSpec extends ObjectBehavior
  5. {
  6. function it_is_initializable()
  7. {
  8. $this->beConstructedWith('r');
  9. $this->shouldHaveType('Gaufrette\StreamMode');
  10. }
  11. function it_gives_access_to_mode()
  12. {
  13. $this->beConstructedWith('r+');
  14. $this->getMode()->shouldReturn('r+');
  15. }
  16. function it_allows_write_only()
  17. {
  18. $this->beConstructedWith('w');
  19. $this->allowsWrite()->shouldReturn(true);
  20. $this->allowsRead()->shouldReturn(false);
  21. }
  22. function it_allows_write_and_read()
  23. {
  24. $this->beConstructedWith('w+');
  25. $this->allowsWrite()->shouldReturn(true);
  26. $this->allowsRead()->shouldReturn(true);
  27. }
  28. function it_allows_read_only()
  29. {
  30. $this->beConstructedWith('r');
  31. $this->allowsWrite()->shouldReturn(false);
  32. $this->allowsRead()->shouldReturn(true);
  33. }
  34. function it_allows_to_existing_file_opening()
  35. {
  36. $this->beConstructedWith('r');
  37. $this->allowsExistingFileOpening()->shouldReturn(true);
  38. }
  39. function it_does_not_allow_to_existing_file_opening()
  40. {
  41. $this->beConstructedWith('x');
  42. $this->allowsExistingFileOpening()->shouldReturn(false);
  43. }
  44. function it_allows_new_file_opening()
  45. {
  46. $this->beConstructedWith('w');
  47. $this->allowsNewFileOpening()->shouldReturn(true);
  48. }
  49. function it_does_not_allow_new_file_opening()
  50. {
  51. $this->beConstructedWith('r');
  52. $this->allowsNewFileOpening()->shouldReturn(false);
  53. }
  54. function it_implies_existing_content_deletion()
  55. {
  56. $this->beConstructedWith('w+');
  57. $this->allowsNewFileOpening()->shouldReturn(true);
  58. }
  59. function it_does_not_implies_existing_content_deletion()
  60. {
  61. $this->beConstructedWith('r+');
  62. $this->allowsNewFileOpening()->shouldReturn(false);
  63. }
  64. function it_implies_positioning_cursor_at_the_beginning()
  65. {
  66. $this->beConstructedWith('r+');
  67. $this->impliesPositioningCursorAtTheBeginning()->shouldReturn(true);
  68. }
  69. function it_does_no_implies_positioning_cursor_at_the_beginning()
  70. {
  71. $this->beConstructedWith('a');
  72. $this->impliesPositioningCursorAtTheBeginning()->shouldReturn(false);
  73. }
  74. function it_implies_positioning_cursor_at_the_end()
  75. {
  76. $this->beConstructedWith('a');
  77. $this->impliesPositioningCursorAtTheEnd()->shouldReturn(true);
  78. }
  79. function it_does_no_implies_positioning_cursor_at_the_end()
  80. {
  81. $this->beConstructedWith('w');
  82. $this->impliesPositioningCursorAtTheEnd()->shouldReturn(false);
  83. }
  84. function it_should_be_binary()
  85. {
  86. $this->beConstructedWith('wb+');
  87. $this->isBinary()->shouldReturn(true);
  88. }
  89. function it_should_not_be_binary()
  90. {
  91. $this->beConstructedWith('w+');
  92. $this->isBinary()->shouldReturn(false);
  93. }
  94. function it_should_not_be_text()
  95. {
  96. $this->beConstructedWith('wb+');
  97. $this->isText()->shouldReturn(false);
  98. }
  99. function it_should_be_text()
  100. {
  101. $this->beConstructedWith('w+');
  102. $this->isText()->shouldReturn(true);
  103. }
  104. }