66
77namespace Magento \FunctionalTestingFramework \StaticCheck ;
88
9- use Magento \FunctionalTestingFramework \Config \Data ;
109use Magento \FunctionalTestingFramework \Config \MftfApplicationConfig ;
1110use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
11+ use Magento \FunctionalTestingFramework \Exceptions \TestReferenceException ;
12+ use Magento \FunctionalTestingFramework \Exceptions \XmlException ;
1213use Magento \FunctionalTestingFramework \Page \Handlers \PageObjectHandler ;
1314use Magento \FunctionalTestingFramework \Page \Handlers \SectionObjectHandler ;
14- use Magento \FunctionalTestingFramework \Page \Objects \SectionObject ;
1515use Magento \FunctionalTestingFramework \Test \Handlers \ActionGroupObjectHandler ;
1616use Magento \FunctionalTestingFramework \Test \Handlers \TestObjectHandler ;
1717use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
1818use Magento \FunctionalTestingFramework \Util \ModuleResolver ;
1919use Magento \FunctionalTestingFramework \Util \TestGenerator ;
2020use Symfony \Component \Console \Input \InputInterface ;
21- use Symfony \Component \Filesystem \Filesystem ;
2221use Symfony \Component \Finder \Finder ;
22+ use Exception ;
2323
2424/**
2525 * Class TestDependencyCheck
@@ -68,11 +68,18 @@ class TestDependencyCheck implements StaticCheckInterface
6868 */
6969 private $ errors ;
7070
71+ /**
72+ * String representing the output summary found after running the execute() function.
73+ * @var string
74+ */
75+ private $ output ;
76+
7177 /**
7278 * Checks test dependencies, determined by references in tests versus the dependencies listed in the Magento module
7379 *
7480 * @param InputInterface $input
7581 * @return string
82+ * @throws Exception;
7683 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
7784 */
7885 public function execute (InputInterface $ input )
@@ -109,8 +116,8 @@ public function execute(InputInterface $input)
109116 $ this ->errors += $ this ->findErrorsInFileSet ($ actionGroupXmlFiles );
110117 $ this ->errors += $ this ->findErrorsInFileSet ($ dataXmlFiles );
111118
112- //print all errors to file
113- return $ this ->printErrorsToFile ( $ this ->getErrors () );
119+ // hold on to the output and print any errors to a file
120+ $ this ->output = $ this ->printErrorsToFile ( );
114121 }
115122
116123 /**
@@ -122,12 +129,17 @@ public function getErrors()
122129 return $ this ->errors ;
123130 }
124131
132+ public function getOutput ()
133+ {
134+ return $ this ->output ;
135+ }
136+
125137 /**
126138 * Finds all reference errors in given set of files
127139 * @param Finder $files
128140 * @return array
129- * @throws \Magento\FunctionalTestingFramework\Exceptions\ TestReferenceException
130- * @throws \Magento\FunctionalTestingFramework\Exceptions\ XmlException
141+ * @throws TestReferenceException
142+ * @throws XmlException
131143 */
132144 private function findErrorsInFileSet ($ files )
133145 {
@@ -348,8 +360,7 @@ private function buildFileList($modulePaths, $path)
348360 * Attempts to find any MFTF entity by its name. Returns null if none are found.
349361 * @param string $name
350362 * @return mixed
351- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
352- * @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
363+ * @throws XmlException
353364 */
354365 private function findEntity ($ name )
355366 {
@@ -378,24 +389,29 @@ private function findEntity($name)
378389
379390 /**
380391 * Prints out given errors to file, and returns summary result string
381- * @param array $errors
382392 * @return string
383393 */
384- private function printErrorsToFile ($ errors )
394+ private function printErrorsToFile ()
385395 {
396+ $ errors = $ this ->getErrors ();
397+
386398 if (empty ($ errors )) {
387399 return "No Dependency errors found. " ;
388400 }
401+
389402 $ outputPath = getcwd () . DIRECTORY_SEPARATOR . "mftf-dependency-checks.txt " ;
390403 $ fileResource = fopen ($ outputPath , 'w ' );
391404 $ header = "MFTF File Dependency Check: \n" ;
392405 fwrite ($ fileResource , $ header );
406+
393407 foreach ($ errors as $ test => $ error ) {
394408 fwrite ($ fileResource , $ error [0 ] . PHP_EOL );
395409 }
410+
396411 fclose ($ fileResource );
397412 $ errorCount = count ($ errors );
398413 $ output = "Dependency errors found across {$ errorCount } file(s). Error details output to {$ outputPath }" ;
414+
399415 return $ output ;
400416 }
401417}
0 commit comments