Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MagentoAllureAdapter.php
Go to the documentation of this file.
1 <?php
7 
10 use Yandex\Allure\Adapter\AllureAdapter;
11 use Yandex\Allure\Adapter\Event\StepStartedEvent;
12 use Codeception\Event\SuiteEvent;
13 use Codeception\Event\StepEvent;
14 
23 class MagentoAllureAdapter extends AllureAdapter
24 {
30  private function getGroup()
31  {
32  if ($this->options['groups'] != null) {
33  return $this->options['groups'][0];
34  }
35  return null;
36  }
37 
44  public function suiteBefore(SuiteEvent $suiteEvent)
45  {
46  $changeSuiteEvent = $suiteEvent;
47 
48  if ($this->getGroup() != null) {
49  $suite = $suiteEvent->getSuite();
50  $suiteName = ($suite->getName()) . "\\" . $this->sanitizeGroupName($this->getGroup());
51 
52  call_user_func(\Closure::bind(
53  function () use ($suite, $suiteName) {
54  $suite->name = $suiteName;
55  },
56  null,
57  $suite
58  ));
59 
60  //change suiteEvent
61  $changeSuiteEvent = new SuiteEvent(
62  $suiteEvent->getSuite(),
63  $suiteEvent->getResult(),
64  $suiteEvent->getSettings()
65  );
66  }
67  // call parent function
68  parent::suiteBefore($changeSuiteEvent);
69  }
70 
77  private function sanitizeGroupName($group)
78  {
79  $suiteNames = array_keys(SuiteObjectHandler::getInstance()->getAllObjects());
80  $exactMatch = in_array($group, $suiteNames);
81 
82  // if this is an existing suite name we dont' need to worry about changing it
83  if ($exactMatch || strpos($group, "_") === false) {
84  return $group;
85  }
86 
87  // if we can't find this group in the generated suites we have to assume that the group was split for generation
88  $groupNameSplit = explode("_", $group);
89  array_pop($groupNameSplit);
90  $originalName = implode("_", $groupNameSplit);
91 
92  // confirm our original name is one of the existing suite names otherwise just return the original group name
93  $originalName = in_array($originalName, $suiteNames) ? $originalName : $group;
94  return $originalName;
95  }
96 
103  public function stepBefore(StepEvent $stepEvent)
104  {
105  //Hard set to 200; we don't expose this config in MFTF
106  $argumentsLength = 200;
107  $stepAction = $stepEvent->getStep()->getHumanizedActionWithoutArguments();
108  $stepArgs = $stepEvent->getStep()->getArgumentsAsString($argumentsLength);
109 
110  if (!trim($stepAction)) {
111  $stepAction = $stepEvent->getStep()->getMetaStep()->getHumanizedActionWithoutArguments();
112  $stepArgs = $stepEvent->getStep()->getMetaStep()->getArgumentsAsString($argumentsLength);
113  }
114 
115  $stepName = $stepAction . ' ' . $stepArgs;
116 
117  $this->emptyStep = false;
118  $this->getLifecycle()->fire(new StepStartedEvent($stepName));
119  }
120 }
$group
Definition: sections.phtml:16