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

Test Improvements #1511

Merged
merged 7 commits into from
Oct 29, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- 'test-improvements'
- '*.x'
pull_request:
schedule:
Expand Down Expand Up @@ -56,8 +57,7 @@ jobs:

- name: Install dependencies
run: |
composer require "illuminate/contracts=^${{ matrix.laravel }}" --dev --no-update
composer update --prefer-dist --no-interaction --no-progress
composer update --prefer-dist --no-interaction --no-progress --with="illuminate/contracts:^${{ matrix.laravel }}"

- name: Execute tests
run: vendor/bin/phpunit
18 changes: 2 additions & 16 deletions tests/Feature/Listeners/MarkJobAsCompleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,11 @@
use Laravel\Horizon\Listeners\MarkJobAsComplete;
use Laravel\Horizon\Tests\IntegrationTest;
use Mockery as m;
use Orchestra\Testbench\Attributes\WithConfig;

#[WithConfig('horizon.silenced', ['App\\Jobs\\ConfigJob'])]
class MarkJobAsCompleteTest extends IntegrationTest
{
protected function tearDown(): void
{
parent::tearDown();

m::close();
}

protected function getEnvironmentSetUp($app): void
{
parent::getEnvironmentSetUp($app);

$app['config']->set('horizon.silenced', [
'App\\Jobs\\ConfigJob',
]);
}

public function test_it_can_mark_a_job_as_complete(): void
{
$this->runScenario('App\\Jobs\\TestJob', false);
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/SupervisorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected function tearDown(): void
parent::tearDown();
}

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

/** @requires extension redis */
public function test_processes_can_be_paused_and_continued()
{
$options = $this->supervisorOptions();
Expand Down
26 changes: 10 additions & 16 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,18 @@ abstract class IntegrationTest extends TestCase
*/
protected function setUp(): void
{
parent::setUp();

Redis::flushall();
}
$this->afterApplicationCreated(function () {
Redis::flushall();
});

/**
* Tear down the test case.
*
* @return void
*/
protected function tearDown(): void
{
parent::tearDown();
$this->beforeApplicationDestroyed(function () {
Redis::flushall();
WorkerCommandString::reset();
SupervisorCommandString::reset();
Horizon::$authUsing = null;
});

Redis::flushall();
WorkerCommandString::reset();
SupervisorCommandString::reset();
Horizon::$authUsing = null;
parent::setUp();
}

/**
Expand Down
19 changes: 2 additions & 17 deletions tests/worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,11 @@
use Illuminate\Queue\QueueManager;
use Illuminate\Queue\Worker;
use Illuminate\Queue\WorkerOptions;
use Orchestra\Testbench\Concerns\CreatesApplication;

$appLoader = new class
{
use CreatesApplication;

/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
{
// Define your environment setup.
}
};
use function Orchestra\Testbench\container;

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

Expand Down