Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdminConfigFixture.php
Go to the documentation of this file.
1 <?php
11 
18 {
24  protected $_currentTest;
25 
31  private $_configValues = [];
32 
39  protected function _getConfigValue($configPath)
40  {
41  return \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
42  \Magento\Framework\App\Config\MutableScopeConfigInterface::class
43  )->getValue(
44  $configPath
45  );
46  }
47 
54  protected function _setConfigValue($configPath, $value)
55  {
57  \Magento\Framework\App\Config\MutableScopeConfigInterface::class
58  )->setValue(
59  $configPath,
60  $value
61  );
62  }
63 
69  protected function _assignConfigData(\PHPUnit\Framework\TestCase $test)
70  {
71  $annotations = $test->getAnnotations();
72  if (!isset($annotations['method']['magentoAdminConfigFixture'])) {
73  return;
74  }
75  foreach ($annotations['method']['magentoAdminConfigFixture'] as $configPathAndValue) {
76  list($configPath, $requiredValue) = preg_split('/\s+/', $configPathAndValue, 2);
77 
78  $originalValue = $this->_getConfigValue($configPath);
79  $this->_configValues[$configPath] = $originalValue;
80 
81  $this->_setConfigValue($configPath, $requiredValue);
82  }
83  }
84 
88  protected function _restoreConfigData()
89  {
90  foreach ($this->_configValues as $configPath => $originalValue) {
91  $this->_setConfigValue($configPath, $originalValue);
92  }
93  $this->_configValues = [];
94  }
95 
101  public function startTest(\PHPUnit\Framework\TestCase $test)
102  {
103  $this->_currentTest = $test;
104  $this->_assignConfigData($test);
105  }
106 
114  public function endTest(\PHPUnit\Framework\TestCase $test)
115  {
116  $this->_currentTest = null;
117  $this->_restoreConfigData();
118  }
119 
123  public function initStoreAfter()
124  {
125  /* process events triggered from within a test only */
126  if ($this->_currentTest) {
127  $this->_assignConfigData($this->_currentTest);
128  }
129  }
130 }
_assignConfigData(\PHPUnit\Framework\TestCase $test)
$value
Definition: gender.phtml:16