mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-16 09:34:39 +00:00
mvc-unittests : remove Phalcon\Di\FactoryDefault usage and support partial app config updates in AppConfig to support different config files in the unit tests.
for https://github.com/opnsense/core/issues/6389
This commit is contained in:
parent
cbc01cb39c
commit
100aac2fb8
@ -73,4 +73,25 @@ class AppConfig
|
||||
// simple conversion from array to StdClass container, current representation of self::$data.
|
||||
self::$obj = json_decode(json_encode(self::$data));
|
||||
}
|
||||
|
||||
/**
|
||||
* update a property inside the container
|
||||
* @param string $path in dot notation a.b.c
|
||||
* @param mixed $value
|
||||
* @return bool true when found and updated
|
||||
*/
|
||||
public function update($path, $value)
|
||||
{
|
||||
$tmp = &self::$data;
|
||||
foreach (explode('.', $path) as $key) {
|
||||
if (isset($tmp[$key])) {
|
||||
$tmp = &$tmp[$key];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$tmp = $value;
|
||||
self::$obj = json_decode(json_encode(self::$data));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
|
||||
// @CodingStandardsIgnoreEnd
|
||||
|
||||
use OPNsense\Base\FieldTypes\AuthGroupField;
|
||||
use Phalcon\Di\FactoryDefault;
|
||||
use OPNsense\Core\AppConfig;
|
||||
use OPNsense\Core\Config;
|
||||
|
||||
class AuthGroupFieldTest extends Field_Framework_TestCase
|
||||
@ -47,7 +47,7 @@ class AuthGroupFieldTest extends Field_Framework_TestCase
|
||||
{
|
||||
$this->assertInstanceOf('\OPNsense\Base\FieldTypes\AuthGroupField', new AuthGroupField());
|
||||
// switch config to test set for this type
|
||||
FactoryDefault::getDefault()->get('config')->globals->config_path = __DIR__ . '/AuthGroupFieldTest/';
|
||||
(new AppConfig())->update('globals.config_path', __DIR__ . '/AuthGroupFieldTest/');
|
||||
Config::getInstance()->forceReload();
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
|
||||
// @CodingStandardsIgnoreEnd
|
||||
|
||||
use OPNsense\Base\FieldTypes\AuthenticationServerField;
|
||||
use Phalcon\Di\FactoryDefault;
|
||||
use OPNsense\Core\AppConfig;
|
||||
use OPNsense\Core\Config;
|
||||
|
||||
class AuthenticationServerFieldTest extends Field_Framework_TestCase
|
||||
@ -47,7 +47,7 @@ class AuthenticationServerFieldTest extends Field_Framework_TestCase
|
||||
{
|
||||
$this->assertInstanceOf('\OPNsense\Base\FieldTypes\AuthenticationServerField', new AuthenticationServerField());
|
||||
// switch config to test set for this type
|
||||
FactoryDefault::getDefault()->get('config')->globals->config_path = __DIR__ . '/AuthenticationServerFieldTest/';
|
||||
(new AppConfig())->update('globals.config_path', __DIR__ . '/AuthenticationServerFieldTest/');
|
||||
Config::getInstance()->forceReload();
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
|
||||
// @CodingStandardsIgnoreEnd
|
||||
|
||||
use OPNsense\Base\FieldTypes\CertificateField;
|
||||
use Phalcon\Di\FactoryDefault;
|
||||
use OPNsense\Core\AppConfig;
|
||||
use OPNsense\Core\Config;
|
||||
|
||||
class CertificateFieldTest extends Field_Framework_TestCase
|
||||
@ -47,7 +47,7 @@ class CertificateFieldTest extends Field_Framework_TestCase
|
||||
{
|
||||
$this->assertInstanceOf('\OPNsense\Base\FieldTypes\CertificateField', new CertificateField());
|
||||
// switch config to test set for this type
|
||||
FactoryDefault::getDefault()->get('config')->globals->config_path = __DIR__ . '/CertificateFieldTest/';
|
||||
(new AppConfig())->update('globals.config_path', __DIR__ . '/CertificateFieldTest/');
|
||||
Config::getInstance()->forceReload();
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
|
||||
// @CodingStandardsIgnoreEnd
|
||||
|
||||
use OPNsense\Base\FieldTypes\InterfaceField;
|
||||
use Phalcon\Di\FactoryDefault;
|
||||
use OPNsense\Core\AppConfig;
|
||||
use OPNsense\Core\Config;
|
||||
|
||||
class InterfaceFieldTest extends Field_Framework_TestCase
|
||||
@ -47,7 +47,7 @@ class InterfaceFieldTest extends Field_Framework_TestCase
|
||||
{
|
||||
$this->assertInstanceOf('\OPNsense\Base\FieldTypes\InterfaceField', new InterfaceField());
|
||||
// switch config to test set for this type
|
||||
FactoryDefault::getDefault()->get('config')->globals->config_path = __DIR__ . '/InterfaceFieldTest/';
|
||||
(new AppConfig())->update('globals.config_path', __DIR__ . '/InterfaceFieldTest/');
|
||||
Config::getInstance()->forceReload();
|
||||
}
|
||||
|
||||
|
||||
@ -34,14 +34,14 @@ require_once __DIR__ . '/../BaseModel/TestModel.php';
|
||||
// @CodingStandardsIgnoreEnd
|
||||
|
||||
use OPNsense\Base\FieldTypes\ModelRelationField;
|
||||
use Phalcon\Di\FactoryDefault;
|
||||
use OPNsense\Core\AppConfig;
|
||||
use OPNsense\Core\Config;
|
||||
|
||||
class ModelRelationFieldTest extends Field_Framework_TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
FactoryDefault::getDefault()->get('config')->globals->config_path = __DIR__ . '/ModelRelationFieldTest/';
|
||||
(new AppConfig())->update('globals.config_path', __DIR__ . '/ModelRelationFieldTest/');
|
||||
Config::getInstance()->forceReload();
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
|
||||
// @CodingStandardsIgnoreEnd
|
||||
|
||||
use OPNsense\Base\FieldTypes\NetworkAliasField;
|
||||
use Phalcon\Di\FactoryDefault;
|
||||
use OPNsense\Core\AppConfig;
|
||||
use OPNsense\Core\Config;
|
||||
|
||||
class NetworkAliasFieldTest extends Field_Framework_TestCase
|
||||
@ -47,7 +47,7 @@ class NetworkAliasFieldTest extends Field_Framework_TestCase
|
||||
{
|
||||
$this->assertInstanceOf('\OPNsense\Base\FieldTypes\NetworkAliasField', new NetworkAliasField());
|
||||
// switch config to test set for this type
|
||||
FactoryDefault::getDefault()->get('config')->globals->config_path = __DIR__ . '/NetworkAliasFieldTest/';
|
||||
(new AppConfig())->update('globals.config_path', __DIR__ . '/NetworkAliasFieldTest/');
|
||||
Config::getInstance()->forceReload();
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
|
||||
// @CodingStandardsIgnoreEnd
|
||||
|
||||
use OPNsense\Base\FieldTypes\VirtualIPField;
|
||||
use Phalcon\Di\FactoryDefault;
|
||||
use OPNsense\Core\AppConfig;
|
||||
use OPNsense\Core\Config;
|
||||
|
||||
class VirtualIPFieldTest extends Field_Framework_TestCase
|
||||
@ -47,7 +47,7 @@ class VirtualIPFieldTest extends Field_Framework_TestCase
|
||||
{
|
||||
$this->assertInstanceOf('\OPNsense\Base\FieldTypes\VirtualIPField', new VirtualIPField());
|
||||
// switch config to test set for this type
|
||||
FactoryDefault::getDefault()->get('config')->globals->config_path = __DIR__ . '/VirtualIPFieldTest/';
|
||||
(new AppConfig())->update('globals.config_path', __DIR__ . '/VirtualIPFieldTest/');
|
||||
Config::getInstance()->forceReload();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user