Skip to content

Commit 97eccbd

Browse files
authored
Test Improvements (#1511)
* 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]>
1 parent ff182b3 commit 97eccbd

File tree

5 files changed

+18
-51
lines changed

5 files changed

+18
-51
lines changed

.github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- master
7+
- 'test-improvements'
78
- '*.x'
89
pull_request:
910
schedule:
@@ -56,8 +57,7 @@ jobs:
5657

5758
- name: Install dependencies
5859
run: |
59-
composer require "illuminate/contracts=^${{ matrix.laravel }}" --dev --no-update
60-
composer update --prefer-dist --no-interaction --no-progress
60+
composer update --prefer-dist --no-interaction --no-progress --with="illuminate/contracts:^${{ matrix.laravel }}"
6161
6262
- name: Execute tests
6363
run: vendor/bin/phpunit

tests/Feature/Listeners/MarkJobAsCompleteTest.php

+2-16
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,11 @@
1111
use Laravel\Horizon\Listeners\MarkJobAsComplete;
1212
use Laravel\Horizon\Tests\IntegrationTest;
1313
use Mockery as m;
14+
use Orchestra\Testbench\Attributes\WithConfig;
1415

16+
#[WithConfig('horizon.silenced', ['App\\Jobs\\ConfigJob'])]
1517
class MarkJobAsCompleteTest extends IntegrationTest
1618
{
17-
protected function tearDown(): void
18-
{
19-
parent::tearDown();
20-
21-
m::close();
22-
}
23-
24-
protected function getEnvironmentSetUp($app): void
25-
{
26-
parent::getEnvironmentSetUp($app);
27-
28-
$app['config']->set('horizon.silenced', [
29-
'App\\Jobs\\ConfigJob',
30-
]);
31-
}
32-
3319
public function test_it_can_mark_a_job_as_complete(): void
3420
{
3521
$this->runScenario('App\\Jobs\\TestJob', false);

tests/Feature/SupervisorTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected function tearDown(): void
4949
parent::tearDown();
5050
}
5151

52+
/** @requires extension redis */
5253
public function test_supervisor_can_start_worker_process_with_given_options()
5354
{
5455
Queue::push(new Jobs\BasicJob);
@@ -260,6 +261,7 @@ public function test_supervisor_can_restart_processes()
260261
$this->assertNotEquals($pid, $supervisor->processes()[0]->getPid());
261262
}
262263

264+
/** @requires extension redis */
263265
public function test_processes_can_be_paused_and_continued()
264266
{
265267
$options = $this->supervisorOptions();

tests/IntegrationTest.php

+10-16
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,18 @@ abstract class IntegrationTest extends TestCase
2020
*/
2121
protected function setUp(): void
2222
{
23-
parent::setUp();
24-
25-
Redis::flushall();
26-
}
23+
$this->afterApplicationCreated(function () {
24+
Redis::flushall();
25+
});
2726

28-
/**
29-
* Tear down the test case.
30-
*
31-
* @return void
32-
*/
33-
protected function tearDown(): void
34-
{
35-
parent::tearDown();
27+
$this->beforeApplicationDestroyed(function () {
28+
Redis::flushall();
29+
WorkerCommandString::reset();
30+
SupervisorCommandString::reset();
31+
Horizon::$authUsing = null;
32+
});
3633

37-
Redis::flushall();
38-
WorkerCommandString::reset();
39-
SupervisorCommandString::reset();
40-
Horizon::$authUsing = null;
34+
parent::setUp();
4135
}
4236

4337
/**

tests/worker.php

+2-17
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,11 @@
77
use Illuminate\Queue\QueueManager;
88
use Illuminate\Queue\Worker;
99
use Illuminate\Queue\WorkerOptions;
10-
use Orchestra\Testbench\Concerns\CreatesApplication;
1110

12-
$appLoader = new class
13-
{
14-
use CreatesApplication;
15-
16-
/**
17-
* Define environment setup.
18-
*
19-
* @param \Illuminate\Foundation\Application $app
20-
* @return void
21-
*/
22-
protected function getEnvironmentSetUp($app)
23-
{
24-
// Define your environment setup.
25-
}
26-
};
11+
use function Orchestra\Testbench\container;
2712

2813
// Configure the application...
29-
$app = $appLoader->createApplication();
14+
$app = container()->createApplication();
3015
$app->register(Laravel\Horizon\HorizonServiceProvider::class);
3116
$app->make('config')->set('queue.default', 'redis');
3217

0 commit comments

Comments
 (0)