-
Notifications
You must be signed in to change notification settings - Fork 132
33309: Eliminated AspectMock usage from TestGeneratorTest.php #850
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
magento-devops-reposync-svc
merged 3 commits into
magento:develop
from
anzin:improvement/mftf-33309-eliminate-aspect-mock-from-test-generator-test
Jul 29, 2021
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/Magento/FunctionalTestingFramework/Util/Filesystem/CestFileCreatorUtil.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\FunctionalTestingFramework\Util\Filesystem; | ||
|
||
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException; | ||
|
||
class CestFileCreatorUtil | ||
{ | ||
/** | ||
* Singleton CestFileCreatorUtil Instance. | ||
* | ||
* @var CestFileCreatorUtil | ||
*/ | ||
private static $INSTANCE; | ||
|
||
/** | ||
* CestFileCreatorUtil constructor. | ||
*/ | ||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* Get CestFileCreatorUtil instance. | ||
* | ||
* @return CestFileCreatorUtil | ||
*/ | ||
public static function getInstance() | ||
{ | ||
if (self::$INSTANCE === null) { | ||
return new self(); | ||
} | ||
|
||
return self::$INSTANCE; | ||
} | ||
|
||
/** | ||
* Create a single PHP file containing the $cestPhp using the $filename. | ||
* If the _generated directory doesn't exist it will be created. | ||
* | ||
* @param string $filename | ||
* @param string $exportDirectory | ||
* @param string $testPhp | ||
* | ||
* @return void | ||
* @throws TestFrameworkException | ||
*/ | ||
public function create(string $filename, string $exportDirectory, string $testPhp): void | ||
{ | ||
DirSetupUtil::createGroupDir($exportDirectory); | ||
$exportFilePath = $exportDirectory . DIRECTORY_SEPARATOR . $filename . '.php'; | ||
$file = fopen($exportFilePath, 'w'); | ||
|
||
if (!$file) { | ||
throw new TestFrameworkException( | ||
sprintf('Could not open test file: "%s"', $exportFilePath) | ||
); | ||
} | ||
|
||
fwrite($file, $testPhp); | ||
fclose($file); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 like the idea of pulling some code out of TestGenerator, but I don't think that creating a singleton that hold no data for a single utility function makes sense.
I would sooner that they change the visibility of
createCestFile
to public and mock that method instead. This is a lot of code to introduce to mock a single method.Uh oh!
There was an error while loading. Please reload this page.
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, as for me, in general, the composition is much better than big classes with a variety of functions.
@jilu1, what do you think about that concrete case?
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.
cc. @andrewbess
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.
@bohdan-harniuk Yeah, I see your point in that. I'm just vigilant about creating any classes that will perpetually live in memory, but I suppose that's not much of a concern if there's not a large amount of data being held.
I'm happy to defer to @jilu1 's original review in this case, I'll approve this and we can merge it.