StreamTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace League\CLImate\Tests\Util\Reader;
  3. use League\CLImate\Tests\TestBase;
  4. use League\CLImate\Util\Reader\Stream;
  5. class StreamTest extends TestBase
  6. {
  7. private $filename;
  8. private $stream;
  9. private $file;
  10. public function setUp(): void
  11. {
  12. $this->filename = tempnam(sys_get_temp_dir(), "climate_");
  13. $this->stream = new Stream($this->filename);
  14. $this->file = new \SplFileObject($this->filename, "w");
  15. }
  16. public function tearDown(): void
  17. {
  18. unset($this->file);
  19. unlink($this->filename);
  20. }
  21. public function testLine()
  22. {
  23. $this->file->fwrite("Line A\n");
  24. $this->file->fwrite("Line B\n");
  25. $response = $this->stream->line();
  26. $this->assertSame("Line A", $response);
  27. $response = $this->stream->line();
  28. $this->assertSame("Line B", $response);
  29. }
  30. public function testMutliLine()
  31. {
  32. $this->file->fwrite("Line one\n");
  33. $this->file->fwrite("Line two\n");
  34. $response = $this->stream->multiLine();
  35. $this->assertSame("Line one\nLine two", $response);
  36. }
  37. public function testChar()
  38. {
  39. $this->file->fwrite("123456789");
  40. $response = $this->stream->char(6);
  41. $this->assertSame("123456", $response);
  42. }
  43. public function testReopenStream()
  44. {
  45. $this->file->fwrite("Line 1\n");
  46. $this->file->fwrite("Line 2\n");
  47. $response = $this->stream->multiLine();
  48. $this->assertSame("Line 1\nLine 2", $response);
  49. $response = $this->stream->line();
  50. $this->assertSame("Line 1", $response);
  51. }
  52. }