-
Notifications
You must be signed in to change notification settings - Fork 136
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
33295: Eliminate AspectMock from FileStorageTest #842
33295: Eliminate AspectMock from FileStorageTest #842
Conversation
Hello @karyna-tsymbal-atwix |
efb91f5
to
e8bbf77
Compare
@magento import pull request to https://github.com/magento-commerce/magento2-functional-testing-framework |
@jilu1 the pull request successfully imported. |
Hello, @jilu1 This task was finished without creating new singletons, so it is not a blocker. Thanks, Bohdan |
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.
@karyna-tsymbal-atwix
Thank you for your contribution!
This change looks good to me.
* @throws TestFrameworkException | ||
*/ | ||
public function __construct() | ||
private function initialize(): void |
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.
@karyna-tsymbal-atwix
Can we try not to change the constructor to initialize()? Do you have some hard dependencies that are difficult to mock?
If it's difficult to find other solutions, please make sure initialization is done properly here:
private function initializeFileStorage()
{
// Initialize file storage
try {
$this->credStorage[self::ARRAY_KEY_FOR_FILE] = new FileStorage();
} catch (TestFrameworkException $e) {
// Print error message in console
print_r($e->getMessage());
// Save to exception context for Allure report
$this->setExceptionContexts(self::ARRAY_KEY_FOR_FILE, $e->getMessage());
}
}
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.
Hi @jilu1 , the problem here is that we need real private methods from the constructor to be executed (including parent constructor), but with our test credentials here https://github.com/magento/magento2-functional-testing-framework/pull/842/files#diff-ae8cfe83e67da69395e70368c54[…]25516f88e60225a94aa557060dda04L31
I didn't find a proper way to avoid calling a real constructor and execute parent constructor&private methods from constructor, at the same time.
Regarding your question about initializeFileStorage() method - I was checking it's usages, and I think it should be ok.
In the FileStorage class, an entry point is getEncryptedValue() method. I think it's the only case when we need those methods from constructor (which I moved to initialize()) to be executed.
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.
@karyna-tsymbal-atwix
I am ok with using initialize() if there is no easy to mock private method in this case.
Practically getEncryptedValue() is the only entry point with the assumption that other public methods inherited from base class should be called after, but logically initialize() should be called right after FileStorage instantiation in initializeFileStorage() here
Line 228 in 6042aea
$this->credStorage[self::ARRAY_KEY_FOR_FILE] = new FileStorage(); |
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.
@jilu1 PR is updated with your suggestion, thank you
6563d30
Eliminated AspectMock usage from
dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/SecretStorage/FileStorageTest.php
note: in this case, main complexity is in a private functions calls rather than static
Fixed Issues (if relevant)
Contribution checklist