123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace tests\unit\Util;
- use Magento\FunctionalTestingFramework\Suite\Util\SuiteObjectExtractor;
- use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor;
- use Magento\FunctionalTestingFramework\Test\Util\TestObjectExtractor;
- class SuiteDataArrayBuilder
- {
- /**
- * Mock test name
- *
- * @var string
- */
- private $name;
- /**
- * Mock before action name
- *
- * @var string
- */
- private $testActionBeforeName = 'testActionBefore';
- /**
- * Mock after action name
- *
- * @var string
- */
- private $testActionAfterName = 'testActionAfter';
- /**
- * Array containing before hook actions
- *
- * @var array
- */
- private $beforeHook = [];
- /**
- * Arrat containing after hook actions
- *
- * @var array
- */
- private $afterHook = [];
- /**
- * Array which contains tests, groups, modules included as part of suite
- *
- * @var array
- */
- private $includes = [];
- /**
- * Array which contains, tests, groups, module excluded from suite
- *
- * @var array
- */
- private $excludes = [];
- /**
- * Mock test action type
- *
- * @var string
- */
- public $testActionType = 'testAction';
- /**
- * Function which sets the name of the mock suite array
- *
- * @param string $name
- * @return $this
- */
- public function withName($name)
- {
- $this->name = $name;
- return $this;
- }
- /**
- * Function which takes an array of test names and formats them as included raw suite data
- *
- * @param array $tests
- * @return $this
- */
- public function includeTests($tests)
- {
- $this->includes = $this->appendEntriesToSuiteContents($this->includes, 'test', $tests);
- return $this;
- }
- /**
- * Function which takes an array of test names and formats them as excluded raw suite data
- *
- * @param array $tests
- * @return $this
- */
- public function excludeTests($tests)
- {
- $this->excludes = $this->appendEntriesToSuiteContents($this->excludes, 'test', $tests);
- return $this;
- }
- /**
- * Function which takes an array of group names and formats them as included raw suite data
- *
- * @param array $groups
- * @return $this
- */
- public function includeGroups($groups)
- {
- $this->includes = $this->appendEntriesToSuiteContents($this->includes, 'group', $groups);
- return $this;
- }
- /**
- * Function which takes an array of group names and formats them as excluded raw suite data
- *
- * @param array $groups
- * @return $this
- */
- public function excludeGroups($groups)
- {
- $this->excludes = $this->appendEntriesToSuiteContents($this->excludes, 'groups', $groups);
- return $this;
- }
- /**
- * Function which takes an array of module names and formats them as included raw suite data
- *
- * @param array $modules
- * @return $this
- */
- public function includeModules($modules)
- {
- $this->includes = $this->appendEntriesToSuiteContents($this->includes, 'module', $modules);
- return $this;
- }
- /**
- * Function which takes an array of group names and formats them as excluded raw suite data
- *
- * @param array $modules
- * @return $this
- */
- public function excludeModules($modules)
- {
- $this->excludes = $this->appendEntriesToSuiteContents($this->excludes, 'module', $modules);
- return $this;
- }
- /**
- * Function which takes an array of current include/exclude contents, a type (group, module, or test) and contents
- * to be appended to the array and returns a propelry formatted array representative of parsed suite data.
- *
- * @param array $currentContents
- * @param string $type
- * @param array $contents
- * @return array
- */
- private function appendEntriesToSuiteContents($currentContents, $type, $contents)
- {
- $newContents = $currentContents;
- foreach ($contents as $entry) {
- $newContents[$entry] = [
- SuiteObjectExtractor::NODE_NAME => $type,
- SuiteObjectExtractor::NAME => $entry
- ];
- }
- return $newContents;
- }
- /**
- * Add an after hook passed in by arg (or default if no arg)
- *
- * @param null $afterHook
- * @return $this
- */
- public function withAfterHook($afterHook = null)
- {
- if ($afterHook == null) {
- $this->afterHook = [$this->testActionAfterName => [
- ActionObjectExtractor::NODE_NAME => $this->testActionType,
- ActionObjectExtractor::TEST_STEP_MERGE_KEY => $this->testActionAfterName
- ]];
- } else {
- $this->afterHook = $afterHook;
- }
- return $this;
- }
- /**
- * Add a before hook passed in by arg (or default if no arg)
- *
- * @param null $beforeHook
- * @return $this
- */
- public function withBeforeHook($beforeHook = null)
- {
- if ($beforeHook == null) {
- $this->beforeHook = [$this->testActionBeforeName => [
- ActionObjectExtractor::NODE_NAME => $this->testActionType,
- ActionObjectExtractor::TEST_STEP_MERGE_KEY => $this->testActionBeforeName
- ]];
- } else {
- $this->beforeHook = $beforeHook;
- }
- return $this;
- }
- /**
- * Function which takes all class properties set and generates an array representing suite data as parsed from xml.
- *
- * @return array
- */
- public function build()
- {
- return ['suites' => [
- $this->name => [
- SuiteObjectExtractor::NAME => $this->name,
- TestObjectExtractor::TEST_BEFORE_HOOK => $this->beforeHook,
- TestObjectExtractor::TEST_AFTER_HOOK => $this->afterHook,
- SuiteObjectExtractor::INCLUDE_TAG_NAME => $this->includes,
- SuiteObjectExtractor::EXCLUDE_TAG_NAME => $this->excludes
- ]
- ]];
- }
- }
|