|
6 | 6 | use Illuminate\Contracts\Queue\ShouldQueue;
|
7 | 7 | use Illuminate\Events\Dispatcher;
|
8 | 8 | use Illuminate\Foundation\Console\EventListCommand;
|
| 9 | +use Illuminate\Support\Facades\Artisan; |
9 | 10 | use Orchestra\Testbench\TestCase;
|
10 | 11 |
|
11 | 12 | class EventListCommandTest extends TestCase
|
@@ -58,6 +59,54 @@ public function testDisplayFilteredEvent()
|
58 | 59 | ->expectsOutputToContain('ExampleEvent');
|
59 | 60 | }
|
60 | 61 |
|
| 62 | + public function testDisplayEmptyListAsJson() |
| 63 | + { |
| 64 | + $this->withoutMockingConsoleOutput()->artisan(EventListCommand::class, ['--json' => true]); |
| 65 | + $output = Artisan::output(); |
| 66 | + |
| 67 | + $this->assertJson($output); |
| 68 | + $this->assertJsonStringEqualsJsonString('[]', $output); |
| 69 | + } |
| 70 | + |
| 71 | + public function testDisplayEventsAsJson() |
| 72 | + { |
| 73 | + $this->dispatcher->subscribe(ExampleSubscriber::class); |
| 74 | + $this->dispatcher->listen(ExampleEvent::class, ExampleListener::class); |
| 75 | + $this->dispatcher->listen(ExampleEvent::class, ExampleQueueListener::class); |
| 76 | + $this->dispatcher->listen(ExampleBroadcastEvent::class, ExampleBroadcastListener::class); |
| 77 | + $this->dispatcher->listen(ExampleEvent::class, fn () => ''); |
| 78 | + $closureLineNumber = __LINE__ - 1; |
| 79 | + $unixFilePath = str_replace('\\', '/', __FILE__); |
| 80 | + |
| 81 | + $this->withoutMockingConsoleOutput()->artisan(EventListCommand::class, ['--json' => true]); |
| 82 | + $output = Artisan::output(); |
| 83 | + |
| 84 | + $this->assertJson($output); |
| 85 | + $this->assertStringContainsString('ExampleSubscriberEventName', $output); |
| 86 | + $this->assertStringContainsString(json_encode('Illuminate\Tests\Integration\Console\Events\ExampleSubscriber@a'), $output); |
| 87 | + $this->assertStringContainsString(json_encode('Illuminate\Tests\Integration\Console\Events\ExampleBroadcastEvent (ShouldBroadcast)'), $output); |
| 88 | + $this->assertStringContainsString(json_encode('Illuminate\Tests\Integration\Console\Events\ExampleBroadcastListener'), $output); |
| 89 | + $this->assertStringContainsString(json_encode('Illuminate\Tests\Integration\Console\Events\ExampleEvent'), $output); |
| 90 | + $this->assertStringContainsString(json_encode('Closure at: '.$unixFilePath.':'.$closureLineNumber), $output); |
| 91 | + } |
| 92 | + |
| 93 | + public function testDisplayFilteredEventAsJson() |
| 94 | + { |
| 95 | + $this->dispatcher->subscribe(ExampleSubscriber::class); |
| 96 | + $this->dispatcher->listen(ExampleEvent::class, ExampleListener::class); |
| 97 | + |
| 98 | + $this->withoutMockingConsoleOutput()->artisan(EventListCommand::class, [ |
| 99 | + '--event' => 'ExampleEvent', |
| 100 | + '--json' => true, |
| 101 | + ]); |
| 102 | + $output = Artisan::output(); |
| 103 | + |
| 104 | + $this->assertJson($output); |
| 105 | + $this->assertStringContainsString('ExampleEvent', $output); |
| 106 | + $this->assertStringContainsString('ExampleListener', $output); |
| 107 | + $this->assertStringNotContainsString('ExampleSubscriberEventName', $output); |
| 108 | + } |
| 109 | + |
61 | 110 | protected function tearDown(): void
|
62 | 111 | {
|
63 | 112 | parent::tearDown();
|
|
0 commit comments