Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add FakeEventDispatcher inspired by Laravel #524

Closed
wants to merge 1 commit into from

Conversation

simonschaufi
Copy link
Contributor

@simonschaufi simonschaufi commented Dec 1, 2023

See https://laravel.com/docs/10.x/events#testing for inspiration source and https://github.com/laravel/framework/blob/10.x/src/Illuminate/Support/Testing/Fakes/EventFake.php for the original source code.

How to use:

use TYPO3\CMS\Core\EventDispatcher\ListenerProvider;

$fakeEventDispatcher = new FakeEventDispatcher(new ListenerProvider($this->getContainer()));

// $this->subject is an Extbase Controller
$this->subject->injectEventDispatcher($fakeEventDispatcher);

// run code which should dispatch an event (dispatch controller)

$fakeEventDispatcher->assertDispatched(MyEvent::class);

@lolli42
Copy link
Member

lolli42 commented Oct 8, 2024

Hey.

We decided to not go with this PR:

  • In general, we want rather less than more helper classes in TF and only add things that are really very much needed by tests.
  • Testing that events are actually dispatched by SUT often gives only very little value: dispatching an event is codewise no-brainish, there is little that can go wrong, having a test does not add crucial value.
  • Devs who still want to check if events have been dispatched can easily do that with casual phpunit mocks and expectations. Having a helper class for this would add another "special handling" that can be solved with base phpunit API instead.

@lolli42 lolli42 closed this Oct 8, 2024
@simonschaufi simonschaufi deleted the FakeEventDispatcher branch October 8, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants