Skip to content

Commit 9dfd3e3

Browse files
authored
Merge pull request magento#62 from magento-commerce/MQE-2683
GitHub PRs
2 parents 3729b72 + aff8802 commit 9dfd3e3

File tree

10 files changed

+93
-95
lines changed

10 files changed

+93
-95
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Config/Reader/FilesystemTest.php

+49-45
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace tests\unit\Magento\FunctionalTestFramework\Config\Reader;
79

10+
use Magento\FunctionalTestingFramework\Config\ConverterInterface;
811
use Magento\FunctionalTestingFramework\Config\FileResolver\Module;
912
use Magento\FunctionalTestingFramework\Config\Reader\Filesystem;
13+
use Magento\FunctionalTestingFramework\Config\SchemaLocatorInterface;
1014
use Magento\FunctionalTestingFramework\Config\ValidationState;
1115
use Magento\FunctionalTestingFramework\Util\Iterator\File;
16+
use PHPUnit\Framework\MockObject\MockObject;
1217
use PHPUnit\Framework\TestCase;
13-
use AspectMock\Test as AspectMock;
1418
use tests\unit\Util\TestLoggingUtil;
1519

1620
class FilesystemTest extends TestCase
1721
{
1822
/**
19-
* Before test functionality
2023
* @return void
2124
*/
2225
public function setUp(): void
@@ -25,79 +28,80 @@ public function setUp(): void
2528
}
2629

2730
/**
28-
* Test Reading Empty Files
2931
* @throws \Exception
3032
*/
3133
public function testEmptyXmlFile()
3234
{
33-
// create mocked items and read the file
34-
$someFile = $this->setMockFile("somepath.xml", "");
35-
$filesystem = $this->createPseudoFileSystem($someFile);
36-
$filesystem->read();
35+
$filesystem = $this->getFilesystem($this->getFileIterator('somepath.xml', ''));
36+
$this->assertEquals([], $filesystem->read());
3737

38-
// validate log statement
3938
TestLoggingUtil::getInstance()->validateMockLogStatement(
40-
"warning",
41-
"XML File is empty.",
42-
["File" => "somepath.xml"]
39+
'warning',
40+
'XML File is empty.',
41+
['File' => 'somepath.xml']
4342
);
4443
}
4544

4645
/**
47-
* Function used to set mock for File created in test
46+
* Retrieve mocked file iterator
4847
*
4948
* @param string $fileName
5049
* @param string $content
51-
* @return object
50+
* @return File|MockObject
5251
* @throws \Exception
5352
*/
54-
public function setMockFile($fileName, $content)
53+
public function getFileIterator(string $fileName, string $content): File
5554
{
56-
$file = AspectMock::double(
57-
File::class,
58-
[
59-
'current' => "",
60-
'count' => 1,
61-
'getFilename' => $fileName
62-
]
63-
)->make();
55+
$iterator = new \ArrayIterator([$content]);
56+
57+
$file = $this->createMock(File::class);
58+
59+
$file->method('current')
60+
->willReturn($content);
61+
$file->method('getFilename')
62+
->willReturn($fileName);
63+
$file->method('count')
64+
->willReturn(1);
65+
66+
$file->method('next')
67+
->willReturnCallback(function () use ($iterator): void {
68+
$iterator->next();
69+
});
6470

65-
//set mocked data property for File
66-
$property = new \ReflectionProperty(File::class, 'data');
67-
$property->setAccessible(true);
68-
$property->setValue($file, [$fileName => $content]);
71+
$file->method('valid')
72+
->willReturnCallback(function () use ($iterator): bool {
73+
return $iterator->valid();
74+
});
6975

7076
return $file;
7177
}
7278

7379
/**
74-
* Function used to set mock for filesystem class during test
80+
* Get real instance of Filesystem class with mocked dependencies
7581
*
76-
* @param string $fileList
77-
* @return object
78-
* @throws \Exception
82+
* @param File $fileIterator
83+
* @return Filesystem
7984
*/
80-
public function createPseudoFileSystem($fileList)
85+
public function getFilesystem(File $fileIterator): Filesystem
8186
{
82-
$filesystem = AspectMock::double(Filesystem::class)->make();
83-
84-
//set resolver to use mocked resolver
85-
$mockFileResolver = AspectMock::double(Module::class, ['get' => $fileList])->make();
86-
$property = new \ReflectionProperty(Filesystem::class, 'fileResolver');
87-
$property->setAccessible(true);
88-
$property->setValue($filesystem, $mockFileResolver);
89-
90-
//set validator to use mocked validator
91-
$mockValidation = AspectMock::double(ValidationState::class, ['isValidationRequired' => false])->make();
92-
$property = new \ReflectionProperty(Filesystem::class, 'validationState');
93-
$property->setAccessible(true);
94-
$property->setValue($filesystem, $mockValidation);
87+
$fileResolver = $this->createMock(Module::class);
88+
$fileResolver->method('get')
89+
->willReturn($fileIterator);
90+
$validationState = $this->createMock(ValidationState::class);
91+
$validationState->method('isValidationRequired')
92+
->willReturn(false);
93+
$filesystem = new Filesystem(
94+
$fileResolver,
95+
$this->createMock(ConverterInterface::class),
96+
$this->createMock(SchemaLocatorInterface::class),
97+
$validationState,
98+
''
99+
);
95100

96101
return $filesystem;
97102
}
98103

99104
/**
100-
* After class functionality
101105
* @return void
102106
*/
103107
public static function tearDownAfterClass(): void

dev/tests/unit/Magento/FunctionalTestFramework/StaticCheck/AnnotationsCheckTest.php

+19-29
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,27 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace tests\unit\Magento\FunctionalTestFramework\StaticCheck;
89

9-
use AspectMock\Test as AspectMock;
1010
use Magento\FunctionalTestingFramework\StaticCheck\AnnotationsCheck;
1111
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
12-
use tests\unit\Util\MagentoTestCase;
1312
use ReflectionClass;
13+
use tests\unit\Util\MagentoTestCase;
1414

1515
class AnnotationsCheckTest extends MagentoTestCase
1616
{
1717
/** @var AnnotationsCheck */
1818
private $staticCheck;
1919

20-
/** @var ReflectionClass*/
20+
/** @var ReflectionClass */
2121
private $staticCheckClass;
2222

2323
public function setUp(): void
2424
{
2525
$this->staticCheck = new AnnotationsCheck();
26-
$this->staticCheckClass = new \ReflectionClass($this->staticCheck);
27-
}
28-
29-
public function tearDown(): void
30-
{
31-
AspectMock::clean();
26+
$this->staticCheckClass = new ReflectionClass($this->staticCheck);
3227
}
3328

3429
public function testValidateRequiredAnnotationsNoError()
@@ -56,11 +51,9 @@ public function testValidateRequiredAnnotationsNoError()
5651
];
5752
$expected = [];
5853

59-
// mock test object
60-
$test = AspectMock::double(
61-
TestObject::class,
62-
['getAnnotations' => $annotations, 'getName' => 'AnnotationsCheckTest']
63-
)->make();
54+
$test = $this->createMock(TestObject::class);
55+
56+
$test->expects($this->once())->method('getAnnotations')->willReturn($annotations);
6457

6558
$validateRequiredAnnotations = $this->staticCheckClass->getMethod('validateRequiredAnnotations');
6659
$validateRequiredAnnotations->setAccessible(true);
@@ -99,11 +92,10 @@ public function testValidateRequiredAnnotationsMissing()
9992
]
10093
];
10194

102-
// mock test object
103-
$test = AspectMock::double(
104-
TestObject::class,
105-
['getAnnotations' => $annotations, 'getName' => 'AnnotationsCheckTest']
106-
)->make();
95+
$test = $this->createMock(TestObject::class);
96+
97+
$test->expects($this->once())->method('getAnnotations')->willReturn($annotations);
98+
$test->expects($this->once())->method('getName')->willReturn('AnnotationsCheckTest');
10799

108100
$validateRequiredAnnotations = $this->staticCheckClass->getMethod('validateRequiredAnnotations');
109101
$validateRequiredAnnotations->setAccessible(true);
@@ -137,11 +129,10 @@ public function testValidateRequiredAnnotationsMissingNoTestCaseId()
137129
]
138130
];
139131

140-
// mock test object
141-
$test = AspectMock::double(
142-
TestObject::class,
143-
['getAnnotations' => $annotations, 'getName' => 'AnnotationsCheckTest']
144-
)->make();
132+
$test = $this->createMock(TestObject::class);
133+
134+
$test->expects($this->once())->method('getAnnotations')->willReturn($annotations);
135+
$test->expects($this->once())->method('getName')->willReturn('AnnotationsCheckTest');
145136

146137
$validateRequiredAnnotations = $this->staticCheckClass->getMethod('validateRequiredAnnotations');
147138
$validateRequiredAnnotations->setAccessible(true);
@@ -179,11 +170,10 @@ public function testValidateRequiredAnnotationsEmpty()
179170
]
180171
];
181172

182-
// mock test object
183-
$test = AspectMock::double(
184-
TestObject::class,
185-
['getAnnotations' => $annotations, 'getName' => 'AnnotationsCheckTest']
186-
)->make();
173+
$test = $this->createMock(TestObject::class);
174+
175+
$test->expects($this->once())->method('getAnnotations')->willReturn($annotations);
176+
$test->expects($this->once())->method('getName')->willReturn('AnnotationsCheckTest');
187177

188178
$validateRequiredAnnotations = $this->staticCheckClass->getMethod('validateRequiredAnnotations');
189179
$validateRequiredAnnotations->setAccessible(true);

dev/tests/unit/Magento/FunctionalTestFramework/StaticCheck/DeprecatedEntityUsageCheckTest.php

-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace tests\unit\Magento\FunctionalTestFramework\StaticCheck;
88

9-
use AspectMock\Test as AspectMock;
109
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\OperationDefinitionObjectHandler;
1110
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
1211
use Magento\FunctionalTestingFramework\Page\Objects\ElementObject;
@@ -34,11 +33,6 @@ public function setUp(): void
3433
$this->staticCheckClass = new \ReflectionClass($this->staticCheck);
3534
}
3635

37-
public function tearDown(): void
38-
{
39-
AspectMock::clean();
40-
}
41-
4236
public function testInvalidPathOption()
4337
{
4438
$input = $this->getMockBuilder(InputInterface::class)

dev/tests/verification/Resources/BasicFunctionalTest.txt

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class BasicFunctionalTestCest
113113
$generateDateKey2 = $date->format("H:i:s");
114114

115115
$getOtp = $I->getOTP(); // stepKey: getOtp
116+
$getOtpWithInput = $I->getOTP("someInput"); // stepKey: getOtpWithInput
116117
$grabAttributeFromKey1 = $I->grabAttributeFrom(".functionalTestSelector", "someInput"); // stepKey: grabAttributeFromKey1
117118
$grabCookieKey1 = $I->grabCookie("grabCookieInput", ['domain' => 'www.google.com']); // stepKey: grabCookieKey1
118119
$grabFromCurrentUrlKey1 = $I->grabFromCurrentUrl("/grabCurrentUrl"); // stepKey: grabFromCurrentUrlKey1

dev/tests/verification/TestModule/Test/BasicFunctionalTest/BasicFunctionalTest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<generateDate date="Now" format="H:i:s" stepKey="generateDateKey"/>
7070
<generateDate date="Now" format="H:i:s" stepKey="generateDateKey2" timezone="UTC"/>
7171
<getOTP stepKey="getOtp"/>
72+
<getOTP stepKey="getOtpWithInput" userInput="someInput"/>
7273
<grabAttributeFrom selector=".functionalTestSelector" userInput="someInput" stepKey="grabAttributeFromKey1" />
7374
<grabCookie userInput="grabCookieInput" parameterArray="['domain' => 'www.google.com']" stepKey="grabCookieKey1" />
7475
<grabFromCurrentUrl regex="/grabCurrentUrl" stepKey="grabFromCurrentUrlKey1" />

src/Magento/FunctionalTestingFramework/Config/Reader/Filesystem.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected function readFiles($fileList)
148148
/** @var \Magento\FunctionalTestingFramework\Config\Dom $configMerger */
149149
$configMerger = null;
150150
$debugLevel = MftfApplicationConfig::getConfig()->getDebugLevel();
151-
foreach ($fileList as $key => $content) {
151+
foreach ($fileList as $content) {
152152
//check if file is empty and continue to next if it is
153153
if (!$this->verifyFileEmpty($content, $fileList->getFilename())) {
154154
continue;

src/Magento/FunctionalTestingFramework/DataTransport/Auth/Tfa/OTP.php

+16-11
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,47 @@ class OTP
2020
/**
2121
* TOTP object
2222
*
23-
* @var TOTP
23+
* @var TOTP[]
2424
*/
25-
private static $totp = null;
25+
private static $totps = [];
2626

2727
/**
2828
* Return OTP for custom secret stored in `magento/tfa/OTP_SHARED_SECRET`
2929
*
30+
* @param string|null $path
3031
* @return string
3132
* @throws TestFrameworkException
3233
*/
33-
public static function getOTP()
34+
public static function getOTP($path = null)
3435
{
35-
return self::create()->now();
36+
if ($path === null) {
37+
$path = self::OTP_SHARED_SECRET_PATH;
38+
}
39+
return self::create($path)->now();
3640
}
3741

3842
/**
3943
* Create TOTP object
4044
*
45+
* @param string $path
4146
* @return TOTP
4247
* @throws TestFrameworkException
4348
*/
44-
private static function create()
49+
private static function create($path)
4550
{
46-
if (self::$totp === null) {
51+
if (!isset(self::$totps[$path])) {
4752
try {
4853
// Get shared secret from Credential storage
49-
$encryptedSecret = CredentialStore::getInstance()->getSecret(self::OTP_SHARED_SECRET_PATH);
54+
$encryptedSecret = CredentialStore::getInstance()->getSecret($path);
5055
$secret = CredentialStore::getInstance()->decryptSecretValue($encryptedSecret);
5156
} catch (TestFrameworkException $e) {
5257
throw new TestFrameworkException('Unable to get OTP' . PHP_EOL . $e->getMessage());
5358
}
5459

55-
self::$totp = TOTP::create($secret);
56-
self::$totp->setIssuer('MFTF');
57-
self::$totp->setLabel('MFTF Testing');
60+
self::$totps[$path] = TOTP::create($secret);
61+
self::$totps[$path]->setIssuer('MFTF');
62+
self::$totps[$path]->setLabel('MFTF Testing');
5863
}
59-
return self::$totp;
64+
return self::$totps[$path];
6065
}
6166
}

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -970,12 +970,13 @@ public function makeScreenshot($name = null)
970970
/**
971971
* Return OTP based on a shared secret
972972
*
973+
* @param string|null $secretsPath
973974
* @return string
974975
* @throws TestFrameworkException
975976
*/
976-
public function getOTP()
977+
public function getOTP($secretsPath = null)
977978
{
978-
return OTP::getOTP();
979+
return OTP::getOTP($secretsPath);
979980
}
980981

981982
/**

src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@
335335
</xs:annotation>
336336
<xs:simpleContent>
337337
<xs:extension base="xs:string">
338+
<xs:attribute ref="userInput"/>
338339
<xs:attributeGroup ref="commonActionAttributes"/>
339340
</xs:extension>
340341
</xs:simpleContent>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,8 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
12621262
$testSteps .= $this->wrapFunctionCallWithReturnValue(
12631263
$stepKey,
12641264
$actor,
1265-
$actionObject
1265+
$actionObject,
1266+
$input
12661267
);
12671268
break;
12681269
case "resizeWindow":

0 commit comments

Comments
 (0)