|
8 | 8 |
|
9 | 9 | use AspectMock\Test as AspectMock;
|
10 | 10 |
|
| 11 | +use Magento\FunctionalTestingFramework\Filter\FilterList; |
11 | 12 | use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
|
12 | 13 | use Magento\FunctionalTestingFramework\Test\Objects\TestHookObject;
|
13 | 14 | use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
|
|
17 | 18 |
|
18 | 19 | class TestGeneratorTest extends MagentoTestCase
|
19 | 20 | {
|
| 21 | + /** |
| 22 | + * After method functionality |
| 23 | + * |
| 24 | + * @return void |
| 25 | + */ |
| 26 | + public function tearDown() |
| 27 | + { |
| 28 | + AspectMock::clean(); |
| 29 | + } |
| 30 | + |
20 | 31 | /**
|
21 | 32 | * Basic test to check exceptions for incorrect entities.
|
22 | 33 | *
|
@@ -99,4 +110,54 @@ public function testAllowSkipped()
|
99 | 110 | $this->assertContains($actionInput, $output);
|
100 | 111 | $this->assertContains($beforeActionInput, $output);
|
101 | 112 | }
|
| 113 | + |
| 114 | + /** |
| 115 | + * Tests that TestGenerator createAllTestFiles correctly filters based on severity |
| 116 | + * |
| 117 | + * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException |
| 118 | + */ |
| 119 | + public function testFilter() |
| 120 | + { |
| 121 | + // Mock filters for TestGenerator |
| 122 | + AspectMock::double( |
| 123 | + MftfApplicationConfig::class, |
| 124 | + ['getFilterList' => new FilterList(['severity' => ["CRITICAL"]])] |
| 125 | + ); |
| 126 | + |
| 127 | + $actionInput = 'fakeInput'; |
| 128 | + $actionObject = new ActionObject('fakeAction', 'comment', [ |
| 129 | + 'userInput' => $actionInput |
| 130 | + ]); |
| 131 | + |
| 132 | + $annotation1 = ['severity' => ['CRITICAL']]; |
| 133 | + $annotation2 = ['severity' => ['MINOR']]; |
| 134 | + $test1 = new TestObject( |
| 135 | + "test1", |
| 136 | + ["fakeAction" => $actionObject], |
| 137 | + $annotation1, |
| 138 | + [], |
| 139 | + "filename" |
| 140 | + ); |
| 141 | + $test2 = new TestObject( |
| 142 | + "test2", |
| 143 | + ["fakeAction" => $actionObject], |
| 144 | + $annotation2, |
| 145 | + [], |
| 146 | + "filename" |
| 147 | + ); |
| 148 | + AspectMock::double(TestGenerator::class, ['loadAllTestObjects' => ["sampleTest" => $test1, "test2" => $test2]]); |
| 149 | + |
| 150 | + // Mock createCestFile to return name of tests that testGenerator tried to create |
| 151 | + $generatedTests = []; |
| 152 | + AspectMock::double(TestGenerator::class, ['createCestFile' => function ($arg1, $arg2) use (&$generatedTests) { |
| 153 | + $generatedTests[$arg2] = true; |
| 154 | + }]); |
| 155 | + |
| 156 | + $testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $test1, "test2" => $test2]); |
| 157 | + $testGeneratorObject->createAllTestFiles(null, []); |
| 158 | + |
| 159 | + // Ensure Test1 was Generated but not Test 2 |
| 160 | + $this->assertArrayHasKey('test1Cest', $generatedTests); |
| 161 | + $this->assertArrayNotHasKey('test2Cest', $generatedTests); |
| 162 | + } |
102 | 163 | }
|
0 commit comments