forked from magento/magento2-functional-testing-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSuiteObject.php
170 lines (152 loc) · 4.16 KB
/
SuiteObject.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Suite\Objects;
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
use Magento\FunctionalTestingFramework\Filter\FilterInterface;
use Magento\FunctionalTestingFramework\Test\Objects\TestHookObject;
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
/**
* Class SuiteObject
*/
class SuiteObject
{
/**
* Name of the Suite.
*
* @var string
*/
private $name;
/**
* Array of Tests to include for the suite.
*
* @var TestObject[]
*/
private $includeTests = [];
/**
* Array of Tests to exclude for the suite.
*
* @var TestObject[]
*/
private $excludeTests = [];
/**
* Array of before/after hooks to be executed for a suite.
*
* @var TestHookObject[]
*/
private $hooks;
/**
* Filename of where the suite came from
*
* @var string
*/
private $filename;
/**
* SuiteObject constructor.
* @param string $name
* @param TestObject[] $includeTests
* @param TestObject[] $excludeTests
* @param TestHookObject[] $hooks
* @param string $filename
*/
public function __construct($name, $includeTests, $excludeTests, $hooks, $filename = null)
{
$this->name = $name;
$this->includeTests = $includeTests;
$this->excludeTests = $excludeTests;
$this->hooks = $hooks;
$this->filename = $filename;
}
/**
* Getter for suite name.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Returns an array of Test Objects based on specifications in exclude and include arrays.
*
* @return array
*/
public function getTests()
{
return $this->resolveTests($this->includeTests, $this->excludeTests);
}
/**
* Takes an array of Test Objects to include and an array of Test Objects to exlucde. Loops through each Test
* and determines any overlapping tests. Returns a resulting array of Test Objects based on this logic. Exclusion is
* preferred to exclusiong (i.e. a test is specified in both include and exclude, it will be excluded).
*
* @param TestObject[] $includeTests
* @param TestObject[] $excludeTests
* @return TestObject[]
* @throws \Exception
*/
private function resolveTests($includeTests, $excludeTests)
{
$finalTestList = $includeTests;
$matchingTests = array_intersect(array_keys($includeTests), array_keys($excludeTests));
// filter out tests for exclusion here
foreach ($matchingTests as $testName) {
unset($finalTestList[$testName]);
}
$filters = MftfApplicationConfig::getConfig()->getFilterList()->getFilters();
/** @var FilterInterface $filter */
foreach ($filters as $filter) {
$filter->filter($finalTestList);
}
return $finalTestList;
}
/**
* Convenience method for determining if a Suite will require group file generation.
* A group file will only be generated when the user specifies a before/after statement.
*
* @return boolean
*/
public function requiresGroupFile()
{
return !empty($this->hooks);
}
/**
* Getter for the Hook Array which contains the before/after objects.
*
* @return TestHookObject[]
*/
public function getHooks()
{
return $this->hooks;
}
/**
* Getter for before hooks.
*
* @return TestHookObject
*/
public function getBeforeHook()
{
return $this->hooks['before'] ?? null;
}
/**
* Getter for after hooks.
*
* @return TestHookObject
*/
public function getAfterHook()
{
return $this->hooks['after'] ?? null;
}
/**
* Getter for the Suite Filename
*
* @return string
*/
public function getFilename()
{
return $this->filename;
}
}