StrackTraceTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Facade\FlareClient\Tests\Stacktrace;
  3. use Facade\FlareClient\Stacktrace\Stacktrace;
  4. use Facade\FlareClient\Tests\Concerns\MatchesCodeSnippetSnapshots;
  5. use Facade\FlareClient\Tests\TestCase;
  6. class StrackTraceTest extends TestCase
  7. {
  8. use MatchesCodeSnippetSnapshots;
  9. /** @test */
  10. public function it_can_convert_an_exception_to_an_array()
  11. {
  12. $exception = (new ThrowAndReturnExceptionAction())->execute();
  13. $stackTrace = Stacktrace::createForThrowable($exception)->toArray();
  14. $this->assertTrue(is_array($stackTrace));
  15. $this->assertGreaterThan(1, count($stackTrace));
  16. $this->assertMatchesCodeSnippetSnapshot($stackTrace[0]);
  17. }
  18. /** @test */
  19. public function it_can_create_a_stacktrace()
  20. {
  21. $stackTrace = Stacktrace::create()->toArray();
  22. $this->assertTrue(is_array($stackTrace));
  23. $this->assertGreaterThan(1, count($stackTrace));
  24. $this->assertMatchesCodeSnippetSnapshot($stackTrace[0]);
  25. }
  26. /** @test */
  27. public function it_can_detect_application_frames()
  28. {
  29. $applicationPath = '/Users/marcel/Code/flare-testapp';
  30. $backtrace = json_decode(file_get_contents(__DIR__.'/testFiles/backtrace.json'), true);
  31. $stackTrace = new Stacktrace($backtrace, $applicationPath);
  32. $this->assertSame(8, $stackTrace->firstApplicationFrameIndex());
  33. }
  34. }