Skip to content

Commit 9fe14c8

Browse files
[10.x] Test Improvements (#49338)
* wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: StyleCI Bot <[email protected]>
1 parent 00c9c7f commit 9fe14c8

19 files changed

+496
-223
lines changed

.github/workflows/queues.yml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: queues
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- '*.x'
8+
pull_request:
9+
10+
jobs:
11+
sync:
12+
runs-on: ubuntu-22.04
13+
14+
strategy:
15+
fail-fast: true
16+
17+
name: Sync Driver
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: 8.1
29+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
30+
tools: composer:v2
31+
coverage: none
32+
33+
- name: Install dependencies
34+
uses: nick-fields/retry@v2
35+
with:
36+
timeout_minutes: 5
37+
max_attempts: 5
38+
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
39+
40+
- name: Execute tests
41+
run: vendor/bin/phpunit tests/Integration/Queue
42+
env:
43+
QUEUE_CONNECTION: sync
44+
45+
database:
46+
runs-on: ubuntu-22.04
47+
48+
strategy:
49+
fail-fast: true
50+
51+
name: Database Driver
52+
53+
steps:
54+
- name: Checkout code
55+
uses: actions/checkout@v4
56+
with:
57+
fetch-depth: 0
58+
59+
- name: Setup PHP
60+
uses: shivammathur/setup-php@v2
61+
with:
62+
php-version: 8.1
63+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
64+
tools: composer:v2
65+
coverage: none
66+
67+
- name: Install dependencies
68+
uses: nick-fields/retry@v2
69+
with:
70+
timeout_minutes: 5
71+
max_attempts: 5
72+
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
73+
74+
- name: Execute tests
75+
run: vendor/bin/phpunit tests/Integration/Queue
76+
env:
77+
DB_CONNECTION: testing
78+
QUEUE_CONNECTION: database
79+
80+
redis:
81+
runs-on: ubuntu-22.04
82+
83+
services:
84+
redis:
85+
image: redis:7.0
86+
ports:
87+
- 6379:6379
88+
options: --entrypoint redis-server
89+
90+
strategy:
91+
fail-fast: true
92+
93+
name: Redis Driver
94+
95+
steps:
96+
- name: Checkout code
97+
uses: actions/checkout@v4
98+
with:
99+
fetch-depth: 0
100+
101+
- name: Setup PHP
102+
uses: shivammathur/setup-php@v2
103+
with:
104+
php-version: 8.1
105+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
106+
tools: composer:v2
107+
coverage: none
108+
109+
- name: Install dependencies
110+
uses: nick-fields/retry@v2
111+
with:
112+
timeout_minutes: 5
113+
max_attempts: 5
114+
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
115+
116+
- name: Execute tests
117+
run: vendor/bin/phpunit tests/Integration/Queue
118+
env:
119+
QUEUE_CONNECTION: redis
120+
121+
beanstalkd:
122+
runs-on: ubuntu-22.04
123+
124+
name: Beanstalkd Driver
125+
126+
steps:
127+
- name: Checkout code
128+
uses: actions/checkout@v4
129+
with:
130+
fetch-depth: 0
131+
132+
- uses: actions/checkout@v3
133+
- name: Download & Extract beanstalkd
134+
run: curl -L https://github.com/beanstalkd/beanstalkd/archive/refs/tags/v1.13.tar.gz | tar xz
135+
- name: Make beanstalkd
136+
run: make
137+
working-directory: beanstalkd-1.13
138+
139+
- name: Setup PHP
140+
uses: shivammathur/setup-php@v2
141+
with:
142+
php-version: 8.1
143+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
144+
tools: composer:v2
145+
coverage: none
146+
147+
- name: Install dependencies
148+
uses: nick-fields/retry@v2
149+
with:
150+
timeout_minutes: 5
151+
max_attempts: 5
152+
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
153+
154+
- name: Daemonize beanstalkd
155+
run: ./beanstalkd-1.13/beanstalkd &
156+
157+
- name: Execute tests
158+
run: vendor/bin/phpunit tests/Integration/Queue
159+
env:
160+
QUEUE_CONNECTION: beanstalkd

src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait InteractsWithRedis
1919
/**
2020
* Redis manager instance.
2121
*
22-
* @var \Illuminate\Redis\RedisManager[]
22+
* @var array<string, \Illuminate\Redis\RedisManager>
2323
*/
2424
private $redis;
2525

tests/Integration/Queue/CallQueuedHandlerTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515

1616
class CallQueuedHandlerTest extends TestCase
1717
{
18-
protected function tearDown(): void
19-
{
20-
parent::tearDown();
21-
22-
m::close();
23-
}
24-
2518
public function testJobCanBeDispatched()
2619
{
2720
CallQueuedHandlerTestJob::$handled = false;

tests/Integration/Queue/CustomPayloadTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Queue\Queue;
99
use Illuminate\Support\ServiceProvider;
1010
use Orchestra\Testbench\Concerns\CreatesApplication;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112

1213
class CustomPayloadTest extends TestCase
1314
{
@@ -25,9 +26,7 @@ public static function websites()
2526
yield ['blog.laravel.com'];
2627
}
2728

28-
/**
29-
* @dataProvider websites
30-
*/
29+
#[DataProvider('websites')]
3130
public function test_custom_payload_gets_cleared_for_each_data_provider(string $websites)
3231
{
3332
$dispatcher = $this->app->make(QueueingDispatcher::class);

tests/Integration/Queue/DynamoBatchTest.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Contracts\Queue\ShouldQueue;
99
use Illuminate\Foundation\Bus\Dispatchable;
1010
use Illuminate\Queue\InteractsWithQueue;
11+
use Illuminate\Support\Env;
1112
use Illuminate\Support\Facades\Bus;
1213
use Illuminate\Support\Str;
1314
use Orchestra\Testbench\TestCase;
@@ -17,34 +18,35 @@
1718
*/
1819
class DynamoBatchTest extends TestCase
1920
{
20-
const DYNAMODB_ENDPOINT = 'http://localhost:8888';
21+
public function setUp(): void
22+
{
23+
$this->afterApplicationCreated(function () {
24+
BatchRunRecorder::reset();
25+
app(DynamoBatchRepository::class)->createAwsDynamoTable();
26+
});
27+
28+
$this->beforeApplicationDestroyed(function () {
29+
app(DynamoBatchRepository::class)->deleteAwsDynamoTable();
30+
});
2131

22-
protected function getEnvironmentSetUp($app)
32+
parent::setUp();
33+
}
34+
35+
protected function defineEnvironment($app)
2336
{
37+
if (is_null($endpoint = Env::get('DYNAMODB_ENDPOINT'))) {
38+
$this->markTestSkipped('Require `dynamodb` to be configured');
39+
}
40+
2441
$app['config']->set('queue.batching', [
2542
'driver' => 'dynamodb',
2643
'region' => 'us-west-2',
27-
'endpoint' => static::DYNAMODB_ENDPOINT,
44+
'endpoint' => $endpoint,
2845
'key' => 'key',
2946
'secret' => 'secret',
3047
]);
3148
}
3249

33-
public function setUp(): void
34-
{
35-
parent::setUp();
36-
37-
BatchRunRecorder::reset();
38-
app(DynamoBatchRepository::class)->createAwsDynamoTable();
39-
}
40-
41-
public function tearDown(): void
42-
{
43-
app(DynamoBatchRepository::class)->deleteAwsDynamoTable();
44-
45-
parent::tearDown();
46-
}
47-
4850
public function test_running_a_batch()
4951
{
5052
Bus::batch([

tests/Integration/Queue/DynamoBatchTestWithTTL.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
namespace Illuminate\Tests\Integration\Queue;
44

5+
use Illuminate\Support\Env;
6+
57
class DynamoBatchTestWithTTL extends DynamoBatchTest
68
{
7-
protected function getEnvironmentSetUp($app)
9+
protected function defineEnvironment($app)
810
{
11+
if (is_null($endpoint = Env::get('DYNAMODB_ENDPOINT'))) {
12+
$this->markTestSkipped('Require `dynamodb` to be configured');
13+
}
14+
915
$app['config']->set('queue.batching', [
1016
'driver' => 'dynamodb',
1117
'region' => 'us-west-2',
12-
'endpoint' => static::DYNAMODB_ENDPOINT,
18+
'endpoint' => $endpoint,
1319
'key' => 'key',
1420
'secret' => 'secret',
1521
'ttl' => 1,

0 commit comments

Comments
 (0)