Skip to content

Commit

Permalink
[4.x] Make event watcher compatible with Laravel 8 subscriber syntax (#…
Browse files Browse the repository at this point in the history
…953)

* Make event watcher compatible with Laravel 8 subscriber syntax

* fix styleci
  • Loading branch information
paras-malhotra authored Sep 22, 2020
1 parent a69fc6f commit 1708902
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/Watchers/EventWatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,38 @@ public function test_event_watcher_stores_payloads()
$this->assertContains('PHP', $entry->content['payload']['data']);
}

public function test_event_watcher_registers_events_and_stores_payloads_with_subscriber_methods()
{
Event::listen(DummyEvent::class, DummyEventSubscriber::class.'@handleDummyEvent');

event(new DummyEvent('Telescope', 'Laravel', 'PHP'));

$entry = $this->loadTelescopeEntries()->first();

$this->assertSame(EntryType::EVENT, $entry->type);
$this->assertSame(DummyEvent::class, $entry->content['name']);
$this->assertArrayHasKey('data', $entry->content['payload']);
$this->assertContains('Telescope', $entry->content['payload']['data']);
$this->assertContains('Laravel', $entry->content['payload']['data']);
$this->assertContains('PHP', $entry->content['payload']['data']);
}

public function test_event_watcher_registers_events_and_stores_payloads_with_subscriber_classes()
{
Event::listen(DummyEvent::class, [DummyEventSubscriber::class, 'handleDummyEvent']);

event(new DummyEvent('Telescope', 'Laravel', 'PHP'));

$entry = $this->loadTelescopeEntries()->first();

$this->assertSame(EntryType::EVENT, $entry->type);
$this->assertSame(DummyEvent::class, $entry->content['name']);
$this->assertArrayHasKey('data', $entry->content['payload']);
$this->assertContains('Telescope', $entry->content['payload']['data']);
$this->assertContains('Laravel', $entry->content['payload']['data']);
$this->assertContains('PHP', $entry->content['payload']['data']);
}

public function test_event_watcher_ignore_event()
{
event(new IgnoredEvent());
Expand All @@ -80,6 +112,14 @@ public function handle()
}
}

class DummyEventSubscriber
{
public function handleDummyEvent($event)
{
//
}
}

class IgnoredEvent
{
public function handle()
Expand Down

0 comments on commit 1708902

Please sign in to comment.