Skip to content

MQE-810: Create a static test to validate references between modules #314

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 11 commits into from
Mar 29, 2019

Conversation

KevinBKozan
Copy link
Contributor

@KevinBKozan KevinBKozan commented Feb 27, 2019

Description

  • Implemented static-checks
  • Checks the following types of files:
    • Test.xml
    • Data.xml
    • ActionGroup.xml
  • Performs checks on following reference types:
    • xml entity references like{{data.xml}} and {{data.xml(also.parameters)}}
    • extends=""
    • actionGroup ref=""
  • Validation is based finding common depdency in file's module and any of the filenames from MFTF entity
    • Above means if dataEntity has base or merge in catalog and wishlist, reference will be valid if file has dendepncy on either catalog or wishlist.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/verification tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)
  • Changes to Framework doesn't have backward incompatible changes for tests or have related Pull Request with fixes to tests

- Implemented Check, only checks first filename found by MFTF.
- fixed actionGroup argument false flagging
- reafactored dependencies check to validate on all entity file origins
- Fixed not all directories being parsed
- Added check for parameters of elements/urls
@coveralls
Copy link

coveralls commented Feb 28, 2019

Coverage Status

Coverage decreased (-1.5%) to 55.296% when pulling 4851692 on MQE-810-B into 44aecc6 on develop.


if (!empty($violatingReferences)) {
// Build error output
$errorOutput = "\nFile \"{$filePath->getRealPath()}\"\ncontains references to following modules:\n\t\t";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we point out the violation directly? e.g. using words like "SomeTest should not contain references to SomeModule" would be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change the error output to be more precise, yes.

}
fclose($fileResource);
$errorCount = count($errors);
$output = "Dependency errors found across {$errorCount} file(s). Error details output to {$outputPath}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it number total tests scanned or number of total errors found? Just look at the error message in console confused me until I see the source code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors unique to file, the $error array is key => value of fileName => [$errors] so the count just counts unique file names.

Copy link
Contributor

@jilu1 jilu1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge file contents are treated as from the parent module, this produced some false positive errors. For example, AdminAddDefaultVideoBundleProductTest, AdminRemoveDefaultVideoBundleProductTest, etc.

@KevinBKozan
Copy link
Contributor Author

@jilu1 I'm not sure how merge file contents play in here, files are being checked on a per-file basis, not per entity (concept of merging is removed).
I reran my tests and am not finding that the above files are shown as errors. Did you pull down the right branch? It's MQE-810-B, due to the extensive refactor.

$filePaths = [
DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR . 'ActionGroup' . DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not include Page and Section here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't think it was relevant, mostly. Section can't reference anything other than static selector strings, and while Pages can reference Sections, that linkage is not really used anywhere in MFTF.
If we do build an actual use for Page->Section linkage I think we should add that link check, but otherwise I don't see it as value adding as far as the check goes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

@jilu1
Copy link
Contributor

jilu1 commented Mar 26, 2019

@jilu1 I'm not sure how merge file contents play in here, files are being checked on a per-file basis, not per entity (concept of merging is removed).
I reran my tests and am not finding that the above files are shown as errors. Did you pull down the right branch? It's MQE-810-B, due to the extensive refactor.

You are right. I was using the wrong branch. Please ignore the previous comment

// Not a module, is either dev/tests/acceptance or loose folder with test materials
if ($moduleFullName == null) {
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am running standalone mftf, and I have a test module under mftf's dev/tests/functional/tests/MFTF/CatalogTest which has been scanned but it should not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check/resolve this.

* @param string $subDependencyName
* @return array
*/
private function extractSubDependencies($subDependencyName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This recursive function is fine by itself. But any reason that you don't build the recursion from root level composer file. Will the current way cause duplicate dependencies in the root level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason is because it would flatten all the dependencies to one huge array, and we want an array with several module => [dependencies].
We iterate through the big list of dependencies on ln 283 so that we can scope the above flattening.

}
// trim `data.field` to `data`
preg_match('/([^.]+)/', $argument, $entityName);
// Double check that {{data.field}} isn't an argument for an ActionGroup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why skipping? What if it's a direct entity reference in an argument for an ActionGroup? e.g. {{_defatultCategory.name}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipping done on line 175 refers to the following case:

<argument name="product" defaultValue="_defaultProduct"/>
...
<comment userInput="{{product.name}} />
<comment userInput="{{_defaultProduct.name}} />

The entity product is just the argument, and if we have a match of name we shouldn't try to resolve it, as the entity doesn't exist.

So in this case the first line would be skipped, but line two would not be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. This is right. I did not look the regex and just thought the argument you tried to skip is in the "value" part.

Copy link
Contributor

@jilu1 jilu1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I checked a few cases and they all work as expected. Please check the standalone case, and it looks good to me.

Copy link
Contributor

@jilu1 jilu1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not reproduce the standalone case. Approve this. Things like how to handle existing violations will be done in separate story.

@KevinBKozan KevinBKozan merged commit 7f82e4d into develop Mar 29, 2019
@KevinBKozan KevinBKozan deleted the MQE-810-B branch July 26, 2019 19:28
magento-devops-reposync-svc pushed a commit that referenced this pull request Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants