BufferTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace League\CLImate\Tests;
  3. use League\CLImate\Util\Output;
  4. use League\CLImate\Util\Writer\Buffer;
  5. class BufferTest extends TestBase
  6. {
  7. /** @test */
  8. public function it_can_buffer_content()
  9. {
  10. $buffer = new Buffer;
  11. $output = new Output;
  12. $output->add('buffer', $buffer);
  13. $output->defaultTo('buffer');
  14. $output->write("Oh, you're still here.");
  15. $this->assertSame("Oh, you're still here.\n", $buffer->get());
  16. }
  17. /** @test */
  18. public function it_can_buffer_content_without_a_new_line()
  19. {
  20. $buffer = new Buffer;
  21. $output = new Output;
  22. $output->add('buffer', $buffer);
  23. $output->defaultTo('buffer');
  24. $output->sameLine()->write("Oh, you're still here.");
  25. $this->assertSame("Oh, you're still here.", $buffer->get());
  26. }
  27. /** @test */
  28. public function it_can_buffer_multiple_lines()
  29. {
  30. $buffer = new Buffer;
  31. $output = new Output;
  32. $output->add('buffer', $buffer);
  33. $output->defaultTo('buffer');
  34. $output->write("Oh, you're still here.");
  35. $output->write("Also am I.");
  36. $this->assertSame("Oh, you're still here.\nAlso am I.\n", $buffer->get());
  37. }
  38. /** @test */
  39. public function it_can_clean_buffered_content()
  40. {
  41. $buffer = new Buffer;
  42. $output = new Output;
  43. $output->add('buffer', $buffer);
  44. $output->defaultTo('buffer');
  45. $output->write("Oh, you're still here.");
  46. $buffer->clean();
  47. $output->write("I am on my own.");
  48. $this->assertSame("I am on my own.\n", $buffer->get());
  49. }
  50. }