-
Notifications
You must be signed in to change notification settings - Fork 132
Add ability to use array entities as arguments. #89
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
1 similar comment
@@ -496,6 +496,10 @@ private function findAndReplaceReferences($objectHandler, $inputString) | |||
|
|||
$replacement = $this->resolveParameterization($parameterized, $replacement, $match, $obj); | |||
|
|||
if (is_array($replacement)) { | |||
$replacement = '["' . implode('","', $replacement) . '"]'; |
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'm aware this would be insufficient escapement but I wasn't sure how far this needed to go. I figured if nothing else this PR serves as a proof of concept and opens the conversation to this feature.
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.
@nathanjosiah, by insufficient escapement
do you mean how it assumes that the array members are string
s?
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.
@KevinBKozan Unless multidimensional arrays have a use case then I'm not thinking as much about that. I was thinking more about if the items contain quotes or $
. The resulting Codception unit test would potentially be malformed or inadvertently contain PHP variable interpolation.
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.
Gotcha. Let me leave some review comments on some small stuff then!
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.
Two small changes requested, but otherwise good work and thank you for diving into it!
@@ -496,6 +496,10 @@ private function findAndReplaceReferences($objectHandler, $inputString) | |||
|
|||
$replacement = $this->resolveParameterization($parameterized, $replacement, $match, $obj); | |||
|
|||
if (is_array($replacement)) { | |||
$replacement = '["' . implode('","', $replacement) . '"]'; |
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.
We should array_walk/array_map with addSlashes
to break quotes at the very least. Inadvertend variable interpolation in MFTF is not yet handled, so this is not introducing anything new.
@@ -496,6 +496,10 @@ private function findAndReplaceReferences($objectHandler, $inputString) | |||
|
|||
$replacement = $this->resolveParameterization($parameterized, $replacement, $match, $obj); | |||
|
|||
if (is_array($replacement)) { |
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 check should either live in the elseif block in 497, or in the resolveEntityDataObjectReference()
function. This conditional only ever applies to EntityDataObjects, so checking it every time is unecessary.
@KevinBKozan I updated my branch with the requested changed and merged mainline and ran tests to verify current compatibility. |
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.
Wasn't very clear in my first feedback, my apologies. Still need to move the new conditional.
@@ -504,6 +504,9 @@ private function findAndReplaceReferences($objectHandler, $inputString) | |||
throw new TestReferenceException("Could not resolve entity reference " . $inputString); | |||
} | |||
} | |||
elseif (is_array($replacement)) { | |||
$replacement = '["' . implode('","', array_map('addSlashes',$replacement)) . '"]'; |
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.
@nathanjosiah my bad, I don't think I was very clear about this portion. I meant that your addition should be entirely inside the elseif
on line 496; that elseif
is the portion that deals with the object passed in being an EntityDataObject
. Since the only time $replacement
could only ever be an array
is if it's an array inside an EntityDataObject
, we should only every have to check it inside that conditional.
Does that make sense?
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.
@KevinBKozan Ah, yes I see what you mean. I have pushed an updated.
@KevinBKozan I have updated the code and the Travis build is now passing. |
@nathanjosiah Awesome. Code additions look good and all the builds are passing, thank you very much for the contribution! |
…2-functional-testing-framework-843 [Imported] MFTF-33305: Eliminate AspectMock from ObjectExtensionUtilTest
Added support for passing array entities as arguments.
Description
As a Test Engineer I want to pass data entity arrays as arguments so that don't have to use hard-coded flat arrays.
For example:
The Entity
The ActionGroup
The Test
Contribution checklist