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

[8.x] Clean up custom Queue payload between tests #36271

Merged
merged 4 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ protected function createStringPayload($job, $queue, $data)
/**
* Register a callback to be executed when creating job payloads.
*
* @param callable $callback
* @param callable|null $callback
* @return void
*/
public static function createPayloadUsing($callback)
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Queue/QueueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class QueueServiceProvider extends ServiceProvider implements DeferrableProvider
*/
public function register()
{
Queue::createPayloadUsing(null);

$this->registerManager();
$this->registerConnection();
$this->registerWorker();
Expand Down
61 changes: 61 additions & 0 deletions tests/Integration/Queue/CustomPayloadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Illuminate\Tests\Integration\Queue;

use Illuminate\Contracts\Bus\QueueingDispatcher;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\Queue;
use Illuminate\Support\ServiceProvider;
use Orchestra\Testbench\TestCase;

class CustomPayloadTest extends TestCase
{
protected function getPackageProviders($app)
{
return [QueueServiceProvider::class];
}

public function websites()
{
yield ['laravel.com'];

yield ['blog.laravel.com'];
}

/**
* @dataProvider websites
*/
public function test_custom_payload_gets_cleared_for_each_data_provider(string $websites)
{
$dispatcher = $this->app->make(QueueingDispatcher::class);

$dispatcher->dispatchToQueue(new MyJob);
}
}

class QueueServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind('one.time.password', function () {
return random_int(1, 10);
});

Queue::createPayloadUsing(function () {
$password = $this->app->make('one.time.password');

$this->app->offsetUnset('one.time.password');

return ['password' => $password];
});
}
}

class MyJob implements ShouldQueue
{
public $connection = 'sync';

public function handle()
{
}
}