34 $this->_fixtureDir = realpath(
__DIR__ .
'/_files') .
'/';
39 $this->_object = new \Magento\TestFramework\Bootstrap\Settings(
42 'item_label' =>
'Item Label',
43 'number_of_items' => 42,
44 'item_price' => 12.99,
45 'is_in_stock' =>
true,
46 'free_shipping' =>
'enabled',
48 'test_file' =>
'metrics.php',
49 'all_xml_files' =>
'*.xml',
50 'all_xml_or_one_php_file' =>
'{*.xml,4.php}',
51 'one_xml_or_any_php_file' =>
'1.xml;?.php',
52 'config_file_with_dist' =>
'1.xml',
53 'config_file_no_dist' =>
'2.xml',
54 'no_config_file_dist' =>
'3.xml' 61 $this->_object =
null;
70 new \Magento\TestFramework\Bootstrap\Settings(
'non_existing_dir', []);
79 public function testGet($settingName, $defaultValue, $expectedResult)
81 $this->assertSame($expectedResult, $this->_object->get($settingName, $defaultValue));
87 'string type' => [
'item_label',
null,
'Item Label'],
88 'integer type' => [
'number_of_items',
null, 42],
89 'float type' => [
'item_price',
null, 12.99],
90 'boolean type' => [
'is_in_stock',
null,
true],
91 'non-existing' => [
'non_existing',
null,
null],
92 'zero string' => [
'zero_value',
'1',
'0'],
93 'default value' => [
'non_existing',
'default',
'default']
104 $this->assertSame($expectedResult, $this->_object->getAsBoolean($settingName));
110 'non-enabled string' => [
'item_label',
false],
111 'non-enabled boolean' => [
'is_in_stock',
false],
112 'enabled string' => [
'free_shipping',
true]
124 $this->assertSame($expectedResult, $this->_object->getAsFile($settingName, $defaultValue));
130 'existing file' => [
'test_file',
'',
"{$this->_fixtureDir}metrics.php"],
131 'zero value setting' => [
'zero_value',
'default_should_be_ignored',
"{$this->_fixtureDir}0"],
132 'empty default value' => [
'non_existing_file',
'',
''],
133 'zero default value' => [
'non_existing_file',
'0',
"{$this->_fixtureDir}0"],
134 'default value' => [
'non_existing_file',
'metrics.php',
"{$this->_fixtureDir}metrics.php"]
145 $actualResult = $this->_object->getAsMatchingPaths($settingName);
146 if (is_array($actualResult)) {
149 $this->assertEquals($expectedResult, $actualResult);
155 'single pattern' => [
157 [
"{$this->_fixtureDir}1.xml",
"{$this->_fixtureDir}2.xml"],
159 'pattern with braces' => [
160 'all_xml_or_one_php_file',
161 [
"{$this->_fixtureDir}1.xml",
"{$this->_fixtureDir}2.xml",
"{$this->_fixtureDir}4.php"],
163 'multiple patterns' => [
164 'one_xml_or_any_php_file',
165 [
"{$this->_fixtureDir}1.xml",
"{$this->_fixtureDir}4.php"],
167 'non-existing setting' => [
'non_existing', []],
168 'setting with zero value' => [
'zero_value', [
"{$this->_fixtureDir}0"]]
179 $actualResult = $this->_object->getAsConfigFile($settingName);
180 if (is_array($actualResult)) {
183 $this->assertEquals($expectedResult, $actualResult);
189 'config file & dist file' => [
'config_file_with_dist',
"{$this->_fixtureDir}1.xml"],
190 'config file & no dist file' => [
'config_file_no_dist',
"{$this->_fixtureDir}2.xml"],
191 'no config file & dist file' => [
'no_config_file_dist',
"{$this->_fixtureDir}3.xml.dist"]
202 $this->expectException(\
Magento\Framework\Exception\LocalizedException::class);
203 $this->expectExceptionMessage((
string)$expectedExceptionMsg);
204 $this->_object->getAsConfigFile($settingName);
210 'non-existing setting' => [
212 __(
"Setting 'non_existing' specifies the non-existing file ''."),
214 'non-existing file' => [
216 __(
"Setting 'item_label' specifies the non-existing file '%1Item Label.dist'.", $this->_fixtureDir),
testGetAsConfigFileException($settingName, $expectedExceptionMsg)
defined('TESTS_BP')||define('TESTS_BP' __DIR__
getAsConfigFileExceptionDataProvider()
getAsBooleanDataProvider()
testGetAsBoolean($settingName, $expectedResult)
getAsMatchingPathsDataProvider()
__construct($name=null, array $data=[], $dataName='')
testGetAsFile($settingName, $defaultValue, $expectedResult)
testGetAsMatchingPaths($settingName, $expectedResult)
testGetAsConfigFile($settingName, $expectedResult)
testConstructorNonExistingBaseDir()
testGet($settingName, $defaultValue, $expectedResult)
getAsConfigFileDataProvider()
if(!isset($_GET['name'])) $name