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,81 @@
<?php
declare(strict_types=1);
namespace MageSail\Magesail\Test\Unit\Model;
use MageSail\Magesail\Model\TunnelStoreState;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Serialize\Serializer\Json;
use PHPUnit\Framework\TestCase;
class TunnelStoreStateTest extends TestCase
{
private string $tmpDir = '';
protected function setUp(): void
{
parent::setUp();
$this->tmpDir = sys_get_temp_dir() . '/magesail_tss_' . uniqid('', true);
mkdir($this->tmpDir, 0777, true);
}
protected function tearDown(): void
{
$file = $this->tmpDir . '/magesail_tunnel_store.json';
if (is_file($file)) {
@unlink($file);
}
@rmdir($this->tmpDir);
parent::tearDown();
}
public function testReadWriteRoundTrip(): void
{
$dir = new DirectoryList();
$dir->setTestPath(DirectoryList::VAR_DIR, $this->tmpDir);
$json = new Json();
$state = new TunnelStoreState($dir, $json);
$payload = [
'store_id' => 5,
'store_code' => 'mgtun_x',
'unsecure_base_url' => 'http://a.test/',
'secure_base_url' => '',
'use_secure_urls' => true,
'nginx_pending_reload' => false,
];
$state->write($payload);
$read = $state->read();
self::assertNotNull($read);
self::assertSame(5, $read['store_id']);
self::assertSame('mgtun_x', $read['store_code']);
self::assertSame('http://a.test/', $read['unsecure_base_url']);
self::assertTrue($read['use_secure_urls']);
}
public function testReadReturnsNullWhenFileMissing(): void
{
$dir = new DirectoryList();
$dir->setTestPath(DirectoryList::VAR_DIR, $this->tmpDir);
$json = new Json();
$state = new TunnelStoreState($dir, $json);
self::assertNull($state->read());
}
public function testDeleteRemovesFile(): void
{
$dir = new DirectoryList();
$dir->setTestPath(DirectoryList::VAR_DIR, $this->tmpDir);
$json = new Json();
$state = new TunnelStoreState($dir, $json);
$state->write([
'store_id' => 1,
'store_code' => 'x',
'unsecure_base_url' => '',
'secure_base_url' => '',
'use_secure_urls' => false,
]);
$state->delete();
self::assertNull($state->read());
}
}