-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathMftfApplicationConfig.php
199 lines (179 loc) · 5.44 KB
/
MftfApplicationConfig.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Config;
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
class MftfApplicationConfig
{
/**
* MFTF Execution Phases
*/
const GENERATION_PHASE = "generation";
const EXECUTION_PHASE = "execution";
const UNIT_TEST_PHASE = "testing";
const MFTF_PHASES = [self::GENERATION_PHASE, self::EXECUTION_PHASE, self::UNIT_TEST_PHASE];
/**
* Mftf debug levels
*/
const LEVEL_DEFAULT = "default";
const LEVEL_DEVELOPER = "developer";
const LEVEL_NONE = "none";
const MFTF_DEBUG_LEVEL = [self::LEVEL_DEFAULT, self::LEVEL_DEVELOPER, self::LEVEL_NONE];
/**
* Determines whether the user has specified a force option for generation
*
* @var boolean
*/
private $forceGenerate;
/**
* String which identifies the current phase of mftf execution
*
* @var string
*/
private $phase;
/**
* Determines whether the user would like to execute mftf in a verbose run.
*
* @var boolean
*/
private $verboseEnabled;
/**
* String which identifies the current debug level of mftf execution
*
* @var string
*/
private $debugLevel;
/**
* Boolean which allows MFTF to fully generate skipped tests
* @var boolean
*/
private $allowSkipped;
/**
* MftfApplicationConfig Singelton Instance
*
* @var MftfApplicationConfig
*/
private static $MFTF_APPLICATION_CONTEXT;
/**
* MftfApplicationConfig constructor.
*
* @param boolean $forceGenerate
* @param string $phase
* @param boolean $verboseEnabled
* @param string $debugLevel
* @param boolean $allowSkipped
* @throws TestFrameworkException
*/
private function __construct(
$forceGenerate = false,
$phase = self::EXECUTION_PHASE,
$verboseEnabled = null,
$debugLevel = self::LEVEL_NONE,
$allowSkipped = false
) {
$this->forceGenerate = $forceGenerate;
if (!in_array($phase, self::MFTF_PHASES)) {
throw new TestFrameworkException("{$phase} is not an mftf phase");
}
$this->phase = $phase;
$this->verboseEnabled = $verboseEnabled;
switch ($debugLevel) {
case self::LEVEL_DEVELOPER:
case self::LEVEL_DEFAULT:
case self::LEVEL_NONE:
$this->debugLevel = $debugLevel;
break;
default:
$this->debugLevel = self::LEVEL_DEVELOPER;
}
$this->allowSkipped = $allowSkipped;
}
/**
* Creates an instance of the configuration instance for reference once application has started. This function
* returns void and is only run once during the lifetime of the application.
*
* @param boolean $forceGenerate
* @param string $phase
* @param boolean $verboseEnabled
* @param string $debugLevel
* @param boolean $allowSkipped
* @return void
* @throws TestFrameworkException
*/
public static function create(
$forceGenerate = false,
$phase = self::EXECUTION_PHASE,
$verboseEnabled = null,
$debugLevel = self::LEVEL_NONE,
$allowSkipped = false
) {
if (self::$MFTF_APPLICATION_CONTEXT == null) {
self::$MFTF_APPLICATION_CONTEXT =
new MftfApplicationConfig($forceGenerate, $phase, $verboseEnabled, $debugLevel, $allowSkipped);
}
}
/**
* This function returns an instance of the MftfApplicationConfig which is created once the application starts.
*
* @return MftfApplicationConfig
* @throws TestFrameworkException
*/
public static function getConfig()
{
// TODO explicitly set this with AcceptanceTester or MagentoWebDriver
// during execution we cannot guarantee the use of the robofile so we return the default application config,
// we don't want to set the application context in case the user explicitly does so at a later time.
if (self::$MFTF_APPLICATION_CONTEXT == null) {
return new MftfApplicationConfig();
}
return self::$MFTF_APPLICATION_CONTEXT;
}
/**
* Returns a booelan indiciating whether or not the user has indicated a forced generation.
*
* @return boolean
*/
public function forceGenerateEnabled()
{
return $this->forceGenerate;
}
/**
* Returns a boolean indicating whether the user has indicated a verbose run, which will cause all applicable
* text to print to the console.
*
* @return boolean
*/
public function verboseEnabled()
{
return $this->verboseEnabled ?? getenv('MFTF_DEBUG');
}
/**
* Returns a string which indicates the debug level of mftf execution.
*
* @return string
*/
public function getDebugLevel()
{
return $this->debugLevel ?? getenv('MFTF_DEBUG');
}
/**
* Returns a boolean indicating whether mftf is generating skipped tests.
*
* @return boolean
*/
public function allowSkipped()
{
return $this->allowSkipped ?? getenv('ALLOW_SKIPPED');
}
/**
* Returns a string which indicates the phase of mftf execution.
*
* @return string
*/
public function getPhase()
{
return $this->phase;
}
}