Files
coolify/tests/Unit/DockerComposeImagePullOrderTest.php
T
Andras Bacsai 1f4006ac49 test: remove tests that do not exercise app code
Remove tests that copy app logic into the test, grep PHP source as
text, only check literals, constants, class_exists or PHP built-ins,
duplicate other tests, or are always skipped. Keep source checks that
guard security and authorization rules.

Rename a duplicate Pest helper so the full suite loads, drop the
missing v5/Browser path, and remove the CLAUDE.md symlink in favor of
AGENTS.md. Correct AGENTS.md: Dusk is not installed and the upgrade
script is scripts/upgrade.sh.
2026-09-28 11:55:56 +02:00

85 lines
2.9 KiB
PHP

<?php
use App\Jobs\ApplicationDeploymentJob;
use App\Models\Application;
use App\Models\ApplicationDeploymentQueue;
use App\Models\Server;
class TestableDockerComposeImagePullDeploymentJob extends ApplicationDeploymentJob
{
public array $recordedCommands = [];
public array $commandServers = [];
public bool $failCommands = false;
public function __construct() {}
public function execute_remote_command(...$commands): void
{
$reflection = new ReflectionClass(ApplicationDeploymentJob::class);
$this->commandServers[] = $reflection->getProperty('server')->getValue($this);
$this->recordedCommands[] = $commands;
if ($this->failCommands) {
throw new RuntimeException('Image pull failed.');
}
}
}
function makeDockerComposeImagePullJob(bool $useBuildServer = false): array
{
$job = new TestableDockerComposeImagePullDeploymentJob;
$reflection = new ReflectionClass(ApplicationDeploymentJob::class);
$application = Mockery::mock(Application::class)->makePartial();
$application->uuid = 'application-uuid';
$application->shouldReceive('workdir')->andReturn('/runtime/application');
$queue = Mockery::mock(ApplicationDeploymentQueue::class)->makePartial();
$queue->shouldReceive('addLogEntry')->once()->andReturnNull();
$buildServer = new Server;
$buildServer->id = 1;
$mainServer = new Server;
$mainServer->id = 2;
foreach ([
'application' => $application,
'application_deployment_queue' => $queue,
'server' => $buildServer,
'build_server' => $buildServer,
'mainServer' => $mainServer,
'use_build_server' => $useBuildServer,
'workdir' => '/artifacts/application',
'deployment_uuid' => 'deployment-uuid',
'docker_compose_location' => '/docker-compose.yaml',
'coolify_variables' => '',
] as $property => $value) {
$reflection->getProperty($property)->setValue($job, $value);
}
return [$job, $reflection, $buildServer, $mainServer];
}
it('aborts the deployment when pulling a compose image fails', function () {
[$job, $reflection] = makeDockerComposeImagePullJob();
$job->failCommands = true;
$reflection->getMethod('pull_docker_compose_images')->invoke($job);
})->throws(RuntimeException::class, 'Image pull failed.');
it('pulls compose images on the runtime server when using a build server', function () {
[$job, $reflection, $buildServer, $mainServer] = makeDockerComposeImagePullJob(useBuildServer: true);
$reflection->getMethod('pull_docker_compose_images')->invoke($job);
$command = $job->recordedCommands[0][0][0];
expect($job->commandServers)->toHaveCount(1)
->and($job->commandServers[0])->toBe($mainServer)
->and($job->commandServers[0])->not->toBe($buildServer)
->and($command)->toContain('pull --ignore-buildable')
->and($command)->toContain('--env-file /runtime/application/.env');
});