tests
CI / php (push) Successful in 2m56s

This commit is contained in:
2026-03-21 03:49:54 -05:00
parent d543c3bb0e
commit bbd83659a7
29 changed files with 1090 additions and 38 deletions
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace MageSail\Magesail\Test\Unit\Model;
use MageSail\Magesail\Model\TunnelProcessPaths;
use Magento\Framework\App\Filesystem\DirectoryList;
use PHPUnit\Framework\TestCase;
class TunnelProcessPathsTest extends TestCase
{
public function testPidPathUsesVarTunnelDirAndSanitizedId(): void
{
$dir = new DirectoryList();
$dir->setTestPath(DirectoryList::VAR_DIR, '/var/magento/var');
$dir->setTestPath(DirectoryList::LOG, '/var/magento/var/log');
$paths = new TunnelProcessPaths($dir);
self::assertSame(
'/var/magento/var/magesail_tunnels/tunnel1.pid',
$paths->getPidFilePath('tunnel1')
);
}
public function testSanitizeIdStripsUnsafeCharacters(): void
{
$dir = new DirectoryList();
$dir->setTestPath(DirectoryList::VAR_DIR, '/v');
$dir->setTestPath(DirectoryList::LOG, '/v/log');
$paths = new TunnelProcessPaths($dir);
self::assertStringContainsString(
'/magesail_tunnels/ab.pid',
$paths->getPidFilePath('a!@#b')
);
}
public function testSanitizeIdFallsBackToInvalidWhenEmpty(): void
{
$dir = new DirectoryList();
$dir->setTestPath(DirectoryList::VAR_DIR, '/v');
$dir->setTestPath(DirectoryList::LOG, '/v/log');
$paths = new TunnelProcessPaths($dir);
self::assertStringEndsWith(
'/magesail_tunnels/invalid.pid',
$paths->getPidFilePath('!!!')
);
}
public function testLegacyPaths(): void
{
$dir = new DirectoryList();
$dir->setTestPath(DirectoryList::VAR_DIR, '/v');
$dir->setTestPath(DirectoryList::LOG, '/v/log');
$paths = new TunnelProcessPaths($dir);
self::assertSame('/v/magesail.pid', $paths->getLegacyPidFilePath());
self::assertSame('/v/magesail.key', $paths->getLegacyKeyFilePath());
self::assertSame('/v/log/magesail_tunnel.log', $paths->getLegacyLogFilePath());
}
}