CaiWuXiTong/tests/Unit/Deployment/ProductionBuildCachePolicyTest.php

49 lines
2.2 KiB
PHP

<?php
namespace Tests\Unit\Deployment;
use Tests\TestCase;
class ProductionBuildCachePolicyTest extends TestCase
{
public function testReleaseExcludesLocalBootstrapCachesAndBootsBeforeProductionAccess(): void
{
$ignore = file_get_contents(base_path('.dockerignore'));
$this->assertContains('bootstrap/cache/*', preg_split('/\R/', $ignore));
$script = file_get_contents(base_path('scripts/deploy-from-workstation.ps1'));
$smoke = strpos($script, 'docker run --rm --network none --user www-data --entrypoint php $fullImage artisan --version');
$remote = strpos($script, '$previousShaOutput =');
$this->assertNotFalse($smoke);
$this->assertLessThan($remote, $smoke);
}
public function testProductionDockerfilePinsBaseImagesAndRetriesExternalDownloads(): void
{
$dockerfile = file_get_contents(base_path('deploy/Dockerfile'));
$this->assertStringContainsString(
'FROM php:8.3-apache-bookworm@sha256:fa8852a2e01747ffe8c8768bfd6bbc2f296f974aa0de90ee157a66664996d263 AS php-base',
$dockerfile,
);
$this->assertStringContainsString(
'FROM composer:2.8@sha256:5248900ab8b5f7f880c2d62180e40960cd87f60149ec9a1abfd62ac72a02577c AS composer-bin',
$dockerfile,
);
$this->assertStringContainsString('Acquire::Retries=3', $dockerfile);
$this->assertStringContainsString('COMPOSER_MAX_PARALLEL_HTTP=4', $dockerfile);
$this->assertStringContainsString('if [ "$attempt" -ge 3 ]', $dockerfile);
}
public function testWorkstationDeploymentRetainsReusableBuildLayers(): void
{
$script = file_get_contents(base_path('scripts/deploy-from-workstation.ps1'));
$this->assertStringContainsString("[string]\$BuildCacheMaxUsedSpace = '24GB'", $script);
$this->assertStringContainsString('[int]$BuildCacheMaxAgeHours = 720', $script);
$this->assertStringContainsString('--max-used-space $BuildCacheMaxUsedSpace', $script);
$this->assertStringContainsString('--keep-storage $BuildCacheMaxUsedSpace', $script);
$this->assertStringNotContainsString('--max-used-space 3GB', $script);
$this->assertStringNotContainsString('--keep-storage 3GB', $script);
}
}