2025-12-03 09:29:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\Unit\Jobs;
|
|
|
|
|
|
|
|
|
|
use App\Jobs\RestartProxyJob;
|
|
|
|
|
use App\Models\Server;
|
|
|
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
|
|
|
use Mockery;
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
2025-12-03 15:18:13 +00:00
|
|
|
/**
|
|
|
|
|
* Unit tests for RestartProxyJob.
|
|
|
|
|
*
|
|
|
|
|
* These tests focus on testing the job's middleware configuration and constructor.
|
|
|
|
|
* Full integration tests for the job's handle() method are in tests/Feature/Proxy/
|
|
|
|
|
* because they require database and complex mocking of SchemalessAttributes.
|
|
|
|
|
*/
|
2025-12-03 09:29:39 +00:00
|
|
|
class RestartProxyJobTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
protected function tearDown(): void
|
|
|
|
|
{
|
|
|
|
|
Mockery::close();
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_job_has_without_overlapping_middleware()
|
|
|
|
|
{
|
|
|
|
|
$server = Mockery::mock(Server::class);
|
2025-12-03 15:18:13 +00:00
|
|
|
$server->shouldReceive('getSchemalessAttributes')->andReturn([]);
|
|
|
|
|
$server->shouldReceive('getAttribute')->with('uuid')->andReturn('test-uuid');
|
2025-12-03 09:29:39 +00:00
|
|
|
|
|
|
|
|
$job = new RestartProxyJob($server);
|
|
|
|
|
$middleware = $job->middleware();
|
|
|
|
|
|
|
|
|
|
$this->assertCount(1, $middleware);
|
|
|
|
|
$this->assertInstanceOf(WithoutOverlapping::class, $middleware[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 15:18:13 +00:00
|
|
|
public function test_job_has_correct_configuration()
|
2025-12-03 09:29:39 +00:00
|
|
|
{
|
|
|
|
|
$server = Mockery::mock(Server::class);
|
|
|
|
|
|
2025-12-03 15:09:47 +00:00
|
|
|
$job = new RestartProxyJob($server);
|
|
|
|
|
|
2025-12-03 15:18:13 +00:00
|
|
|
$this->assertEquals(1, $job->tries);
|
2025-12-03 15:21:26 +00:00
|
|
|
$this->assertEquals(120, $job->timeout);
|
2025-12-03 15:18:13 +00:00
|
|
|
$this->assertNull($job->activity_id);
|
2025-12-03 15:09:47 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-03 15:18:13 +00:00
|
|
|
public function test_job_stores_server()
|
2025-12-03 15:09:47 +00:00
|
|
|
{
|
|
|
|
|
$server = Mockery::mock(Server::class);
|
|
|
|
|
|
2025-12-03 09:29:39 +00:00
|
|
|
$job = new RestartProxyJob($server);
|
|
|
|
|
|
2025-12-03 15:18:13 +00:00
|
|
|
$this->assertSame($server, $job->server);
|
2025-12-03 09:29:39 +00:00
|
|
|
}
|
|
|
|
|
}
|