public function testLazySet() { $this->conf->lazySet('db.options.tables.author', function ($len) { return ['columns' => ['id' => 'INT(9) UNSIGNED NOT NULL PRIMARY KEY', 'name' => "VARCHAR({$len}) NOT NULL"]]; }, [50]); $this->assertInstanceOf(ConfigRepository::LAZY_VAL_CLASS, $this->conf->asArray()['db']['options']['tables']['author']); $this->assertEquals('VARCHAR(50) NOT NULL', $this->conf->get('db.options.tables.author.columns.name')); $this->assertEquals('VARCHAR(50) NOT NULL', $this->conf->asArray()['db']['options']['tables']['author']['columns']['name']); $this->conf->lazySet('db.options.tables.book', function () { return ['columns' => ['id' => 'INT(9) UNSIGNED NOT NULL PRIMARY KEY', 'title' => 'VARCHAR(50) NOT NULL', 'author' => 'VARCHAR(50)']]; }, null, true); $this->assertInstanceOf(ConfigRepository::LAZY_VAL_CLASS, $this->conf->asArray()['db']['options']['tables']['book']); $this->assertEquals('VARCHAR(50)', $this->conf->get('db.options.tables.book.columns.author')); $this->assertInstanceOf(ConfigRepository::LAZY_VAL_CLASS, $this->conf->asArray()['db']['options']['tables']['book']); }
/** * test loadSettings * * @dataProvider loadSettingsProvider */ public function testLoadSettings($section, $isScope) { $criteria = ['scopedEntity' => 'user', 'recordId' => 1]; if ($isScope) { $value = $this->getMock('Oro\\Bundle\\ConfigBundle\\Entity\\ConfigValue'); $value->expects($this->once())->method('getSection')->will($this->returnValue('oro_user')); $value->expects($this->once())->method('getName')->will($this->returnValue('level')); $value->expects($this->once())->method('getValue')->will($this->returnValue('test')); $scope = $this->getMock('Oro\\Bundle\\ConfigBundle\\Entity\\Config'); $scope->expects($this->once())->method('getValues')->will($this->returnValue([$value])); $scope->expects($this->once())->method('getEntity')->will($this->returnValue('user')); $this->repository->expects($this->once())->method('findOneBy')->with($criteria)->will($this->returnValue($scope)); } else { $criteria['section'] = 'oro_user'; $this->repository->expects($this->once())->method('findOneBy')->with($criteria)->will($this->returnValue(false)); } $settings = $this->repository->loadSettings($criteria['scopedEntity'], $criteria['recordId'], $section); if ($isScope) { $this->assertArrayHasKey('oro_user', $settings); $this->assertEquals('test', $settings['oro_user']['level']['value']); } else { $this->assertEmpty($settings); } }
<?php require_once 'config-repository.php'; echo '<pre>'; $conf = new ConfigRepository(); // set/get $conf->set('email', '*****@*****.**'); var_export($conf->get('email')); // '*****@*****.**' echo PHP_EOL; // get deep item $conf->set('db', ['host' => '127.0.0.1', 'username' => 'admin', 'password' => 'qwerty12345']); var_export($conf->get('db.username')); // 'admin' echo PHP_EOL; // default value var_export($conf->get('db.charset')); // NULL echo PHP_EOL; var_export($conf->get('db.charset', 'UTF-8')); // 'UTF-8' echo PHP_EOL; // remove $conf->remove('db.password'); var_export($conf->get('db.password')); // NULL echo PHP_EOL; // set deep item $conf->set('db.options.attr.' . PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); var_export($conf->get('db.options.attr', [])); // array(3 => 2,)