CaiWuXiTong/tests/Unit/Deployment/WebProcessOwnershipTest.php
chenxi 26556a9169 Add warehouse short names to inventory report
Restore warehouse name mapping ledger and inventory short-name column.
2026-09-28 16:33:38 +08:00

77 lines
2.9 KiB
PHP

<?php
namespace Tests\Unit\Deployment;
use Tests\TestCase;
class WebProcessOwnershipTest extends TestCase
{
public function test_container_entrypoint_runs_laravel_maintenance_as_web_user(): void
{
$entrypoint = file_get_contents(base_path('deploy/entrypoint.sh'));
$this->assertIsString($entrypoint);
$this->assertStringContainsString(
'runuser -u www-data -- php artisan "$@"',
$entrypoint
);
$this->assertStringContainsString(
'run_artisan_as_web local-bootstrap:update --no-ansi',
$entrypoint
);
$this->assertStringContainsString('assert_web_writable', $entrypoint);
$this->assertDoesNotMatchRegularExpression('/^\s*php artisan /m', $entrypoint);
}
public function test_local_worker_healthcheck_and_initialization_use_web_user(): void
{
$compose = file_get_contents(base_path('docker-compose.local.yml'));
$initializer = file_get_contents(base_path('deploy/local-init.sh'));
$this->assertIsString($compose);
$this->assertStringContainsString(
'test: ["CMD", "jiangling-healthcheck"]',
$compose
);
$this->assertStringNotContainsString('snapshot_worker:', $compose);
$this->assertIsString($initializer);
$this->assertStringContainsString(
'exec -T -u www-data app',
$initializer
);
$this->assertStringContainsString(
'php artisan local-bootstrap:update --no-ansi',
$initializer
);
$this->assertStringContainsString('docker rm -f jiangling_snapshot_worker', $initializer);
$this->assertDoesNotMatchRegularExpression(
'/exec -T app\s+(?:\\\\\s*)?php artisan/',
$initializer
);
}
public function test_local_entrypoint_does_not_build_persistent_laravel_caches(): void
{
$entrypoint = file_get_contents(base_path('deploy/entrypoint.sh'));
$this->assertIsString($entrypoint);
$this->assertStringContainsString('if [ "$app_environment" = "local" ]; then', $entrypoint);
$this->assertStringContainsString('run_artisan_as_web optimize:clear', $entrypoint);
$this->assertStringContainsString('run_artisan_as_web config:cache', $entrypoint);
$this->assertStringContainsString('run_artisan_as_web view:cache', $entrypoint);
}
public function test_local_php_and_view_caches_are_disabled(): void
{
$php = file_get_contents(base_path('deploy/php-local.ini'));
$view = file_get_contents(base_path('config/view.php'));
$this->assertIsString($php);
$this->assertStringContainsString('opcache.enable=0', $php);
$this->assertStringContainsString('opcache.enable_cli=0', $php);
$this->assertStringContainsString("'cache' => env('APP_ENV', 'production') === 'local'", $view);
$this->assertStringContainsString("? false", $view);
}
}