8
8
namespace tests \unit \Magento \FunctionalTestFramework \Util ;
9
9
10
10
use Exception ;
11
+ use Magento \FunctionalTestingFramework \Config \MftfApplicationConfig ;
11
12
use Magento \FunctionalTestingFramework \Exceptions \TestReferenceException ;
12
13
use Magento \FunctionalTestingFramework \Filter \FilterList ;
13
14
use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
14
15
use Magento \FunctionalTestingFramework \Test \Objects \TestHookObject ;
15
16
use Magento \FunctionalTestingFramework \Test \Objects \TestObject ;
16
17
use Magento \FunctionalTestingFramework \Util \Filesystem \CestFileCreatorUtil ;
18
+ use Magento \FunctionalTestingFramework \Util \GenerationErrorHandler ;
19
+ use Magento \FunctionalTestingFramework \Util \TestGenerator ;
17
20
use ReflectionProperty ;
18
21
use tests \unit \Util \MagentoTestCase ;
19
- use Magento \FunctionalTestingFramework \Util \TestGenerator ;
20
- use Magento \FunctionalTestingFramework \Config \MftfApplicationConfig ;
21
22
use tests \unit \Util \TestLoggingUtil ;
22
- use Magento \FunctionalTestingFramework \Util \GenerationErrorHandler ;
23
23
24
24
class TestGeneratorTest extends MagentoTestCase
25
25
{
26
26
/**
27
27
* Before method functionality.
28
+ *
29
+ * @return void
28
30
*/
29
- public function setUp (): void
31
+ protected function setUp (): void
30
32
{
31
33
TestLoggingUtil::getInstance ()->setMockLoggingUtil ();
32
34
}
@@ -36,7 +38,7 @@ public function setUp(): void
36
38
*
37
39
* @return void
38
40
*/
39
- public function tearDown (): void
41
+ protected function tearDown (): void
40
42
{
41
43
GenerationErrorHandler::getInstance ()->reset ();
42
44
}
@@ -53,12 +55,12 @@ public function testEntityException(): void
53
55
'userInput ' => '{{someEntity.entity}} '
54
56
]);
55
57
56
- $ testObject = new TestObject (" sampleTest " , [" merge123 " => $ actionObject ], [], [], " filename " );
57
- $ testGeneratorObject = TestGenerator::getInstance ("" , [" sampleTest " => $ testObject ]);
58
+ $ testObject = new TestObject (' sampleTest ' , [' merge123 ' => $ actionObject ], [], [], ' filename ' );
59
+ $ testGeneratorObject = TestGenerator::getInstance ('' , [' sampleTest ' => $ testObject ]);
58
60
$ testGeneratorObject ->createAllTestFiles (null , []);
59
61
60
62
// assert that no exception for createAllTestFiles and generation error is stored in GenerationErrorHandler
61
- $ errorMessage = '/ ' . preg_quote (" Removed invalid test object sampleTest " ) . '/ ' ;
63
+ $ errorMessage = '/ ' . preg_quote (' Removed invalid test object sampleTest ' ) . '/ ' ;
62
64
TestLoggingUtil::getInstance ()->validateMockLogStatmentRegex ('error ' , $ errorMessage , []);
63
65
$ testErrors = GenerationErrorHandler::getInstance ()->getErrorsByType ('test ' );
64
66
$ this ->assertArrayHasKey ('sampleTest ' , $ testErrors );
@@ -78,9 +80,9 @@ public function testSkippedNoGeneration(): void
78
80
]);
79
81
80
82
$ annotations = ['skip ' => ['issue ' ]];
81
- $ testObject = new TestObject (" sampleTest " , [" merge123 " => $ actionObject ], $ annotations , [], " filename " );
83
+ $ testObject = new TestObject (' sampleTest ' , [' merge123 ' => $ actionObject ], $ annotations , [], ' filename ' );
82
84
83
- $ testGeneratorObject = TestGenerator::getInstance ("" , [" sampleTest " => $ testObject ]);
85
+ $ testGeneratorObject = TestGenerator::getInstance ('' , [' sampleTest ' => $ testObject ]);
84
86
$ output = $ testGeneratorObject ->assembleTestPhp ($ testObject );
85
87
86
88
$ this ->assertStringContainsString ('This test is skipped ' , $ output );
@@ -97,7 +99,7 @@ public function testAllowSkipped(): void
97
99
{
98
100
// Mock allowSkipped for TestGenerator
99
101
$ mockConfig = $ this ->createMock (MftfApplicationConfig::class);
100
- $ mockConfig-> expects ( $ this -> any ())
102
+ $ mockConfig
101
103
->method ('allowSkipped ' )
102
104
->willReturn (true );
103
105
@@ -115,16 +117,16 @@ public function testAllowSkipped(): void
115
117
]);
116
118
117
119
$ annotations = ['skip ' => ['issue ' ]];
118
- $ beforeHook = new TestHookObject (" before " , " sampleTest " , ['beforeAction ' => $ beforeActionObject ]);
120
+ $ beforeHook = new TestHookObject (' before ' , ' sampleTest ' , ['beforeAction ' => $ beforeActionObject ]);
119
121
$ testObject = new TestObject (
120
- " sampleTest " ,
121
- [" fakeAction " => $ actionObject ],
122
+ ' sampleTest ' ,
123
+ [' fakeAction ' => $ actionObject ],
122
124
$ annotations ,
123
- [" before " => $ beforeHook ],
124
- " filename "
125
+ [' before ' => $ beforeHook ],
126
+ ' filename '
125
127
);
126
128
127
- $ testGeneratorObject = TestGenerator::getInstance ("" , [" sampleTest " => $ testObject ]);
129
+ $ testGeneratorObject = TestGenerator::getInstance ('' , [' sampleTest ' => $ testObject ]);
128
130
$ output = $ testGeneratorObject ->assembleTestPhp ($ testObject );
129
131
130
132
$ this ->assertStringNotContainsString ('This test is skipped ' , $ output );
@@ -141,8 +143,10 @@ public function testAllowSkipped(): void
141
143
public function testFilter (): void
142
144
{
143
145
$ mockConfig = $ this ->createMock (MftfApplicationConfig::class);
144
- $ fileList = new FilterList (['severity ' => ["CRITICAL " ]]);
145
- $ mockConfig ->expects ($ this ->once ())->method ('getFilterList ' )->willReturn ($ fileList );
146
+ $ fileList = new FilterList (['severity ' => ['CRITICAL ' ]]);
147
+ $ mockConfig
148
+ ->method ('getFilterList ' )
149
+ ->willReturn ($ fileList );
146
150
147
151
$ property = new ReflectionProperty (MftfApplicationConfig::class, 'MFTF_APPLICATION_CONTEXT ' );
148
152
$ property ->setAccessible (true );
@@ -156,24 +160,24 @@ public function testFilter(): void
156
160
$ annotation1 = ['severity ' => ['CRITICAL ' ]];
157
161
$ annotation2 = ['severity ' => ['MINOR ' ]];
158
162
$ test1 = new TestObject (
159
- " test1 " ,
160
- [" fakeAction " => $ actionObject ],
163
+ ' test1 ' ,
164
+ [' fakeAction ' => $ actionObject ],
161
165
$ annotation1 ,
162
166
[],
163
- " filename "
167
+ ' filename '
164
168
);
165
169
$ test2 = new TestObject (
166
- " test2 " ,
167
- [" fakeAction " => $ actionObject ],
170
+ ' test2 ' ,
171
+ [' fakeAction ' => $ actionObject ],
168
172
$ annotation2 ,
169
173
[],
170
- " filename "
174
+ ' filename '
171
175
);
172
176
173
177
// Mock createCestFile to return name of tests that testGenerator tried to create
174
178
$ generatedTests = [];
175
179
$ cestFileCreatorUtil = $ this ->createMock (CestFileCreatorUtil::class);
176
- $ cestFileCreatorUtil-> expects ( $ this -> once ())
180
+ $ cestFileCreatorUtil
177
181
->method ('create ' )
178
182
->will (
179
183
$ this ->returnCallback (
@@ -187,11 +191,27 @@ function ($filename) use (&$generatedTests) {
187
191
$ property ->setAccessible (true );
188
192
$ property ->setValue ($ cestFileCreatorUtil );
189
193
190
- $ testGeneratorObject = TestGenerator::getInstance ("" , [" sampleTest " => $ test1 , " test2 " => $ test2 ]);
194
+ $ testGeneratorObject = TestGenerator::getInstance ('' , [' sampleTest ' => $ test1 , ' test2 ' => $ test2 ]);
191
195
$ testGeneratorObject ->createAllTestFiles ();
192
196
193
197
// Ensure Test1 was Generated but not Test 2
194
198
$ this ->assertArrayHasKey ('test1Cest ' , $ generatedTests );
195
199
$ this ->assertArrayNotHasKey ('test2Cest ' , $ generatedTests );
196
200
}
201
+
202
+ /**
203
+ * @inheritDoc
204
+ */
205
+ public static function tearDownAfterClass (): void
206
+ {
207
+ parent ::tearDownAfterClass ();
208
+
209
+ $ cestFileCreatorUtilInstance = new ReflectionProperty (CestFileCreatorUtil::class, 'INSTANCE ' );
210
+ $ cestFileCreatorUtilInstance ->setAccessible (true );
211
+ $ cestFileCreatorUtilInstance ->setValue (null );
212
+
213
+ $ mftfAppConfigInstance = new ReflectionProperty (MftfApplicationConfig::class, 'MFTF_APPLICATION_CONTEXT ' );
214
+ $ mftfAppConfigInstance ->setAccessible (true );
215
+ $ mftfAppConfigInstance ->setValue (null );
216
+ }
197
217
}
0 commit comments