SentReportsTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Facade\Ignition\Tests\Support;
  3. use Exception;
  4. use Facade\FlareClient\Report;
  5. use Facade\Ignition\Support\SentReports;
  6. use Facade\Ignition\Tests\TestCase;
  7. use Flare;
  8. class SentReportsTest extends TestCase
  9. {
  10. /** @var \Facade\Ignition\Support\SentReports[] */
  11. protected $sentReports = [];
  12. public function setUp(): void
  13. {
  14. parent::setUp();
  15. $this->sentReports = new SentReports();
  16. }
  17. /** @test */
  18. public function it_can_get_the_uuids()
  19. {
  20. $this->assertNull($this->sentReports->latestUuid());
  21. $report = $this->getReport('first-report');
  22. $this->sentReports->add($report);
  23. $this->assertEquals('first-report', $this->sentReports->latestUuid());
  24. $report = $this->getReport('second-report');
  25. $this->sentReports->add($report);
  26. $this->assertEquals('second-report', $this->sentReports->latestUuid());
  27. $this->assertEquals([
  28. 'first-report',
  29. 'second-report',
  30. ], $this->sentReports->uuids());
  31. }
  32. /** @test */
  33. public function it_can_get_the_error_urls()
  34. {
  35. $report = $this->getReport('first-report');
  36. $this->sentReports->add($report);
  37. $this->assertEquals('https://flareapp.io/tracked-occurrence/first-report', $this->sentReports->latestUrl());
  38. $report = $this->getReport('second-report');
  39. $this->sentReports->add($report);
  40. $this->assertEquals('https://flareapp.io/tracked-occurrence/second-report', $this->sentReports->latestUrl());
  41. $this->assertEquals([
  42. 'https://flareapp.io/tracked-occurrence/first-report',
  43. 'https://flareapp.io/tracked-occurrence/second-report',
  44. ], $this->sentReports->urls());
  45. }
  46. /** @test */
  47. public function it_can_be_cleared()
  48. {
  49. $report = $this->getReport('first-report');
  50. $this->sentReports->add($report);
  51. $this->assertCount(1, $this->sentReports->all());
  52. $this->sentReports->clear();
  53. $this->assertCount(0, $this->sentReports->all());
  54. }
  55. protected function getReport(string $fakeUuid = 'fake-uuid'): Report
  56. {
  57. Report::$fakeTrackingUuid = $fakeUuid;
  58. return Flare::report(new Exception());
  59. }
  60. }