1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace EasySwoole\Config\Test;
- use EasySwoole\Config\TableConfig;
- use PHPUnit\Framework\TestCase;
- class TableTest extends TestCase
- {
- protected $config;
- public function setUp()/* The :void return type declaration that should be here would cause a BC issue */
- {
- $this->config = new \EasySwoole\Config\TableConfig();
- }
- private function getConfigObj(): TableConfig
- {
- return $this->config;
- }
- private function loadConfig()
- {
- $config = [
- 'SERVER_NAME' => "EasySwoole",
- 'MAIN_SERVER' => [
- 'LISTEN_ADDRESS' => '0.0.0.0',
- 'PORT' => 9901,
- 'SERVER_TYPE' => 'EASYSWOOLE_WEB_SERVER',
- 'SOCK_TYPE' => 'SWOOLE_TCP',
- 'RUN_MODEL' => 'SWOOLE_PROCESS',
- 'SETTING' => [
- 'worker_num' => 8,
- 'max_request' => 5000,
- 'task_worker_num' => 8,
- 'task_max_request' => 1000
- ]
- ],
- 'TEMP_DIR' => null,
- 'LOG_DIR' => null,
- ];
- $this->getConfigObj()->load($config);
- }
- public function testSetConf()
- {
- $this->assertNull($this->getConfigObj()->getConf('SERVER_NAME'));
- $this->getConfigObj()->setConf('SERVER_NAME', 'EaswSwoole');
- $this->getConfigObj()->setConf('MAIN_SERVER.PORT', 9999);
- $this->assertEquals('EaswSwoole', $this->getConfigObj()->getConf('SERVER_NAME'));
- $this->assertEquals(9999, $this->getConfigObj()->getConf('MAIN_SERVER.PORT'));
- }
- public function testGetConf()
- {
- $this->loadConfig();
- $this->assertEquals('EasySwoole', $this->getConfigObj()->getConf('SERVER_NAME'));
- $this->assertEquals(9901, $this->getConfigObj()->getConf('MAIN_SERVER.PORT'));
- $this->assertEquals(8, $this->getConfigObj()->getConf('MAIN_SERVER.SETTING.worker_num'));
- }
- public function testMerge()
- {
- $this->loadConfig();
- $this->assertEquals('EasySwoole', $this->getConfigObj()->getConf('SERVER_NAME'));
- $arr = ['SERVER_NAME' => 'bb', 'MAIN_SERVER' => ['MAIN_SERVER' => 9903]];
- $this->getConfigObj()->merge($arr);
- $this->assertEquals('bb', $this->getConfigObj()->getConf('SERVER_NAME'));
- $this->assertEquals('9903', $this->getConfigObj()->getConf('MAIN_SERVER.MAIN_SERVER'));
- }
- public function testClear()
- {
- $this->loadConfig();
- $this->getConfigObj()->clear();
- $arr = $this->getConfigObj()->getConf();
- $this->assertEmpty($arr);
- }
- }
|