CI / php (push) Successful in 2m53s
- Add EnvServicePortResolver (DeploymentConfig) for MySQL, Redis frontends, session Redis, AMQP, http_cache_hosts, optional search - Extend tunnel registry with tunnel_type, service_key, service metadata; provisionServiceTunnel without store/NGINX map; teardown guards - Admin: Type (Website|Service), service dropdown, list Type column; JS toggle - TunnelManager/start-server: forward to resolved host:port - Tests: EnvServicePortResolver + service teardown; test stubs for Magento/PSR - docs: admin-ui Type/Service and security notes
106 lines
3.3 KiB
PHP
106 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MageSail\Magesail\Test\Unit\Model;
|
|
|
|
use Magento\Framework\App\DeploymentConfig;
|
|
use MageSail\Magesail\Model\EnvServicePortResolver;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class EnvServicePortResolverTest extends TestCase
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $flat
|
|
*/
|
|
private function resolverWithFlatConfig(array $flat): EnvServicePortResolver
|
|
{
|
|
$config = new DeploymentConfig();
|
|
foreach ($flat as $k => $v) {
|
|
$config->setTestValue($k, $v);
|
|
}
|
|
|
|
return new EnvServicePortResolver($config);
|
|
}
|
|
|
|
public function testMysqlDefaultPortWhenOmitted(): void
|
|
{
|
|
$r = $this->resolverWithFlatConfig([
|
|
'db/connection/default' => [
|
|
'host' => '127.0.0.1',
|
|
'active' => '1',
|
|
],
|
|
]);
|
|
$resolved = $r->resolveService('mysql_default');
|
|
$this->assertNotNull($resolved);
|
|
$this->assertSame('127.0.0.1', $resolved['host']);
|
|
$this->assertSame(3306, $resolved['port']);
|
|
}
|
|
|
|
public function testDiscoversRedisCacheFrontendsAndSession(): void
|
|
{
|
|
$r = $this->resolverWithFlatConfig([
|
|
'db/connection/default' => ['host' => '127.0.0.1'],
|
|
'cache' => [
|
|
'frontend' => [
|
|
'default' => [
|
|
'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
|
|
'backend_options' => [
|
|
'server' => '127.0.0.1',
|
|
'port' => '6380',
|
|
],
|
|
],
|
|
'page_cache' => [
|
|
'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
|
|
'backend_options' => [
|
|
'server' => '127.0.0.1',
|
|
'port' => '6381',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
'session' => [
|
|
'save' => 'redis',
|
|
'redis' => [
|
|
'host' => '127.0.0.1',
|
|
'port' => '6379',
|
|
],
|
|
],
|
|
]);
|
|
$this->assertNotNull($r->resolveService('mysql_default'));
|
|
$keys = [];
|
|
foreach ($r->getDiscoveredServices() as $s) {
|
|
$keys[] = $s['service_key'];
|
|
}
|
|
$this->assertContains('cache_frontend_default', $keys);
|
|
$this->assertContains('cache_frontend_page_cache', $keys);
|
|
$this->assertContains('session_redis', $keys);
|
|
}
|
|
|
|
public function testAmqpAndHttpCacheHosts(): void
|
|
{
|
|
$r = $this->resolverWithFlatConfig([
|
|
'db/connection/default' => ['host' => '127.0.0.1'],
|
|
'queue' => [
|
|
'amqp' => [
|
|
'host' => '127.0.0.1',
|
|
'port' => '5672',
|
|
],
|
|
],
|
|
'http_cache_hosts' => [
|
|
['host' => '127.0.0.1', 'port' => '80'],
|
|
],
|
|
]);
|
|
$this->assertNotNull($r->resolveService('queue_amqp'));
|
|
$this->assertNotNull($r->resolveService('http_cache_0'));
|
|
}
|
|
|
|
public function testResolveUnknownKeyReturnsNull(): void
|
|
{
|
|
$r = $this->resolverWithFlatConfig([
|
|
'db/connection/default' => ['host' => '127.0.0.1'],
|
|
]);
|
|
$this->assertNull($r->resolveService('does_not_exist'));
|
|
}
|
|
}
|