Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InjectableTests.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\ObjectManager;
10 use Magento\Mtf\ObjectManagerFactory;
11 
16 class InjectableTests extends \PHPUnit\Framework\TestSuite
17 {
21  protected $objectManager;
22 
26  protected $suite;
27 
31  protected $result;
32 
41  public function run(\PHPUnit\Framework\TestResult $result = null)
42  {
43  if ($result === null) {
44  $this->result = $this->createResult();
45  }
46  }
47 
53  public static function suite()
54  {
55  $suite = new self();
56  return $suite->prepareSuite();
57  }
58 
64  public function prepareSuite()
65  {
66  $this->init();
67  return $this->objectManager->create(\Magento\Mtf\TestSuite\AppState::class);
68  }
69 
73  public function init()
74  {
75  $this->initObjectManager();
76  }
77 
81  private function initObjectManager()
82  {
83  if (!isset($this->objectManager)) {
84  $objectManagerFactory = new ObjectManagerFactory();
85 
86  $configFileName = isset($_ENV['testsuite_rule']) ? $_ENV['testsuite_rule'] : 'basic';
87  $configFilePath = realpath(MTF_BP . '/testsuites/' . $_ENV['testsuite_rule_path']);
88 
90  $configData = $objectManagerFactory->getObjectManager()->create(\Magento\Mtf\Config\TestRunner::class);
91  $filter = getopt('', ['filter:']);
92  if (!isset($filter['filter'])) {
93  $configData->setFileName($configFileName . '.xml')->load($configFilePath);
94  } else {
95  $isValid = preg_match('`variation::(.*?)$`', $filter['filter'], $variation);
96  if ($isValid === 1) {
97  $configData->setFileName($configFileName . '.xml')->load($configFilePath);
98  $data['rule']['variation']['allow'][0]['name'][0]['value'] = $variation[1];
99  $configData->merge($data);
100  }
101  }
102  $this->objectManager = $objectManagerFactory->create(
103  [\Magento\Mtf\Config\TestRunner::class => $configData]
104  );
105  }
106  }
107 }
defined('MTF_TESTS_PATH')||define('MTF_TESTS_PATH' MTF_BP
Definition: bootstrap.php:10
$objectManagerFactory
run(\PHPUnit\Framework\TestResult $result=null)