-
Notifications
You must be signed in to change notification settings - Fork 47
Closed as not planned
Closed as not planned
Copy link
Labels
bugSomething isn't workingSomething isn't working
Description
What happened?
When registering an external event listener with #On(Phase::Handle) the respective Event's commit calls now return the original return value wrapped in a Collection.
How to reproduce the bug
See the example test below, which showcases how we don't get the expected Event::commit return value once we registered our listener. Also note the stray null element, which might somehow be the root cause of implicit wrapping into a collection?
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
use Thunk\Verbs\Attributes\Hooks\On;
use Thunk\Verbs\Event;
use Thunk\Verbs\Facades\Verbs;
use Thunk\Verbs\Lifecycle\Phase;
class ExampleVerbsListenerTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function handle_hook_turns_commit_response_into_collection(): void
{
// Get the commit return value before the event listener was registered
$result = MyEvent::commit();
$this->assertSame(MyEvent::COMMIT_RETURN_VALUE, $result);
// Register the event listener
Verbs::listen(ExampleVerbsListener::class);
// 💥 See our assetion fail
$result = MyEvent::commit();
$this->assertSame(MyEvent::COMMIT_RETURN_VALUE, $result);
}
}
class MyEvent extends Event
{
public const COMMIT_RETURN_VALUE = 'Hello!';
public function handle(): string
{
return self::COMMIT_RETURN_VALUE;
}
}
class ExampleVerbsListener
{
#[On(Phase::Handle)]
public function handle(Event $event): void {}
}Package Version
0.7.0
PHP Version
8.2.25
Laravel Version
10.48.29
Which operating systems does with happen with?
macOS
Notes
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
