-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[11.x] Accepts BackedEnum for onQueue, onConnection, allOnQueue, and …
…allOnConnection methods in the Queueable trait (#52604) * Accepts StringBackedEnum * Tests * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
- Loading branch information
1 parent
d343e5b
commit 811ea6a
Showing
2 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Bus; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class QueueableTest extends TestCase | ||
{ | ||
public static function connectionDataProvider(): array | ||
{ | ||
return [ | ||
'uses string' => ['redis', 'redis'], | ||
'uses BackedEnum #1' => [ConnectionEnum::SQS, 'sqs'], | ||
'uses BackedEnum #2' => [ConnectionEnum::REDIS, 'redis'], | ||
'uses null' => [null, null], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider connectionDataProvider | ||
*/ | ||
public function testOnConnection(mixed $connection, ?string $expected): void | ||
{ | ||
$job = new FakeJob(); | ||
$job->onConnection($connection); | ||
|
||
$this->assertSame($job->connection, $expected); | ||
} | ||
|
||
/** | ||
* @dataProvider connectionDataProvider | ||
*/ | ||
public function testAllOnConnection(mixed $connection, ?string $expected): void | ||
{ | ||
$job = new FakeJob(); | ||
$job->allOnConnection($connection); | ||
|
||
$this->assertSame($job->connection, $expected); | ||
$this->assertSame($job->chainConnection, $expected); | ||
} | ||
|
||
public static function queuesDataProvider(): array | ||
{ | ||
return [ | ||
'uses string' => ['high', 'high',], | ||
'uses BackedEnum #1' => [QueueEnum::DEFAULT, 'default'], | ||
'uses BackedEnum #2' => [QueueEnum::HIGH, 'high'], | ||
'uses null' => [null, null], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider queuesDataProvider | ||
*/ | ||
public function testOnQueue(mixed $queue, ?string $expected): void | ||
{ | ||
$job = new FakeJob(); | ||
$job->onQueue($queue); | ||
|
||
$this->assertSame($job->queue, $expected); | ||
} | ||
|
||
/** | ||
* @dataProvider queuesDataProvider | ||
*/ | ||
public function testAllOnQueue(mixed $queue, ?string $expected): void | ||
{ | ||
$job = new FakeJob(); | ||
$job->allOnQueue($queue); | ||
|
||
$this->assertSame($job->queue, $expected); | ||
$this->assertSame($job->chainQueue, $expected); | ||
} | ||
} | ||
|
||
class FakeJob { | ||
use Queueable; | ||
} | ||
|
||
enum ConnectionEnum: string { | ||
case SQS = 'sqs'; | ||
case REDIS = 'redis'; | ||
} | ||
|
||
enum QueueEnum: string { | ||
case HIGH = 'high'; | ||
case DEFAULT = 'default'; | ||
} |