Skip to content

MQE-2039: fatal error in actionGroupArguments static check when there… #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

namespace Magento\FunctionalTestingFramework\StaticCheck;

use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
use Magento\FunctionalTestingFramework\Test\Handlers\ActionGroupObjectHandler;
use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject;
use Symfony\Component\Console\Input\InputInterface;
use Magento\FunctionalTestingFramework\Util\ModuleResolver;
use Symfony\Component\Finder\Finder;
use Exception;
use Magento\FunctionalTestingFramework\Util\Script\ScriptUtil;
Expand All @@ -22,7 +19,6 @@
*/
class ActionGroupArgumentsCheck implements StaticCheckInterface
{

const ACTIONGROUP_XML_REGEX_PATTERN = '/<actionGroup\sname=(?: (?!<\/actionGroup>).)*/mxs';
const ACTIONGROUP_ARGUMENT_REGEX_PATTERN = '/<argument[^\/>]*name="([^"\']*)/mxs';
const ACTIONGROUP_NAME_REGEX_PATTERN = '/<actionGroup name=["\']([^\'"]*)/';
Expand All @@ -42,6 +38,13 @@ class ActionGroupArgumentsCheck implements StaticCheckInterface
*/
private $output;

/**
* ScriptUtil instance
*
* @var ScriptUtil
*/
private $scriptUtil;

/**
* Checks unused arguments in action groups and prints out error to file.
*
Expand All @@ -51,16 +54,17 @@ class ActionGroupArgumentsCheck implements StaticCheckInterface
*/
public function execute(InputInterface $input)
{
$allModules = ScriptUtil::getAllModulePaths();
$this->scriptUtil = new ScriptUtil();
$allModules = $this->scriptUtil->getAllModulePaths();

$actionGroupXmlFiles = ScriptUtil::getModuleXmlFilesByScope(
$actionGroupXmlFiles = $this->scriptUtil->getModuleXmlFilesByScope(
$allModules,
DIRECTORY_SEPARATOR . 'ActionGroup' . DIRECTORY_SEPARATOR
);

$this->errors = $this->findErrorsInFileSet($actionGroupXmlFiles);

$this->output = ScriptUtil::printErrorsToFile(
$this->output = $this->scriptUtil->printErrorsToFile(
$this->errors,
self::ERROR_LOG_FILENAME,
self::ERROR_LOG_MESSAGE
Expand Down Expand Up @@ -132,10 +136,19 @@ private function findUnusedArguments($actionGroupXml)

preg_match_all(self::ACTIONGROUP_ARGUMENT_REGEX_PATTERN, $actionGroupXml, $arguments);
preg_match(self::ACTIONGROUP_NAME_REGEX_PATTERN, $actionGroupXml, $actionGroupName);
$validActionGroup = false;
try {
$actionGroup = ActionGroupObjectHandler::getInstance()->getObject($actionGroupName[1]);
} catch (XmlException $e) {
if ($actionGroup) {
$validActionGroup = true;
}
} catch (Exception $e) {
}

if (!$validActionGroup) {
return $unusedArguments;
}

foreach ($arguments[1] as $argument) {
//pattern to match all argument references
$patterns = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\FunctionalTestingFramework\Test\Handlers;

use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
use Magento\FunctionalTestingFramework\ObjectManager\ObjectHandlerInterface;
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject;
Expand Down Expand Up @@ -49,6 +50,7 @@ class ActionGroupObjectHandler implements ObjectHandlerInterface
* Singleton getter for instance of ActionGroupObjectHandler
*
* @return ActionGroupObjectHandler
* @throws XmlException
*/
public static function getInstance(): ActionGroupObjectHandler
{
Expand All @@ -61,6 +63,7 @@ public static function getInstance(): ActionGroupObjectHandler

/**
* ActionGroupObjectHandler constructor.
* @throws XmlException
*/
private function __construct()
{
Expand All @@ -73,6 +76,8 @@ private function __construct()
*
* @param string $actionGroupName
* @return ActionGroupObject
* @throws TestFrameworkException
* @throws XmlException
*/
public function getObject($actionGroupName)
{
Expand All @@ -88,6 +93,8 @@ public function getObject($actionGroupName)
* Function to return all objects for which the handler is responsible
*
* @return array
* @throws TestFrameworkException
* @throws XmlException
*/
public function getAllObjects(): array
{
Expand All @@ -101,6 +108,7 @@ public function getAllObjects(): array
* Method which populates field array with objects from parsed action_group.xml
*
* @return void
* @throws XmlException
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
*/
private function initActionGroups()
Expand Down Expand Up @@ -137,6 +145,7 @@ private function initActionGroups()
*
* @param ActionGroupObject $actionGroupObject
* @return ActionGroupObject
* @throws XmlException
* @throws TestFrameworkException
*/
private function extendActionGroup($actionGroupObject): ActionGroupObject
Expand Down