|
35 | 35 | */ |
36 | 36 | class CreatedDataFromOutsideActionGroupCheck implements StaticCheckInterface |
37 | 37 | { |
38 | | - const ACTIONGROUP_REGEX_PATTERN = '/\$(\$)*([\w.]+)(\$)*\$/'; |
39 | | - |
40 | | - const ERROR_LOG_FILENAME = 'create-data-from-outside-action-group'; |
41 | | - const ERROR_LOG_MESSAGE = 'Created Data From Outside Action Group'; |
42 | | - |
43 | | - /** |
44 | | - * Array containing all errors found after running the execute() function |
45 | | - * |
46 | | - * @var array |
47 | | - */ |
48 | | - private $errors = []; |
49 | | - |
50 | | - /** |
51 | | - * String representing the output summary found after running the execute() function |
52 | | - * |
53 | | - * @var string |
54 | | - */ |
55 | | - private $output; |
56 | | - |
57 | | - /** |
58 | | - * ScriptUtil instance |
59 | | - * |
60 | | - * @var ScriptUtil |
61 | | - */ |
62 | | - private $scriptUtil; |
63 | | - |
64 | | - /** |
65 | | - * Action group xml files to scan |
66 | | - * |
67 | | - * @var Finder|array |
68 | | - */ |
69 | | - private $actionGroupXmlFiles = []; |
70 | | - |
71 | | - /** |
72 | | - * Checks test dependencies, determined by references in tests versus the dependencies listed in the Magento module |
73 | | - * |
74 | | - * @param InputInterface $input |
75 | | - * @return void |
76 | | - * @throws Exception |
77 | | - */ |
78 | | - public function execute(InputInterface $input) |
79 | | - { |
| 38 | + const ACTIONGROUP_REGEX_PATTERN = '/\$(\$)*([\w.]+)(\$)*\$/'; |
| 39 | + const ERROR_LOG_FILENAME = 'create-data-from-outside-action-group'; |
| 40 | + const ERROR_LOG_MESSAGE = 'Created Data From Outside Action Group'; |
| 41 | + |
| 42 | + /** |
| 43 | + * Array containing all errors found after running the execute() function |
| 44 | + * |
| 45 | + * @var array |
| 46 | + */ |
| 47 | + private $errors = []; |
| 48 | + |
| 49 | + /** |
| 50 | + * String representing the output summary found after running the execute() function |
| 51 | + * |
| 52 | + * @var string |
| 53 | + */ |
| 54 | + private $output; |
| 55 | + |
| 56 | + /** |
| 57 | + * ScriptUtil instance |
| 58 | + * |
| 59 | + * @var ScriptUtil |
| 60 | + */ |
| 61 | + private $scriptUtil; |
| 62 | + |
| 63 | + /** |
| 64 | + * Action group xml files to scan |
| 65 | + * |
| 66 | + * @var Finder|array |
| 67 | + */ |
| 68 | + private $actionGroupXmlFiles = []; |
| 69 | + |
| 70 | + /** |
| 71 | + * Checks test dependencies, determined by references in tests versus the dependencies listed in the Magento module |
| 72 | + * |
| 73 | + * @param InputInterface $input |
| 74 | + * @return void |
| 75 | + * @throws Exception |
| 76 | + */ |
| 77 | + public function execute(InputInterface $input) |
| 78 | + { |
80 | 79 | $this->scriptUtil = new ScriptUtil(); |
81 | 80 | $this->loadAllXmlFiles($input); |
82 | 81 | $this->errors = []; |
83 | | - |
84 | 82 | $this->errors += $this->findReferenceErrorsInActionFiles($this->actionGroupXmlFiles); |
85 | | - |
86 | 83 | $this->output = $this->scriptUtil->printErrorsToFile( |
87 | 84 | $this->errors, |
88 | 85 | StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt', |
89 | 86 | self::ERROR_LOG_MESSAGE |
90 | 87 | ); |
91 | | - } |
92 | | - |
93 | | - /** |
94 | | - * Return array containing all errors found after running the execute() function |
95 | | - * |
96 | | - * @return array |
97 | | - */ |
98 | | - public function getErrors() |
99 | | - { |
100 | | - return $this->errors; |
101 | | - } |
102 | | - |
103 | | - /** |
104 | | - * Return string of a short human readable result of the check. For example: "No Dependency errors found." |
105 | | - * |
106 | | - * @return string |
107 | | - */ |
108 | | - public function getOutput() |
109 | | - { |
110 | | - return $this->output; |
111 | | - } |
| 88 | + } |
112 | 89 |
|
113 | | - /** |
114 | | - * Read all XML files for scanning |
115 | | - * |
116 | | - * @param InputInterface $input |
117 | | - * @return void |
118 | | - * @throws Exception |
119 | | - * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
120 | | - */ |
121 | | - private function loadAllXmlFiles($input) |
122 | | - { |
123 | | - $modulePaths = []; |
124 | | - $includeRootPath = true; |
125 | | - $path = $input->getOption('path'); |
126 | | - if ($path) { |
127 | | - if (!realpath($path)) { |
128 | | - throw new InvalidArgumentException('Invalid --path option: ' . $path); |
129 | | - } |
130 | | - MftfApplicationConfig::create( |
131 | | - true, |
132 | | - MftfApplicationConfig::UNIT_TEST_PHASE, |
133 | | - false, |
134 | | - MftfApplicationConfig::LEVEL_DEFAULT, |
135 | | - true |
136 | | - ); |
137 | | - $modulePaths[] = realpath($path); |
138 | | - $includeRootPath = false; |
139 | | - } else { |
140 | | - $modulePaths = $this->scriptUtil->getAllModulePaths(); |
| 90 | + /** |
| 91 | + * Return array containing all errors found after running the execute() function |
| 92 | + * |
| 93 | + * @return array |
| 94 | + */ |
| 95 | + public function getErrors() |
| 96 | + { |
| 97 | + return $this->errors; |
141 | 98 | } |
142 | 99 |
|
143 | | - // These files can contain references to other entities |
144 | | - $this->actionGroupXmlFiles = $this->scriptUtil->getModuleXmlFilesByScope($modulePaths, 'ActionGroup'); |
145 | | - |
146 | | - if (empty($this->actionGroupXmlFiles)) { |
147 | | - if ($path) { |
148 | | - throw new InvalidArgumentException( |
149 | | - 'Invalid --path option: ' |
150 | | - . $path |
151 | | - . PHP_EOL |
152 | | - . 'Please make sure --path points to a valid MFTF Test Module.' |
153 | | - ); |
154 | | - } elseif (empty($this->rootSuiteXmlFiles)) { |
155 | | - throw new TestFrameworkException('No xml file to scan.'); |
156 | | - } |
| 100 | + /** |
| 101 | + * Return string of a short human readable result of the check. For example: "No Dependency errors found." |
| 102 | + * |
| 103 | + * @return string |
| 104 | + */ |
| 105 | + public function getOutput() |
| 106 | + { |
| 107 | + return $this->output; |
157 | 108 | } |
158 | | - } |
159 | 109 |
|
160 | | - /** |
161 | | - * Find reference errors in set of action files |
162 | | - * |
163 | | - * @param Finder $files |
164 | | - * @return array |
165 | | - * @throws XmlException |
166 | | - */ |
167 | | - private function findReferenceErrorsInActionFiles($files) |
168 | | - { |
169 | | - $testErrors = []; |
170 | | - /** @var SplFileInfo $filePath */ |
171 | | - foreach ($files as $filePath) { |
172 | | - $contents = file_get_contents($filePath); |
173 | | - preg_match_all(self::ACTIONGROUP_REGEX_PATTERN, $contents, $actionGroupReferences); |
174 | | - if(count( $actionGroupReferences) > 0) { |
175 | | - $testErrors = array_merge($testErrors, $this->setErrorOutput($actionGroupReferences, $filePath)); |
| 110 | + /** |
| 111 | + * Read all XML files for scanning |
| 112 | + * |
| 113 | + * @param InputInterface $input |
| 114 | + * @return void |
| 115 | + * @throws Exception |
| 116 | + * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
| 117 | + */ |
| 118 | + private function loadAllXmlFiles($input) |
| 119 | + { |
| 120 | + $modulePaths = []; |
| 121 | + $includeRootPath = true; |
| 122 | + $path = $input->getOption('path'); |
| 123 | + if ($path) { |
| 124 | + if (!realpath($path)) { |
| 125 | + throw new InvalidArgumentException('Invalid --path option: ' . $path); |
| 126 | + } |
| 127 | + MftfApplicationConfig::create( |
| 128 | + true, |
| 129 | + MftfApplicationConfig::UNIT_TEST_PHASE, |
| 130 | + false, |
| 131 | + MftfApplicationConfig::LEVEL_DEFAULT, |
| 132 | + true |
| 133 | + ); |
| 134 | + $modulePaths[] = realpath($path); |
| 135 | + $includeRootPath = false; |
| 136 | + } else { |
| 137 | + $modulePaths = $this->scriptUtil->getAllModulePaths(); |
| 138 | + } |
| 139 | + |
| 140 | + // These files can contain references to other entities |
| 141 | + $this->actionGroupXmlFiles = $this->scriptUtil->getModuleXmlFilesByScope($modulePaths, 'ActionGroup'); |
| 142 | + |
| 143 | + if (empty($this->actionGroupXmlFiles)) { |
| 144 | + if ($path) { |
| 145 | + throw new InvalidArgumentException( |
| 146 | + 'Invalid --path option: ' |
| 147 | + . $path |
| 148 | + . PHP_EOL |
| 149 | + . 'Please make sure --path points to a valid MFTF Test Module.' |
| 150 | + ); |
| 151 | + } elseif (empty($this->rootSuiteXmlFiles)) { |
| 152 | + throw new TestFrameworkException('No xml file to scan.'); |
| 153 | + } |
176 | 154 | } |
177 | 155 | } |
178 | 156 |
|
179 | | - return $testErrors; |
180 | | - } |
| 157 | + /** |
| 158 | + * Find reference errors in set of action files |
| 159 | + * |
| 160 | + * @param Finder $files |
| 161 | + * @return array |
| 162 | + * @throws XmlException |
| 163 | + */ |
| 164 | + private function findReferenceErrorsInActionFiles($files) |
| 165 | + { |
| 166 | + $testErrors = []; |
| 167 | + /** @var SplFileInfo $filePath */ |
| 168 | + foreach ($files as $filePath) { |
| 169 | + $contents = file_get_contents($filePath); |
| 170 | + preg_match_all(self::ACTIONGROUP_REGEX_PATTERN, $contents, $actionGroupReferences); |
| 171 | + if (count($actionGroupReferences) > 0) { |
| 172 | + $testErrors = array_merge($testErrors, $this->setErrorOutput($actionGroupReferences, $filePath)); |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + return $testErrors; |
| 177 | + } |
181 | 178 |
|
182 | | - /** |
183 | | - * Build and return error output for violating references |
184 | | - * |
185 | | - * @param array $actionGroupReferences |
186 | | - * @param SplFileInfo $path |
187 | | - * @return mixed |
188 | | - */ |
189 | | - private function setErrorOutput( $actionGroupReferences , $path) |
190 | | - { |
191 | | - $testErrors = []; |
| 179 | + /** |
| 180 | + * Build and return error output for violating references |
| 181 | + * |
| 182 | + * @param array $actionGroupReferences |
| 183 | + * @param SplFileInfo $path |
| 184 | + * @return mixed |
| 185 | + */ |
| 186 | + private function setErrorOutput($actionGroupReferences, $path) |
| 187 | + { |
| 188 | + $testErrors = []; |
192 | 189 | $errorOutput = ""; |
193 | 190 | $filePath = StaticChecksList::getFilePath($path->getRealPath()); |
194 | 191 |
|
195 | | - foreach($actionGroupReferences as $key => $actionGroupReferencesData) { |
196 | | - foreach($actionGroupReferencesData as $actionGroupReferencesDataResult) { |
197 | | - |
198 | | - $errorOutput .= "\nFile \"{$filePath}\" contains: ". "\n\t {$actionGroupReferencesDataResult} in {$filePath}"; |
199 | | - $testErrors[$filePath][] = $errorOutput; |
200 | | - } |
201 | | - |
202 | | - |
| 192 | + foreach ($actionGroupReferences as $key => $actionGroupReferencesData) { |
| 193 | + foreach ($actionGroupReferencesData as $actionGroupReferencesDataResult) { |
| 194 | + $errorOutput .= "\nFile \"{$filePath}\" contains: ". "\n\t |
| 195 | + {$actionGroupReferencesDataResult} in {$filePath}"; |
| 196 | + $testErrors[$filePath][] = $errorOutput; |
| 197 | + } |
203 | 198 | } |
204 | 199 | return $testErrors; |
205 | 200 | } |
206 | | - |
207 | 201 | } |
0 commit comments