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

[5.7] Added test helper to assert that a Job has been queued with a Chain #23381

Closed
wants to merge 4 commits into from

Conversation

asantibanez
Copy link
Contributor

The following PR adds a helper method for testing that allows to assert if a Job was pushed to the Queue with a specific Chain. The proposed method name is assertPushedWithChain and expects two parameters: the First Job in the Chain and an array of Jobs that will execute.

I have attached an image on how this assertion can be used.

image

I have used the Queueable trait chain method to simulate jobs serialization and have used the same method to check for the chain in the assertion method.

image

This helper can be useful to assert that a chain has been triggered with a specific set of jobs and order.

Hope it is useful for others! Cheers!

@asantibanez
Copy link
Contributor Author

I am sorry about the second commit for this PR. I removed some dead code I had from my previous implementation for the same feature.

@asantibanez
Copy link
Contributor Author

I made some extra digging and found out that when the expected chain assertion fails, it gives a not so helpful message when checking the compared values (at least on PhpStorm)

image

However, working with serialization the other way around, the compared values are more meaningful for debugging.

image

This is done by unserializing the jobs chain instead of serializing the expected chain.

image

This could be decided going forward if the PR is a welcomed addition.

Thanks.

@GrahamCampbell GrahamCampbell changed the title Added test helper to assert that a Job has been queued with a Chain [5.7] Added test helper to assert that a Job has been queued with a Chain Mar 4, 2018
@taylorotwell
Copy link
Member

What if you pushed the same job once without a chain and once with chain. Wouldn't this fail since you are only checking the first pushed job for the chain?

@asantibanez
Copy link
Contributor Author

You are right @taylorotwell . Never crossed my mind on testing if the same job was queued but with different payload. Let me check on how to deal with this scenario. I imagine it has to be similar than using a call back to check if the correct job was queued.

Is the proposed feature using correctly the job serialization/unserialization? I was also thinking on just testing for the class name to be chained instead of the object. What are your thoughts on this one?

Thanks.

- Added callback to support identifying particular jobs
- Added tests
@asantibanez
Copy link
Contributor Author

@taylorotwell

I have added support for checking for particular jobs using a callback. This will cover the scenario you spoke of:

What if you pushed the same job once without a chain and once with chain. Wouldn't this fail since you are only checking the first pushed job for the chain?

I have also added support for checking for chained jobs using class names. Now it is possible to check using an array of job class names or an array of job objects

image

Hope it is all good. Thanks for the feedback.

Regards.

@taylorotwell
Copy link
Member

I still see you taking the first job. What if I push the same job twice with different chains? I want to assert that the job was pushed with each chain, so I would call assertPushedWithChain twice for the same job type but different chains. I would expect them both to pass. Feel free to re-visit when that has been solved.

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.

None yet

2 participants