-
Notifications
You must be signed in to change notification settings - Fork 132
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
Conversation
- Set up ground work for test command
- Set up More ground work for test command
- Added filename to all test objects
- Added filename to page/section
- 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
- Static/Unit test Fixes
|
||
if (!empty($violatingReferences)) { | ||
// Build error output | ||
$errorOutput = "\nFile \"{$filePath->getRealPath()}\"\ncontains references to following modules:\n\t\t"; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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}"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
@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). |
$filePaths = [ | ||
DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR, | ||
DIRECTORY_SEPARATOR . 'ActionGroup' . DIRECTORY_SEPARATOR, | ||
DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see
You are right. I was using the wrong branch. Please ignore the previous comment |
- Updated Output error message
- Fixed Static Check
// Not a module, is either dev/tests/acceptance or loose folder with test materials | ||
if ($moduleFullName == null) { | ||
continue; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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}}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
There was a problem hiding this 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.
Description
static-checks
{{data.xml}}
and{{data.xml(also.parameters)}}
extends=""
ref=""
dataEntity
has base or merge incatalog
andwishlist
, reference will be valid if file has dendepncy on eithercatalog
orwishlist
.Contribution checklist