8
8
namespace Magento \FunctionalTestingFramework \Suite \Service ;
9
9
10
10
use Magento \FunctionalTestingFramework \Exceptions \TestFrameworkException ;
11
+ use Magento \FunctionalTestingFramework \Suite \SuiteGenerator ;
11
12
use Magento \FunctionalTestingFramework \Util \Path \FilePathFormatter ;
12
13
use Symfony \Component \Yaml \Yaml ;
13
14
16
17
*/
17
18
class SuiteGeneratorService
18
19
{
19
- const YAML_CODECEPTION_DIST_FILENAME = 'codeception.dist.yml ' ;
20
- const YAML_CODECEPTION_CONFIG_FILENAME = 'codeception.yml ' ;
21
- const YAML_GROUPS_TAG = 'groups ' ;
22
- const YAML_EXTENSIONS_TAG = 'extensions ' ;
23
- const YAML_ENABLED_TAG = 'enabled ' ;
24
- const YAML_COPYRIGHT_TEXT =
25
- "# Copyright © Magento, Inc. All rights reserved. \n# See COPYING.txt for license details. \n" ;
26
-
27
-
28
20
/**
29
21
* Singleton SuiteGeneratorService Instance.
30
22
*
@@ -65,56 +57,57 @@ public function clearPreviousSessionConfigEntries()
65
57
$ ymlArray = self ::getYamlFileContents ();
66
58
$ newYmlArray = $ ymlArray ;
67
59
// if the yaml entries haven't already been cleared
68
- if (array_key_exists (self ::YAML_EXTENSIONS_TAG , $ ymlArray )) {
69
- foreach ($ ymlArray [self ::YAML_EXTENSIONS_TAG ][self ::YAML_ENABLED_TAG ] as $ key => $ entry ) {
60
+ if (array_key_exists (SuiteGenerator::YAML_EXTENSIONS_TAG , $ ymlArray )) {
61
+ $ ymlEntries = $ ymlArray [SuiteGenerator::YAML_EXTENSIONS_TAG ][SuiteGenerator::YAML_ENABLED_TAG ];
62
+
63
+ foreach ($ ymlEntries as $ key => $ entry ) {
70
64
if (preg_match ('/(Group \\\\.*)/ ' , $ entry )) {
71
- unset($ newYmlArray [self ::YAML_EXTENSIONS_TAG ][self ::YAML_ENABLED_TAG ][$ key ]);
65
+ unset($ newYmlArray [SuiteGenerator ::YAML_EXTENSIONS_TAG ][SuiteGenerator ::YAML_ENABLED_TAG ][$ key ]);
72
66
}
73
67
}
74
68
75
69
// needed for proper yml file generation based on indices
76
- $ newYmlArray [self ::YAML_EXTENSIONS_TAG ][self ::YAML_ENABLED_TAG ] =
77
- array_values ($ newYmlArray [self ::YAML_EXTENSIONS_TAG ][self ::YAML_ENABLED_TAG ]);
70
+ $ newYmlArray [SuiteGenerator ::YAML_EXTENSIONS_TAG ][SuiteGenerator ::YAML_ENABLED_TAG ] =
71
+ array_values ($ newYmlArray [SuiteGenerator ::YAML_EXTENSIONS_TAG ][SuiteGenerator ::YAML_ENABLED_TAG ]);
78
72
}
79
73
80
- if (array_key_exists (self ::YAML_GROUPS_TAG , $ newYmlArray )) {
81
- unset($ newYmlArray [self ::YAML_GROUPS_TAG ]);
74
+ if (array_key_exists (SuiteGenerator ::YAML_GROUPS_TAG , $ newYmlArray )) {
75
+ unset($ newYmlArray [SuiteGenerator ::YAML_GROUPS_TAG ]);
82
76
}
83
77
84
- $ ymlText = self ::YAML_COPYRIGHT_TEXT . Yaml::dump ($ newYmlArray , 10 );
85
- file_put_contents (self ::getYamlConfigFilePath () . self ::YAML_CODECEPTION_CONFIG_FILENAME , $ ymlText );
78
+ $ ymlText = SuiteGenerator ::YAML_COPYRIGHT_TEXT . Yaml::dump ($ newYmlArray , 10 );
79
+ file_put_contents (self ::getYamlConfigFilePath () . SuiteGenerator ::YAML_CODECEPTION_CONFIG_FILENAME , $ ymlText );
86
80
}
87
81
88
-
89
82
/**
90
83
* Function which accepts a suite name and suite path and appends a new group entry to the codeception.yml.dist
91
84
* file in order to register the set of tests as a new group. Also appends group object location if required
92
85
* by suite.
93
86
*
94
- * @param string $suiteName
95
- * @param string $suitePath
96
- * @param string $groupNamespace
87
+ * @param string $suiteName
88
+ * @param string $suitePath
89
+ * @param string|null $groupNamespace
97
90
*
98
91
* @return void
99
92
* @throws TestFrameworkException
100
93
*/
101
- public function appendEntriesToConfig (string $ suiteName , string $ suitePath , string $ groupNamespace )
94
+ public function appendEntriesToConfig (string $ suiteName , string $ suitePath , ? string $ groupNamespace )
102
95
{
103
96
$ relativeSuitePath = substr ($ suitePath , strlen (TESTS_BP ));
104
97
$ relativeSuitePath = ltrim ($ relativeSuitePath , DIRECTORY_SEPARATOR );
105
98
$ ymlArray = self ::getYamlFileContents ();
106
99
107
- if (!array_key_exists (self ::YAML_GROUPS_TAG , $ ymlArray )) {
108
- $ ymlArray [self ::YAML_GROUPS_TAG ]= [];
100
+ if (!array_key_exists (SuiteGenerator ::YAML_GROUPS_TAG , $ ymlArray )) {
101
+ $ ymlArray [SuiteGenerator ::YAML_GROUPS_TAG ] = [];
109
102
}
110
103
111
104
if ($ groupNamespace ) {
112
- $ ymlArray [self ::YAML_EXTENSIONS_TAG ][self ::YAML_ENABLED_TAG ][] = $ groupNamespace ;
105
+ $ ymlArray [SuiteGenerator ::YAML_EXTENSIONS_TAG ][SuiteGenerator ::YAML_ENABLED_TAG ][] = $ groupNamespace ;
113
106
}
114
107
115
- $ ymlArray [self ::YAML_GROUPS_TAG ][$ suiteName ] = [$ relativeSuitePath ];
116
- $ ymlText = self ::YAML_COPYRIGHT_TEXT . Yaml::dump ($ ymlArray , 10 );
117
- file_put_contents (self ::getYamlConfigFilePath () . self ::YAML_CODECEPTION_CONFIG_FILENAME , $ ymlText );
108
+ $ ymlArray [SuiteGenerator ::YAML_GROUPS_TAG ][$ suiteName ] = [$ relativeSuitePath ];
109
+ $ ymlText = SuiteGenerator ::YAML_COPYRIGHT_TEXT . Yaml::dump ($ ymlArray , 10 );
110
+ file_put_contents (self ::getYamlConfigFilePath () . SuiteGenerator ::YAML_CODECEPTION_CONFIG_FILENAME , $ ymlText );
118
111
}
119
112
120
113
/**
@@ -125,8 +118,8 @@ public function appendEntriesToConfig(string $suiteName, string $suitePath, stri
125
118
*/
126
119
private static function getYamlFileContents (): array
127
120
{
128
- $ configYmlFile = self ::getYamlConfigFilePath () . self ::YAML_CODECEPTION_CONFIG_FILENAME ;
129
- $ defaultConfigYmlFile = self ::getYamlConfigFilePath () . self ::YAML_CODECEPTION_DIST_FILENAME ;
121
+ $ configYmlFile = self ::getYamlConfigFilePath () . SuiteGenerator ::YAML_CODECEPTION_CONFIG_FILENAME ;
122
+ $ defaultConfigYmlFile = self ::getYamlConfigFilePath () . SuiteGenerator ::YAML_CODECEPTION_DIST_FILENAME ;
130
123
$ ymlContents = null ;
131
124
132
125
if (file_exists ($ configYmlFile )) {
@@ -148,4 +141,4 @@ private static function getYamlConfigFilePath()
148
141
{
149
142
return FilePathFormatter::format (TESTS_BP );
150
143
}
151
- }
144
+ }
0 commit comments