Skip to content

[5.8] Bugfix - QueueFake size method and added a test#29761

Merged
taylorotwell merged 7 commits into
laravel:5.8from
hlorofos:5.8
Sep 2, 2019
Merged

[5.8] Bugfix - QueueFake size method and added a test#29761
taylorotwell merged 7 commits into
laravel:5.8from
hlorofos:5.8

Conversation

@hlorofos

Copy link
Copy Markdown

This is fixing #29755

Comment thread tests/Queue/QueueSizeTest.php Outdated
Comment thread tests/Queue/QueueSizeTest.php Outdated
Comment thread tests/Queue/QueueSizeTest.php Outdated
@hlorofos hlorofos marked this pull request as ready for review August 27, 2019 14:37
@GrahamCampbell

Copy link
Copy Markdown
Collaborator

This will break if the queue is null?

@hlorofos

Copy link
Copy Markdown
Author

This will break if the queue is null?

@GrahamCampbell thats why I put first assertion in the test without pushing anything to a queue:

Queue::fake();
        $this->assertEquals(0, Queue::size());

there is initializer for $job in QueueFake

    protected $jobs = [];

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

No, I mean if there are jobs, but the queue name is null, it should be non-zero.

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

To clarify, in Laravel, using null for the queue name means "use the default". This needs to be handled within the implementation.

@hlorofos

Copy link
Copy Markdown
Author

To clarify, in Laravel, using null for the queue name means "use the default". This needs to be handled within the implementation.

@GrahamCampbell , here are my explanations in the test, please consider if possible to explain what's wrong based on the test:

        dispatch($job); // Pushed to default queue
        dispatch(new TestJob2); //  Other job pushed to default queue, this would validate we traverse through different job classes properly
        dispatch($job)->onQueue('Q2'); // Pushed to queue 'Q2'

        $this->assertEquals(2, Queue::size()); // Get the amount of jobs in default queue, internally its NULL for QueueFake
        $this->assertEquals(1, Queue::size('Q2')); // Get the amount of jobs in queue `Q2`

If you're talking about default property for Queue implementations this have nothing to do with QueueFake implementation.

@taylorotwell

Copy link
Copy Markdown
Member

I think you can already assert on Queue::pushedJobs() when using the fake. I'm not sure having size always return the number of pushed jobs makes sense.

@hlorofos

Copy link
Copy Markdown
Author

@taylorotwell you interpret this wrong, I'm testing my code which expose Queue::size through API. Since I'm faking queue and testing API which calling size() - as a developer I expect size method return proper value instead of some random number.

@taylorotwell taylorotwell reopened this Sep 2, 2019
@taylorotwell taylorotwell merged commit b27be4f into laravel:5.8 Sep 2, 2019
@driesvints

Copy link
Copy Markdown
Member

@hlorofos we got this merged 👍

@hlorofos

hlorofos commented Sep 3, 2019

Copy link
Copy Markdown
Author

@hlorofos we got this merged 👍

@driesvints appreciate all your help along the way!

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.

4 participants