Skip to content

Commit 254b9b6

Browse files
authored
Merge branch 'develop' into imported-magento-magento2-functional-testing-framework-850
2 parents 43f9436 + 01d02e5 commit 254b9b6

File tree

4 files changed

+112
-60
lines changed

4 files changed

+112
-60
lines changed

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
"csharpru/vault-php": "^4.2.1",
2626
"csharpru/vault-php-guzzle6-transport": "^2.0",
2727
"hoa/console": "~3.0",
28-
"monolog/monolog": "^2.2",
28+
"monolog/monolog": "^2.3",
2929
"mustache/mustache": "~2.5",
30+
"nikic/php-parser": "^4.4",
3031
"php-webdriver/webdriver": "^1.9.0",
3132
"spomky-labs/otphp": "^10.0",
3233
"symfony/console": "^4.4",
@@ -35,8 +36,7 @@
3536
"symfony/mime": "^5.0",
3637
"symfony/process": "^4.4",
3738
"vlucas/phpdotenv": "^2.4",
38-
"weew/helpers-array": "^1.3",
39-
"nikic/php-parser": "^4.4"
39+
"weew/helpers-array": "^1.3"
4040
},
4141
"require-dev": {
4242
"brainmaestro/composer-git-hooks": "^2.3.1",

composer.lock

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php

+85-30
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,46 @@
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\Console;
79

8-
use AspectMock\Test as AspectMock;
9-
use PHPUnit\Framework\TestCase;
10+
use Exception;
1011
use Magento\FunctionalTestingFramework\Console\BaseGenerateCommand;
11-
use Magento\FunctionalTestingFramework\Suite\Objects\SuiteObject;
1212
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
13-
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
13+
use Magento\FunctionalTestingFramework\Suite\Objects\SuiteObject;
1414
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
15+
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
16+
use PHPUnit\Framework\TestCase;
17+
use ReflectionClass;
18+
use ReflectionException;
19+
use ReflectionProperty;
1520

1621
class BaseGenerateCommandTest extends TestCase
1722
{
18-
public function tearDown(): void
23+
/**
24+
* @inheritDoc
25+
*/
26+
protected function tearDown(): void
1927
{
20-
AspectMock::clean();
28+
$handler = TestObjectHandler::getInstance();
29+
$testsProperty = new ReflectionProperty(TestObjectHandler::class, 'tests');
30+
$testsProperty->setAccessible(true);
31+
$testsProperty->setValue($handler, []);
32+
$testObjectHandlerProperty = new ReflectionProperty(TestObjectHandler::class, 'testObjectHandler');
33+
$testObjectHandlerProperty->setAccessible(true);
34+
$testObjectHandlerProperty->setValue($handler);
35+
36+
$handler = SuiteObjectHandler::getInstance();
37+
$suiteObjectsProperty = new ReflectionProperty(SuiteObjectHandler::class, 'suiteObjects');
38+
$suiteObjectsProperty->setAccessible(true);
39+
$suiteObjectsProperty->setValue($handler, []);
40+
$suiteObjectHandlerProperty = new ReflectionProperty(SuiteObjectHandler::class, 'instance');
41+
$suiteObjectHandlerProperty->setAccessible(true);
42+
$suiteObjectHandlerProperty->setValue($handler);
2143
}
2244

23-
public function testOneTestOneSuiteConfig()
45+
public function testOneTestOneSuiteConfig(): void
2446
{
2547
$testOne = new TestObject('Test1', [], [], []);
2648
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []);
@@ -35,7 +57,7 @@ public function testOneTestOneSuiteConfig()
3557
$this->assertEquals($expected, $actual);
3658
}
3759

38-
public function testOneTestTwoSuitesConfig()
60+
public function testOneTestTwoSuitesConfig(): void
3961
{
4062
$testOne = new TestObject('Test1', [], [], []);
4163
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []);
@@ -51,7 +73,7 @@ public function testOneTestTwoSuitesConfig()
5173
$this->assertEquals($expected, $actual);
5274
}
5375

54-
public function testOneTestOneGroup()
76+
public function testOneTestOneGroup(): void
5577
{
5678
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
5779

@@ -65,7 +87,7 @@ public function testOneTestOneGroup()
6587
$this->assertEquals($expected, $actual);
6688
}
6789

68-
public function testThreeTestsTwoGroup()
90+
public function testThreeTestsTwoGroup(): void
6991
{
7092
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
7193
$testTwo = new TestObject('Test2', [], ['group' => ['Group1']], []);
@@ -81,7 +103,7 @@ public function testThreeTestsTwoGroup()
81103
$this->assertEquals($expected, $actual);
82104
}
83105

84-
public function testOneTestOneSuiteOneGroupConfig()
106+
public function testOneTestOneSuiteOneGroupConfig(): void
85107
{
86108
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
87109
$suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []);
@@ -96,7 +118,7 @@ public function testOneTestOneSuiteOneGroupConfig()
96118
$this->assertEquals($expected, $actual);
97119
}
98120

99-
public function testTwoTestOneSuiteTwoGroupConfig()
121+
public function testTwoTestOneSuiteTwoGroupConfig(): void
100122
{
101123
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
102124
$testTwo = new TestObject('Test2', [], ['group' => ['Group2']], []);
@@ -112,7 +134,7 @@ public function testTwoTestOneSuiteTwoGroupConfig()
112134
$this->assertEquals($expected, $actual);
113135
}
114136

115-
public function testTwoTestTwoSuiteOneGroupConfig()
137+
public function testTwoTestTwoSuiteOneGroupConfig(): void
116138
{
117139
$testOne = new TestObject('Test1', [], ['group' => ['Group1']], []);
118140
$testTwo = new TestObject('Test2', [], ['group' => ['Group1']], []);
@@ -131,10 +153,12 @@ public function testTwoTestTwoSuiteOneGroupConfig()
131153

132154
/**
133155
* Test specific usecase of a test that is in a group with the group being called along with the suite
134-
* i.e. run:group Group1 Suite1
135-
* @throws \Exception
156+
* i.e. run:group Group1 Suite1.
157+
*
158+
* @return void
159+
* @throws Exception
136160
*/
137-
public function testThreeTestOneSuiteOneGroupMix()
161+
public function testThreeTestOneSuiteOneGroupMix(): void
138162
{
139163
$testOne = new TestObject('Test1', [], [], []);
140164
$testTwo = new TestObject('Test2', [], [], []);
@@ -156,7 +180,7 @@ public function testThreeTestOneSuiteOneGroupMix()
156180
$this->assertEquals($expected, $actual);
157181
}
158182

159-
public function testSuiteToTestSyntax()
183+
public function testSuiteToTestSyntax(): void
160184
{
161185
$testOne = new TestObject('Test1', [], [], []);
162186
$suiteOne = new SuiteObject(
@@ -175,51 +199,82 @@ public function testSuiteToTestSyntax()
175199
}
176200

177201
/**
178-
* Mock handlers to skip parsing
202+
* Mock handlers to skip parsing.
203+
*
179204
* @param array $testArray
180205
* @param array $suiteArray
181-
* @throws \Exception
206+
*
207+
* @return void
208+
* @throws Exception
182209
*/
183-
public function mockHandlers($testArray, $suiteArray)
210+
public function mockHandlers(array $testArray, array $suiteArray): void
184211
{
185-
AspectMock::double(TestObjectHandler::class, ['initTestData' => ''])->make();
212+
// bypass the initTestData method
213+
$testObjectHandlerClass = new ReflectionClass(TestObjectHandler::class);
214+
$constructor = $testObjectHandlerClass->getConstructor();
215+
$constructor->setAccessible(true);
216+
$testObjectHandlerObject = $testObjectHandlerClass->newInstanceWithoutConstructor();
217+
$constructor->invoke($testObjectHandlerObject);
218+
219+
$testObjectHandlerProperty = new ReflectionProperty(TestObjectHandler::class, 'testObjectHandler');
220+
$testObjectHandlerProperty->setAccessible(true);
221+
$testObjectHandlerProperty->setValue($testObjectHandlerObject);
222+
186223
$handler = TestObjectHandler::getInstance();
187-
$property = new \ReflectionProperty(TestObjectHandler::class, 'tests');
224+
$property = new ReflectionProperty(TestObjectHandler::class, 'tests');
188225
$property->setAccessible(true);
189226
$property->setValue($handler, $testArray);
190227

191-
AspectMock::double(SuiteObjectHandler::class, ['initSuiteData' => ''])->make();
228+
// bypass the initTestData method
229+
$suiteObjectHandlerClass = new ReflectionClass(SuiteObjectHandler::class);
230+
$constructor = $suiteObjectHandlerClass->getConstructor();
231+
$constructor->setAccessible(true);
232+
$suiteObjectHandlerObject = $suiteObjectHandlerClass->newInstanceWithoutConstructor();
233+
$constructor->invoke($suiteObjectHandlerObject);
234+
235+
$suiteObjectHandlerProperty = new ReflectionProperty(SuiteObjectHandler::class, 'instance');
236+
$suiteObjectHandlerProperty->setAccessible(true);
237+
$suiteObjectHandlerProperty->setValue($suiteObjectHandlerObject);
238+
192239
$handler = SuiteObjectHandler::getInstance();
193-
$property = new \ReflectionProperty(SuiteObjectHandler::class, 'suiteObjects');
240+
$property = new ReflectionProperty(SuiteObjectHandler::class, 'suiteObjects');
194241
$property->setAccessible(true);
195242
$property->setValue($handler, $suiteArray);
196243
}
197244

198245
/**
199-
* Changes visibility and runs getTestAndSuiteConfiguration
246+
* Changes visibility and runs getTestAndSuiteConfiguration.
247+
*
200248
* @param array $testArray
249+
*
201250
* @return string
251+
* @throws ReflectionException
202252
*/
203-
public function callTestConfig($testArray)
253+
public function callTestConfig(array $testArray): string
204254
{
205255
$command = new BaseGenerateCommand();
206-
$class = new \ReflectionClass($command);
256+
$class = new ReflectionClass($command);
207257
$method = $class->getMethod('getTestAndSuiteConfiguration');
208258
$method->setAccessible(true);
259+
209260
return $method->invokeArgs($command, [$testArray]);
210261
}
211262

212263
/**
213-
* Changes visibility and runs getGroupAndSuiteConfiguration
264+
* Changes visibility and runs getGroupAndSuiteConfiguration.
265+
*
214266
* @param array $groupArray
267+
*
215268
* @return string
269+
* @throws ReflectionException
216270
*/
217-
public function callGroupConfig($groupArray)
271+
public function callGroupConfig(array $groupArray): string
218272
{
219273
$command = new BaseGenerateCommand();
220-
$class = new \ReflectionClass($command);
274+
$class = new ReflectionClass($command);
221275
$method = $class->getMethod('getGroupAndSuiteConfiguration');
222276
$method->setAccessible(true);
277+
223278
return $method->invokeArgs($command, [$groupArray]);
224279
}
225280
}

dev/tests/unit/Magento/FunctionalTestFramework/Util/GenerationErrorHandlerTest.php

+16-19
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
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\Util;
89

9-
use AspectMock\Test as AspectMock;
10+
use ReflectionProperty;
1011
use tests\unit\Util\MagentoTestCase;
1112
use Magento\FunctionalTestingFramework\Util\GenerationErrorHandler;
1213
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
@@ -21,10 +22,9 @@ class GenerationErrorHandlerTest extends MagentoTestCase
2122
*/
2223
public function testGetDistinctErrors()
2324
{
24-
AspectMock::double(
25-
MftfApplicationConfig::class,
26-
['getPhase' => MftfApplicationConfig::GENERATION_PHASE]
27-
);
25+
$this->createMock(MftfApplicationConfig::class)
26+
->method('getPhase')
27+
->willReturn(MftfApplicationConfig::GENERATION_PHASE);
2828

2929
$expectedAllErrors = [
3030
'test' => [
@@ -79,10 +79,9 @@ public function testGetDistinctErrors()
7979
*/
8080
public function testGetErrorsWithSameKey()
8181
{
82-
AspectMock::double(
83-
MftfApplicationConfig::class,
84-
['getPhase' => MftfApplicationConfig::GENERATION_PHASE]
85-
);
82+
$this->createMock(MftfApplicationConfig::class)
83+
->method('getPhase')
84+
->willReturn(MftfApplicationConfig::GENERATION_PHASE);
8685

8786
$expectedAllErrors = [
8887
'test' => [
@@ -163,10 +162,9 @@ public function testGetErrorsWithSameKey()
163162
*/
164163
public function testGetAllErrorsDuplicate()
165164
{
166-
AspectMock::double(
167-
MftfApplicationConfig::class,
168-
['getPhase' => MftfApplicationConfig::GENERATION_PHASE]
169-
);
165+
$this->createMock(MftfApplicationConfig::class)
166+
->method('getPhase')
167+
->willReturn(MftfApplicationConfig::GENERATION_PHASE);
170168

171169
$expectedAllErrors = [
172170
'test' => [
@@ -254,7 +252,7 @@ public function testGetAllErrorMessages($expectedErrMessages, $errors)
254252
$handler = GenerationErrorHandler::getInstance();
255253
$handler->reset();
256254

257-
$property = new \ReflectionProperty(GenerationErrorHandler::class, 'errors');
255+
$property = new ReflectionProperty(GenerationErrorHandler::class, 'errors');
258256
$property->setAccessible(true);
259257
$property->setValue($handler, $errors);
260258

@@ -334,10 +332,9 @@ public function getAllErrorMessagesDataProvider()
334332
*/
335333
public function testResetError()
336334
{
337-
AspectMock::double(
338-
MftfApplicationConfig::class,
339-
['getPhase' => MftfApplicationConfig::GENERATION_PHASE]
340-
);
335+
$this->createMock(MftfApplicationConfig::class)
336+
->method('getPhase')
337+
->willReturn(MftfApplicationConfig::GENERATION_PHASE);
341338

342339
GenerationErrorHandler::getInstance()->addError('something', 'some', 'error');
343340
GenerationErrorHandler::getInstance()->addError('otherthing', 'other', 'error');
@@ -353,7 +350,7 @@ public function testResetError()
353350

354351
public function tearDown(): void
355352
{
356-
$property = new \ReflectionProperty(GenerationErrorHandler::class, 'instance');
353+
$property = new ReflectionProperty(GenerationErrorHandler::class, 'instance');
357354
$property->setAccessible(true);
358355
$property->setValue(null);
359356
}

0 commit comments

Comments
 (0)