Skip to content

Commit db1ce7b

Browse files
committed
MQE-999: Replace all explicit print or echo statements with logging
- add LogginUtil and monolog - remove expliclit echo/print statements - update tests - update mftf exceptions to include log statments
1 parent 57ad442 commit db1ce7b

23 files changed

+690
-119
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"epfremme/swagger-php": "^2.0",
1717
"flow/jsonpath": ">0.2",
1818
"fzaninotto/faker": "^1.6",
19+
"monolog/monolog": "^1.0",
1920
"mustache/mustache": "~2.5",
2021
"symfony/process": "^2.8 || ^3.1 || ^4.0",
2122
"vlucas/phpdotenv": "^2.4"

composer.lock

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

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Objects/EntityDataObjectTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\FunctionalTestingFramework\DataGenerator\Objects;
88

99
use PHPUnit\Framework\TestCase;
10+
use tests\unit\Util\TestLoggingUtil;
1011

1112
/**
1213
* The following function declarations override the global function_exists and declare msq/msqs for use
@@ -34,6 +35,15 @@ function msqs($id = null)
3435
*/
3536
class EntityDataObjectTest extends TestCase
3637
{
38+
/**
39+
* Before test functionality
40+
* @return void
41+
*/
42+
public function setUp()
43+
{
44+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
45+
}
46+
3747
public function testBasicGetters()
3848
{
3949
$data = ["datakey1" => "value1"];
@@ -109,4 +119,13 @@ public function testGetLinkedEntities()
109119
$this->assertEquals("linkedEntity1", $dataObject->getLinkedEntitiesOfType("linkedEntityType")[0]);
110120
$this->assertEquals("linkedEntity2", $dataObject->getLinkedEntitiesOfType("otherEntityType")[0]);
111121
}
122+
123+
/**
124+
* After class functionality
125+
* @return void
126+
*/
127+
public static function tearDownAfterClass()
128+
{
129+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
130+
}
112131
}

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Persist/OperationDataArrayResolverTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use tests\unit\Util\EntityDataObjectBuilder;
1414
use tests\unit\Util\OperationDefinitionBuilder;
1515
use tests\unit\Util\OperationElementBuilder;
16+
use tests\unit\Util\TestLoggingUtil;
1617

1718
class OperationDataArrayResolverTest extends TestCase
1819
{
@@ -35,6 +36,15 @@ class OperationDataArrayResolverTest extends TestCase
3536
]
3637
]];
3738

39+
/**
40+
* Before test functionality
41+
* @return void
42+
*/
43+
public function setUp()
44+
{
45+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
46+
}
47+
3848
/**
3949
* Test a basic metadata resolve between primitive values and a primitive data set
4050
* <object>
@@ -344,4 +354,13 @@ public function testNestedMetadataArrayOfValue()
344354
// Do assert on result here
345355
$this->assertEquals(self::NESTED_METADATA_ARRAY_RESULT, $result);
346356
}
357+
358+
/**
359+
* After class functionality
360+
* @return void
361+
*/
362+
public static function tearDownAfterClass()
363+
{
364+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
365+
}
347366
}

dev/tests/unit/Magento/FunctionalTestFramework/Suite/SuiteGeneratorTest.php

+28-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use PHPUnit\Framework\TestCase;
2020
use tests\unit\Util\SuiteDataArrayBuilder;
2121
use tests\unit\Util\TestDataArrayBuilder;
22+
use tests\unit\Util\TestLoggingUtil;
2223

2324
class SuiteGeneratorTest extends TestCase
2425
{
@@ -34,6 +35,15 @@ public static function setUpBeforeClass()
3435
]);
3536
}
3637

38+
/**
39+
* Before test functionality
40+
* @return void
41+
*/
42+
public function setUp()
43+
{
44+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
45+
}
46+
3747
/**
3848
* Tests generating a single suite given a set of parsed test data
3949
* @throws \Exception
@@ -63,7 +73,11 @@ public function testGenerateSuite()
6373
$mockSuiteGenerator->generateSuite("basicTestSuite");
6474

6575
// assert that expected suite is generated
66-
$this->expectOutputString("Suite basicTestSuite generated to _generated/basicTestSuite." . PHP_EOL);
76+
TestLoggingUtil::getInstance()->validateMockLogStatement(
77+
'info',
78+
"suite generated",
79+
['suite' => 'basicTestSuite', 'relative_path' => "_generated/basicTestSuite"]
80+
);
6781
}
6882

6983
/**
@@ -96,7 +110,11 @@ public function testGenerateAllSuites()
96110
$mockSuiteGenerator->generateAllSuites($exampleTestManifest);
97111

98112
// assert that expected suites are generated
99-
$this->expectOutputString("Suite basicTestSuite generated to _generated/basicTestSuite." . PHP_EOL);
113+
TestLoggingUtil::getInstance()->validateMockLogStatement(
114+
'info',
115+
"suite generated",
116+
['suite' => 'basicTestSuite', 'relative_path' => "_generated/basicTestSuite"]
117+
);
100118
}
101119

102120
/**
@@ -181,4 +199,12 @@ private function setMockTestAndSuiteParserOutput($testData, $suiteData)
181199
$property->setAccessible(true);
182200
$property->setValue($instance, $instance);
183201
}
202+
203+
/**
204+
* clean up function runs after all tests
205+
*/
206+
public static function tearDownAfterClass()
207+
{
208+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
209+
}
184210
}

dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionGroupObjectTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,21 @@
1818
use PHPUnit\Framework\TestCase;
1919
use tests\unit\Util\ActionGroupObjectBuilder;
2020
use tests\unit\Util\EntityDataObjectBuilder;
21+
use tests\unit\Util\TestLoggingUtil;
2122

2223
class ActionGroupObjectTest extends TestCase
2324
{
2425
const ACTION_GROUP_MERGE_KEY = 'TestKey';
2526

27+
/**
28+
* Before test functionality
29+
* @return void
30+
*/
31+
public function setUp()
32+
{
33+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
34+
}
35+
2636
/**
2737
* Tests a string literal in an action group
2838
*/
@@ -284,4 +294,13 @@ private function assertOnMergeKeyAndActionValue($actions, $expectedValue, $expec
284294
$this->assertEquals($expectedMergeKey, $action->getStepKey());
285295
$this->assertEquals($expectedValue, $action->getCustomActionAttributes());
286296
}
297+
298+
/**
299+
* After class functionality
300+
* @return void
301+
*/
302+
public static function tearDownAfterClass()
303+
{
304+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
305+
}
287306
}

dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php

+26-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@
1616
use Magento\FunctionalTestingFramework\Page\Handlers\SectionObjectHandler;
1717
use Magento\FunctionalTestingFramework\Page\Objects\SectionObject;
1818
use PHPUnit\Framework\TestCase;
19+
use tests\unit\Util\TestLoggingUtil;
1920

2021
/**
2122
* Class ActionObjectTest
2223
*/
2324
class ActionObjectTest extends TestCase
2425
{
26+
/**
27+
* Before test functionality
28+
* @return void
29+
*/
30+
public function setUp()
31+
{
32+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
33+
}
34+
2535
/**
2636
* The order offset should be 0 when the action is instantiated with 'before'
2737
*/
@@ -234,14 +244,16 @@ public function testResolveUrlWithNoAttribute()
234244
)->make(); // bypass the private constructor
235245
AspectMock::double(PageObjectHandler::class, ['getInstance' => $instance]);
236246

237-
// Expect this warning to get generated
238-
$this->expectOutputString(
239-
"WARNING: Page url attribute not found for {{PageObject}} and is required for amOnPage." . PHP_EOL
240-
);
241-
242247
// Call the method under test
243248
$actionObject->resolveReferences();
244249

250+
// Expect this warning to get generated
251+
TestLoggingUtil::getInstance()->validateMockLogStatement(
252+
"warning",
253+
"page url attribute not found and is required",
254+
['action' => $actionObject->getType(), 'url' => '{{PageObject}}', 'stepKey' => $actionObject->getStepKey()]
255+
);
256+
245257
// Verify
246258
$expected = [
247259
'url' => '{{PageObject}}'
@@ -371,4 +383,13 @@ private function mockDataHandlerWithData($dataObject)
371383
->make();
372384
AspectMock::double(DataObjectHandler::class, ['getInstance' => $dataInstance]);
373385
}
386+
387+
/**
388+
* After class functionality
389+
* @return void
390+
*/
391+
public static function tearDownAfterClass()
392+
{
393+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
394+
}
374395
}

dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionMergeUtilTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@
1313
use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor;
1414
use PHPUnit\Framework\TestCase;
1515
use tests\unit\Util\DataObjectHandlerReflectionUtil;
16+
use tests\unit\Util\TestLoggingUtil;
1617

1718
class ActionMergeUtilTest extends TestCase
1819
{
20+
/**
21+
* Before test functionality
22+
* @return void
23+
*/
24+
public function setUp()
25+
{
26+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
27+
}
28+
1929
/**
2030
* Test to validate actions are properly ordered during a merge.
2131
*
@@ -161,6 +171,14 @@ public function testInsertWait()
161171
0
162172
);
163173
$this->assertEquals($expected, $actual);
174+
}
164175

176+
/**
177+
* After class functionality
178+
* @return void
179+
*/
180+
public static function tearDownAfterClass()
181+
{
182+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
165183
}
166184
}

0 commit comments

Comments
 (0)