FileTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Facade\FlareClient\Tests\Stacktrace;
  3. use Facade\FlareClient\Stacktrace\File;
  4. use Facade\FlareClient\Tests\TestCase;
  5. class FileTest extends TestCase
  6. {
  7. /** @var \Facade\FlareClient\Stacktrace\File */
  8. protected $file;
  9. public function setUp()
  10. {
  11. $this->file = new File($this->getTestFilePath('20-lines.txt'));
  12. }
  13. /** @test */
  14. public function it_can_get_the_number_of_lines()
  15. {
  16. $this->assertEquals(20, $this->file->numberOfLines());
  17. }
  18. /** @test */
  19. public function it_can_get_a_specific_line()
  20. {
  21. $line = $this->file->getLine(18);
  22. $this->assertEquals($line, 'Line 18'.PHP_EOL);
  23. }
  24. /** @test */
  25. public function it_can_get_the_next_line()
  26. {
  27. $this->file->getLine(18);
  28. $this->assertEquals($this->file->getNextLine(), 'Line 19'.PHP_EOL);
  29. }
  30. /** @test */
  31. public function it_will_get_the_next_line_if_no_line_number_is_given()
  32. {
  33. $this->file->getLine(18);
  34. $this->assertEquals($this->file->getLine(), 'Line 19'.PHP_EOL);
  35. }
  36. /** @test */
  37. public function it_will_return_an_empty_string_for_a_line_that_doesnt_exist()
  38. {
  39. $this->assertEquals('', $this->file->getLine(21));
  40. $this->assertEquals('', $this->file->getNextLine());
  41. }
  42. private function getTestFilePath(string $fileName): string
  43. {
  44. return __DIR__."/testFiles/{$fileName}";
  45. }
  46. }