Core MVC, HTTP client, Session, Cookie, Config, HTTPException — 111 PHPUnit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use System\Classes\Config;
|
|
|
|
class ConfigTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
// Сбрасываем загруженный конфиг через рефлексию
|
|
$ref = new \ReflectionClass(Config::class);
|
|
$prop = $ref->getProperty('config');
|
|
$prop->setAccessible(true);
|
|
$prop->setValue(null, null);
|
|
}
|
|
|
|
public function testGetSectionReturnsArray(): void
|
|
{
|
|
$db = Config::get('db');
|
|
$this->assertIsArray($db);
|
|
$this->assertArrayHasKey('default', $db);
|
|
}
|
|
|
|
public function testGetGroupReturnsValue(): void
|
|
{
|
|
$params = Config::get('session', 'cookie_params');
|
|
$this->assertIsArray($params);
|
|
$this->assertArrayHasKey('lifetime', $params);
|
|
}
|
|
|
|
public function testGetMissingKeyReturnsNull(): void
|
|
{
|
|
$this->assertNull(Config::get('nonexistent'));
|
|
$this->assertNull(Config::get('nonexistent', 'group'));
|
|
}
|
|
|
|
public function testSetOverridesValue(): void
|
|
{
|
|
Config::set('foo', ['bar' => 'baz']);
|
|
$this->assertSame(['bar' => 'baz'], Config::get('foo'));
|
|
}
|
|
|
|
public function testMergeDeep(): void
|
|
{
|
|
$base = ['a' => ['x' => 1, 'y' => 2], 'b' => 3];
|
|
$override = ['a' => ['y' => 99, 'z' => 4], 'b' => 10];
|
|
$result = Config::merge($base, $override);
|
|
|
|
$this->assertSame(1, $result['a']['x']);
|
|
$this->assertSame(99, $result['a']['y']);
|
|
$this->assertSame(4, $result['a']['z']);
|
|
$this->assertSame(10, $result['b']);
|
|
}
|
|
}
|