|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Spiral\RoadRunnerLaravel\Tests\Unit\Listeners; |
| 6 | + |
| 7 | +use Mockery as m; |
| 8 | +use Laravel\Telescope\Telescope; |
| 9 | +use Laravel\Telescope\IncomingEntry; |
| 10 | +use Spiral\RoadRunnerLaravel\Listeners\SetupTelescopeListener; |
| 11 | +use Spiral\RoadRunnerLaravel\Events\Contracts\WithApplication; |
| 12 | + |
| 13 | +/** |
| 14 | + * @covers \Spiral\RoadRunnerLaravel\Listeners\SetupTelescopeListener |
| 15 | + */ |
| 16 | +class SetupTelescopeListenerTest extends AbstractListenerTestCase |
| 17 | +{ |
| 18 | + /** |
| 19 | + * {@inheritDoc} |
| 20 | + */ |
| 21 | + protected function setUp(): void |
| 22 | + { |
| 23 | + parent::setUp(); |
| 24 | + |
| 25 | + $this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * {@inheritdoc} |
| 30 | + */ |
| 31 | + public function testHandle(): void |
| 32 | + { |
| 33 | + /** @var m\MockInterface|WithApplication $event_mock */ |
| 34 | + $event_mock = m::mock(WithApplication::class) |
| 35 | + ->makePartial() |
| 36 | + ->expects('application') |
| 37 | + ->andReturn($this->app) |
| 38 | + ->getMock(); |
| 39 | + |
| 40 | + $this->assertEmpty(Telescope::$entriesQueue); |
| 41 | + Telescope::recordEvent($event = new IncomingEntry(['name' => 'Spiral\\RoadRunnerLaravel\\'])); |
| 42 | + Telescope::recordRequest($request = new IncomingEntry(['controller_action' => 'Laravel\\Telescope\\'])); |
| 43 | + Telescope::recordView($view = new IncomingEntry(['name' => 'telescope::foo'])); |
| 44 | + Telescope::recordRedis($redis1 = new IncomingEntry(['command' => 'get cache:telescope:pause-recording'])); |
| 45 | + Telescope::recordRedis($redis2 = new IncomingEntry(['command' => 'get cache:telescope:dump-watcher'])); |
| 46 | + $this->assertCount(5, Telescope::$entriesQueue); |
| 47 | + |
| 48 | + Telescope::flushEntries(); |
| 49 | + |
| 50 | + $this->listenerFactory()->handle($event_mock); |
| 51 | + |
| 52 | + $this->assertEmpty(Telescope::$entriesQueue); |
| 53 | + Telescope::recordEvent($event); |
| 54 | + Telescope::recordRequest($request); |
| 55 | + Telescope::recordView($view); |
| 56 | + Telescope::recordRedis($redis1); |
| 57 | + Telescope::recordRedis($redis2); |
| 58 | + $this->assertEmpty(Telescope::$entriesQueue); |
| 59 | + |
| 60 | + Telescope::recordBatch($any_another_entry = new IncomingEntry([])); |
| 61 | + Telescope::recordCache($any_another_entry); |
| 62 | + Telescope::recordCommand($any_another_entry); |
| 63 | + Telescope::recordDump($any_another_entry); |
| 64 | + Telescope::recordEvent($any_another_entry); |
| 65 | + Telescope::recordException($any_another_entry); |
| 66 | + Telescope::recordGate($any_another_entry); |
| 67 | + Telescope::recordJob($any_another_entry); |
| 68 | + Telescope::recordLog($any_another_entry); |
| 69 | + Telescope::recordMail($any_another_entry); |
| 70 | + Telescope::recordNotification($any_another_entry); |
| 71 | + Telescope::recordQuery($any_another_entry); |
| 72 | + Telescope::recordModelEvent($any_another_entry); |
| 73 | + Telescope::recordRedis($any_another_entry); |
| 74 | + Telescope::recordRequest($any_another_entry); |
| 75 | + Telescope::recordScheduledCommand($any_another_entry); |
| 76 | + Telescope::recordView($any_another_entry); |
| 77 | + Telescope::recordClientRequest($any_another_entry); |
| 78 | + $this->assertCount(18, Telescope::$entriesQueue); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @return SetupTelescopeListener |
| 83 | + */ |
| 84 | + protected function listenerFactory(): SetupTelescopeListener |
| 85 | + { |
| 86 | + return new SetupTelescopeListener(); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * {@inheritDoc} |
| 91 | + */ |
| 92 | + protected function tearDown(): void |
| 93 | + { |
| 94 | + Telescope::flushEntries(); |
| 95 | + |
| 96 | + parent::tearDown(); |
| 97 | + } |
| 98 | +} |
0 commit comments