Closed patrickomeara closed 3 months ago
Hiya! 👋
Thanks for the great PR!
I'm really liking this and I love the fact that this kills a test helper. It's usually a good sign that this is needed for the API. However, I'm having a hard time digesting the name assertPushedWithParamsOn
haha.
Also, I'm not sure if this is now the convention in Laravel, but in testing frameworks, I'm more used to a single With
suffix instead of WithParams
. I think the following API could be a bit more intuitive.
assertPushedWithParams
to assertPushedWith
. E.g. SendPodcastPublishedEmail::assertPushedWith([$user, $podcast]);
looks very clean to me.assertNotPushedWith
.assertPushedWithParamsOn
. We already have assertPushedWith
and assertPushedOn
so why not just make people do two assertions in order to compose them instead of trying to create helpers that do it all. See example below.SendPodcastPublishedEmail::assertPushedWith([$user, $podcast]);
SendPodcastPublishedEmail::assertPushedOn("someQueue");
What do you think?
I think you're right about the naming, I'll update that and clean it up. Let me have a think about the queue, because having it in two different assertions could assert two different jobs have been pushed.
I've cleaned up the naming, and it feels much better.
The queue can be asserted using:
SendPodcastPublishedEmail::assertPushedWith([$user, $podcast], 'someQueue');
Perfect, thank you for this! 🍺
Problem
When I am testing that actions are pushed correctly, I almost always want to check the parameters that it is pushed with.
Currently it is a little cumbersome to check the params, as they are passed in as an array.
Additionally, the thing I want to check is in the second argument so I have an unused variable.
Solution
If we spread the params into the callback we can use type safety to check we have the correct type and shortcut the param check.
Or we can assert by an array
Or my favourite way if the action only has a single param.
This PR also adds the ability to assert the queue using
assertPushedWithParamsOn()
, and assert that an action wasn't pushed with params usingassertNotPushedWithParams()
I later found a test helper
assertJobPushedWith()
that could be replaced.Note: Naming the methods
assertPushedWith()
,assertNotPushedWith()
also works well, but sounds a little strange when checking the queue as wellassertPushedWithOn()
I'm easy either way.