3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace tests \unit \Magento \FunctionalTestFramework \Util ;
8
9
9
- use AspectMock \ Test as AspectMock ;
10
-
10
+ use Exception ;
11
+ use Magento \ FunctionalTestingFramework \ Exceptions \ TestReferenceException ;
11
12
use Magento \FunctionalTestingFramework \Filter \FilterList ;
12
- use Magento \FunctionalTestingFramework \Test \Handlers \TestObjectHandler ;
13
13
use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
14
14
use Magento \FunctionalTestingFramework \Test \Objects \TestHookObject ;
15
15
use Magento \FunctionalTestingFramework \Test \Objects \TestObject ;
16
+ use Magento \FunctionalTestingFramework \Util \Filesystem \CestFileCreatorUtil ;
17
+ use ReflectionProperty ;
16
18
use tests \unit \Util \MagentoTestCase ;
17
19
use Magento \FunctionalTestingFramework \Util \TestGenerator ;
18
20
use Magento \FunctionalTestingFramework \Config \MftfApplicationConfig ;
22
24
class TestGeneratorTest extends MagentoTestCase
23
25
{
24
26
/**
25
- * Before method functionality
27
+ * Before method functionality.
26
28
*/
27
29
public function setUp (): void
28
30
{
29
31
TestLoggingUtil::getInstance ()->setMockLoggingUtil ();
30
32
}
31
33
32
34
/**
33
- * After method functionality
35
+ * After method functionality.
34
36
*
35
37
* @return void
36
38
*/
37
39
public function tearDown (): void
38
40
{
39
- AspectMock::clean ();
40
41
GenerationErrorHandler::getInstance ()->reset ();
41
42
}
42
43
43
44
/**
44
45
* Basic test to check exceptions for incorrect entities.
45
46
*
46
- * @throws \Exception
47
+ * @return void
48
+ * @throws Exception
47
49
*/
48
- public function testEntityException ()
50
+ public function testEntityException (): void
49
51
{
50
52
$ actionObject = new ActionObject ('fakeAction ' , 'comment ' , [
51
53
'userInput ' => '{{someEntity.entity}} '
52
54
]);
53
55
54
56
$ testObject = new TestObject ("sampleTest " , ["merge123 " => $ actionObject ], [], [], "filename " );
55
-
56
- AspectMock::double (TestObjectHandler::class, ['initTestData ' => '' ]);
57
-
58
57
$ testGeneratorObject = TestGenerator::getInstance ("" , ["sampleTest " => $ testObject ]);
59
-
60
- AspectMock::double (TestGenerator::class, ['loadAllTestObjects ' => ["sampleTest " => $ testObject ]]);
61
-
62
58
$ testGeneratorObject ->createAllTestFiles (null , []);
63
59
64
60
// assert that no exception for createAllTestFiles and generation error is stored in GenerationErrorHandler
@@ -69,11 +65,12 @@ public function testEntityException()
69
65
}
70
66
71
67
/**
72
- * Tests that skipped tests do not have a fully generated body
68
+ * Tests that skipped tests do not have a fully generated body.
73
69
*
74
- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
70
+ * @return void
71
+ * @throws TestReferenceException
75
72
*/
76
- public function testSkippedNoGeneration ()
73
+ public function testSkippedNoGeneration (): void
77
74
{
78
75
$ actionInput = 'fakeInput ' ;
79
76
$ actionObject = new ActionObject ('fakeAction ' , 'comment ' , [
@@ -91,14 +88,22 @@ public function testSkippedNoGeneration()
91
88
}
92
89
93
90
/**
94
- * Tests that skipped tests have a fully generated body when --allowSkipped is passed in
91
+ * Tests that skipped tests have a fully generated body when --allowSkipped is passed in.
95
92
*
96
- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
93
+ * @return void
94
+ * @throws TestReferenceException
97
95
*/
98
- public function testAllowSkipped ()
96
+ public function testAllowSkipped (): void
99
97
{
100
98
// Mock allowSkipped for TestGenerator
101
- AspectMock::double (MftfApplicationConfig::class, ['allowSkipped ' => true ]);
99
+ $ mockConfig = $ this ->createMock (MftfApplicationConfig::class);
100
+ $ mockConfig ->expects ($ this ->any ())
101
+ ->method ('allowSkipped ' )
102
+ ->willReturn (true );
103
+
104
+ $ property = new ReflectionProperty (MftfApplicationConfig::class, 'MFTF_APPLICATION_CONTEXT ' );
105
+ $ property ->setAccessible (true );
106
+ $ property ->setValue ($ mockConfig );
102
107
103
108
$ actionInput = 'fakeInput ' ;
104
109
$ actionObject = new ActionObject ('fakeAction ' , 'comment ' , [
@@ -128,17 +133,20 @@ public function testAllowSkipped()
128
133
}
129
134
130
135
/**
131
- * Tests that TestGenerator createAllTestFiles correctly filters based on severity
136
+ * Tests that TestGenerator createAllTestFiles correctly filters based on severity.
132
137
*
133
- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
138
+ * @return void
139
+ * @throws TestReferenceException
134
140
*/
135
- public function testFilter ()
141
+ public function testFilter (): void
136
142
{
137
- // Mock filters for TestGenerator
138
- AspectMock::double (
139
- MftfApplicationConfig::class,
140
- ['getFilterList ' => new FilterList (['severity ' => ["CRITICAL " ]])]
141
- );
143
+ $ mockConfig = $ this ->createMock (MftfApplicationConfig::class);
144
+ $ fileList = new FilterList (['severity ' => ["CRITICAL " ]]);
145
+ $ mockConfig ->expects ($ this ->once ())->method ('getFilterList ' )->willReturn ($ fileList );
146
+
147
+ $ property = new ReflectionProperty (MftfApplicationConfig::class, 'MFTF_APPLICATION_CONTEXT ' );
148
+ $ property ->setAccessible (true );
149
+ $ property ->setValue ($ mockConfig );
142
150
143
151
$ actionInput = 'fakeInput ' ;
144
152
$ actionObject = new ActionObject ('fakeAction ' , 'comment ' , [
@@ -161,16 +169,26 @@ public function testFilter()
161
169
[],
162
170
"filename "
163
171
);
164
- AspectMock::double (TestGenerator::class, ['loadAllTestObjects ' => ["sampleTest " => $ test1 , "test2 " => $ test2 ]]);
165
172
166
173
// Mock createCestFile to return name of tests that testGenerator tried to create
167
174
$ generatedTests = [];
168
- AspectMock::double (TestGenerator::class, ['createCestFile ' => function ($ arg1 , $ arg2 ) use (&$ generatedTests ) {
169
- $ generatedTests [$ arg2 ] = true ;
170
- }]);
175
+ $ cestFileCreatorUtil = $ this ->createMock (CestFileCreatorUtil::class);
176
+ $ cestFileCreatorUtil ->expects ($ this ->once ())
177
+ ->method ('create ' )
178
+ ->will (
179
+ $ this ->returnCallback (
180
+ function ($ filename ) use (&$ generatedTests ) {
181
+ $ generatedTests [$ filename ] = true ;
182
+ }
183
+ )
184
+ );
185
+
186
+ $ property = new ReflectionProperty (CestFileCreatorUtil::class, 'INSTANCE ' );
187
+ $ property ->setAccessible (true );
188
+ $ property ->setValue ($ cestFileCreatorUtil );
171
189
172
190
$ testGeneratorObject = TestGenerator::getInstance ("" , ["sampleTest " => $ test1 , "test2 " => $ test2 ]);
173
- $ testGeneratorObject ->createAllTestFiles (null , [] );
191
+ $ testGeneratorObject ->createAllTestFiles ();
174
192
175
193
// Ensure Test1 was Generated but not Test 2
176
194
$ this ->assertArrayHasKey ('test1Cest ' , $ generatedTests );
0 commit comments