-
Notifications
You must be signed in to change notification settings - Fork 25
Update event assertions #168
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
Update event assertions #168
Conversation
…ate existing ones)
@TavoNiievez, I just realized (stumbled on this in my tests) that it would be nice to have a method that checks if an event was dispatched regardless of whether it has listeners or not (if it is orphaned). What do you think about this? Should I update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @xEdelweiss,
I totally agree, in #147 it was already established that the names were not correct, and I'm glad to see that someone has been able to come up with a much better approach :).
In general I see quite well what you did in your PR, my only observations are the following:
-
Since in Codeception it is important that the method names (assertions) can be written just like in natural language, I think you could name these methods like
seeEventListenerWasCalled
anddontSeeEventListenerWasCalled
, I think adding the 'Was' here would be fine. -
I agree with adding the new methods you indicate:
seeEvent
anddontSeeEvent
and it would be great if you could add tests for them, but I would ask you to add them in a different PR (I will merge both, don't worry) but this way it will be easier to review the changes in the future. (i.e. in one PR you modify the names, and in another you add the new methods.)
Are you ok with doing it this way? -
One last thing. I see that the way you deprecated the old methods was with the @deprecated annotation, while it is an option, it seems to me that when someone runs the tests it won't pop up any warning that those methods are deprecated and will be removed in the future (usually the next major version of the module), I'm not sure if @Naktibalda can tell us if in Codeception there is a standard way to deprecate things like this that we can use, or if using the annotation would be the right thing to do.
Thanks!
Just some thoughts from me. I don't use events that much, so I can't come up with a real suggestion.
|
trigger_error('message', E_USER_DEPRECATED); Deprecation messages are counted and printed below test execution results unless: |
Hi! Thank you all for your feedback. I'll start with the deprecations.
@TavoNiievez good point. Also, Given @ThomasLandauer it seems a good idea to name them using "is" for consistency.
@ThomasLandauer, that's the question I was asking myself. I have got the impression that in Symfony code, listeners are more often called with the Listener suffix (although they do implement EventSubscriberInterface), so I think this name will be more understandable. To continue the current discussion about new methods I've added another PR that includes only methods deprecation and adds new names for them: #169. |
… (deprecate existing ones)" This reverts commit 0274d16.
@ThomasLandauer I agree, it would be nice to cover this. There is one question though: how it should be handled if the user passes multiple event listeners: $I->seeEventListenerIsCalled([CalledListenerOne::class, CalledListenerTwo::class], 'event.name');
$I->seeEventListenerIsCalled([CalledListenerOne::class, CalledListenerTwo::class], ['event_one.name', 'event_two.name'] Should it check that all events are handled by all listeners? It may seem confusing. Or we can disallow passing multiple listeners and require to call seeEventListenerIsCalled multiple times. $I->seeEventListenerIsCalled(CalledListenerOne::class, ['event_one.name', 'event_two.name']
$I->seeEventListenerIsCalled(CalledListenerTwo::class, ['event_one.name', 'event_two.name']
In my code, I check that some component dispatches an event and often it can be done before the listener/subscriber is implemented. |
It would only occur to me to write that as an associative array: $I->seeEventListenerIsCalled([
CalledListenerOne::class => ['event_one.name', 'event_two.name'],
CalledListenerTwo::class => ['event_three.name', 'event_four.name'],
]); But it seems to me that it would be more complex than necessary, both in implementation and reading.
I also agree. |
I also agree to disallow this. Most Codeception methods are pretty straightforward. Introducing some fancy array syntax only makes it more complicated than necessary. Even more so, as a super easy alternative is available: |
0274d16
to
46ba34b
Compare
…ate existing ones)
46ba34b
to
05fb9e0
Compare
Hi @xEdelweiss , I have updated your branch with the latest changes present in the main branch of this repository, plus I have added a small fix for an incorrect method call. Currently your PR is doing several things at once: Also, the Please create different PRs for these tasks in order to continue. |
@xEdelweiss remember that the agreed names for the new methods are:
currently in your PR are added two additional methods named:
in addition to the first two already mentioned. |
…date_event_assertions
Hi @TavoNiievez, I apologize for my absence and the slight mess in the commits history. As we discussed, I have implemented the possibility to check if a listener was triggered for a specific event(s) within the $I->seeEventListenerIsCalled(CalledListenerOne::class, 'event_one.name');
$I->seeEventListenerIsCalled(CalledListenerTwo::class, ['event_one.name', 'event_two.name']);
// and the same for dontSeeEventListenerIsCalled Additionally, I have removed the
These were removed as well. I've updated the tests, and I'm ready to create a PR for it when required. |
Hi @xEdelweiss , Don't worry about the git history while working on this PR. In any case it will be merged to the main branch of this repository with the 'Squash and merge' strategy so the main repo will only get a single commit. At the moment I have fixed some tests that were failing in the test project (symfony-module-tests), I will review the changes you have added as soon as possible. Thanks. |
Hi! Currently,
seeEventTriggered
anddontSeeEventTriggered
are actually checking if Event Listener was called.So I've marked these methods as deprecated and created new ones for the Listeners with more intuitive names:
seeEventListenerCalled
dontSeeEventListenerCalled
Additionally, I've added methods to check if Events were dispatched (named them in a way like
seeOrphanEvent
):seeEvent
dontSeeEvent
Tests can be updated if you approve this PR.