ReportTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Facade\FlareClient\Tests;
  3. use Exception;
  4. use Facade\FlareClient\Context\ConsoleContext;
  5. use Facade\FlareClient\Glows\Glow;
  6. use Facade\FlareClient\Report;
  7. use Facade\FlareClient\Tests\Concerns\MatchesReportSnapshots;
  8. use Facade\FlareClient\Tests\TestClasses\FakeTime;
  9. class ReportTest extends TestCase
  10. {
  11. use MatchesReportSnapshots;
  12. public function setUp()
  13. {
  14. parent::setUp();
  15. Report::useTime(new FakeTime('2019-01-01 01:23:45'));
  16. }
  17. /** @test */
  18. public function it_can_create_a_report()
  19. {
  20. $report = Report::createForThrowable(new Exception('this is an exception'), new ConsoleContext());
  21. $report = $report->toArray();
  22. $this->assertMatchesReportSnapshot($report);
  23. }
  24. /** @test */
  25. public function it_can_create_a_report_for_a_string_message()
  26. {
  27. $report = Report::createForMessage('this is a message', 'Log', new ConsoleContext());
  28. $report = $report->toArray();
  29. $this->assertMatchesReportSnapshot($report);
  30. }
  31. /** @test */
  32. public function it_can_create_a_report_with_glows()
  33. {
  34. /** @var Report $report */
  35. $report = Report::createForThrowable(new Exception('this is an exception'), new ConsoleContext());
  36. $report->addGlow(new Glow('Glow 1', 'info', ['meta' => 'data']));
  37. $report = $report->toArray();
  38. $this->assertMatchesReportSnapshot($report);
  39. }
  40. /** @test */
  41. public function it_can_create_a_report_with_meta_data()
  42. {
  43. /** @var Report $report */
  44. $report = Report::createForThrowable(new Exception('this is an exception'), new ConsoleContext());
  45. $metadata = [
  46. 'some' => 'data',
  47. 'something' => 'more',
  48. ];
  49. $report->userProvidedContext(['meta' => $metadata]);
  50. $this->assertEquals($metadata, $report->toArray()['context']['meta']);
  51. }
  52. /** @test */
  53. public function it_will_generate_a_uuid()
  54. {
  55. $report = Report::createForThrowable(new Exception('this is an exception'), new ConsoleContext());
  56. $this->assertIsString($report->trackingUuid());
  57. $this->assertIsString($report->toArray()['tracking_uuid']);
  58. }
  59. }