Update additional PP

This commit is contained in:
DariusIII
2026-07-12 16:30:39 +02:00
parent 1e6c6f5193
commit 645eba20e2
17 changed files with 1748 additions and 140 deletions
+31 -4
View File
@@ -3,12 +3,13 @@
namespace Tests\Unit;
use App\Services\TempWorkspaceService;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\File;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
use PHPUnit\Framework\TestCase;
use RuntimeException;
class TempWorkspaceServiceTest extends TestCase
{
@@ -20,9 +21,9 @@ class TempWorkspaceServiceTest extends TestCase
{
parent::setUp();
// Minimal Facade container for File facade
$container = new Container;
$container->instance('files', new Filesystem);
Facade::setFacadeApplication($container);
$app = new Application(dirname(__DIR__, 2));
$app->instance('files', new Filesystem);
Facade::setFacadeApplication($app);
$this->svc = new TempWorkspaceService;
// Unique base path under system temp
@@ -56,6 +57,32 @@ class TempWorkspaceServiceTest extends TestCase
$this->assertStringEndsWith('/group42/guid-123/', str_replace('\\', '/', $tmp));
}
#[WithoutErrorHandler]
public function test_ensure_main_temp_path_repairs_existing_unwritable_bucket_directory(): void
{
$bucket = $this->base.DIRECTORY_SEPARATOR.'a';
File::makeDirectory($bucket, 0555, true, true);
chmod($bucket, 0555);
$resolved = $this->svc->ensureMainTempPath($this->base, 'a', '');
$this->assertTrue(File::isDirectory($resolved));
$this->assertTrue(is_writable($resolved));
}
#[WithoutErrorHandler]
public function test_ensure_main_temp_path_reports_path_when_base_cannot_be_created(): void
{
$fileBase = $this->base.DIRECTORY_SEPARATOR.'not-a-directory';
File::put($fileBase, 'x');
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Additional post-processing temp path');
$this->expectExceptionMessage('not-a-directory');
$this->svc->ensureMainTempPath($fileBase, 'a', '');
}
#[WithoutErrorHandler]
public function test_list_files_with_and_without_pattern(): void
{
+50
View File
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace Tests\Unit;
use App\Services\Tmux\TmuxMonitorService;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;
class TmuxMonitorServiceTest extends TestCase
{
public function test_calculate_statistics_backfills_missing_work_count_defaults(): void
{
$reflection = new ReflectionClass(TmuxMonitorService::class);
/** @var TmuxMonitorService $monitor */
$monitor = $reflection->newInstanceWithoutConstructor();
$runVar = [
'counts' => [
'now' => [
'processnfo' => 2,
'tv' => 1,
],
'start' => [],
'diff' => [],
'percent' => [],
],
];
$runVarProperty = new ReflectionProperty(TmuxMonitorService::class, 'runVar');
$runVarProperty->setValue($monitor, $runVar);
$iterationsProperty = new ReflectionProperty(TmuxMonitorService::class, 'iterations');
$iterationsProperty->setValue($monitor, 1);
$calculate = new ReflectionMethod(TmuxMonitorService::class, 'calculateStatistics');
$calculate->invoke($monitor);
$updatedRunVar = $runVarProperty->getValue($monitor);
$this->assertSame(0, $updatedRunVar['counts']['now']['work']);
$this->assertSame(0, $updatedRunVar['counts']['now']['work_available']);
$this->assertSame('0', $updatedRunVar['counts']['diff']['work']);
$this->assertSame('0', $updatedRunVar['counts']['diff']['work_available']);
$this->assertSame(2, $updatedRunVar['counts']['now']['total_work']);
}
}