Skip to content

MQE-999: Replace all explicit print or echo statements with logging #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"epfremme/swagger-php": "^2.0",
"flow/jsonpath": ">0.2",
"fzaninotto/faker": "^1.6",
"monolog/monolog": "^1.0",
"mustache/mustache": "~2.5",
"symfony/process": "^2.8 || ^3.1 || ^4.0",
"vlucas/phpdotenv": "^2.4"
Expand Down
78 changes: 78 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\FunctionalTestingFramework\DataGenerator\Objects;

use PHPUnit\Framework\TestCase;
use tests\unit\Util\TestLoggingUtil;

/**
* The following function declarations override the global function_exists and declare msq/msqs for use
Expand Down Expand Up @@ -34,6 +35,15 @@ function msqs($id = null)
*/
class EntityDataObjectTest extends TestCase
{
/**
* Before test functionality
* @return void
*/
public function setUp()
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
}

public function testBasicGetters()
{
$data = ["datakey1" => "value1"];
Expand Down Expand Up @@ -109,4 +119,13 @@ public function testGetLinkedEntities()
$this->assertEquals("linkedEntity1", $dataObject->getLinkedEntitiesOfType("linkedEntityType")[0]);
$this->assertEquals("linkedEntity2", $dataObject->getLinkedEntitiesOfType("otherEntityType")[0]);
}

/**
* After class functionality
* @return void
*/
public static function tearDownAfterClass()
{
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use tests\unit\Util\EntityDataObjectBuilder;
use tests\unit\Util\OperationDefinitionBuilder;
use tests\unit\Util\OperationElementBuilder;
use tests\unit\Util\TestLoggingUtil;

class OperationDataArrayResolverTest extends TestCase
{
Expand All @@ -35,6 +36,15 @@ class OperationDataArrayResolverTest extends TestCase
]
]];

/**
* Before test functionality
* @return void
*/
public function setUp()
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
}

/**
* Test a basic metadata resolve between primitive values and a primitive data set
* <object>
Expand Down Expand Up @@ -344,4 +354,13 @@ public function testNestedMetadataArrayOfValue()
// Do assert on result here
$this->assertEquals(self::NESTED_METADATA_ARRAY_RESULT, $result);
}

/**
* After class functionality
* @return void
*/
public static function tearDownAfterClass()
{
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PHPUnit\Framework\TestCase;
use tests\unit\Util\SuiteDataArrayBuilder;
use tests\unit\Util\TestDataArrayBuilder;
use tests\unit\Util\TestLoggingUtil;

class SuiteGeneratorTest extends TestCase
{
Expand All @@ -34,6 +35,15 @@ public static function setUpBeforeClass()
]);
}

/**
* Before test functionality
* @return void
*/
public function setUp()
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
}

/**
* Tests generating a single suite given a set of parsed test data
* @throws \Exception
Expand Down Expand Up @@ -63,7 +73,11 @@ public function testGenerateSuite()
$mockSuiteGenerator->generateSuite("basicTestSuite");

// assert that expected suite is generated
$this->expectOutputString("Suite basicTestSuite generated to _generated/basicTestSuite." . PHP_EOL);
TestLoggingUtil::getInstance()->validateMockLogStatement(
'info',
"suite generated",
['suite' => 'basicTestSuite', 'relative_path' => "_generated/basicTestSuite"]
);
}

/**
Expand Down Expand Up @@ -96,7 +110,11 @@ public function testGenerateAllSuites()
$mockSuiteGenerator->generateAllSuites($exampleTestManifest);

// assert that expected suites are generated
$this->expectOutputString("Suite basicTestSuite generated to _generated/basicTestSuite." . PHP_EOL);
TestLoggingUtil::getInstance()->validateMockLogStatement(
'info',
"suite generated",
['suite' => 'basicTestSuite', 'relative_path' => "_generated/basicTestSuite"]
);
}

/**
Expand Down Expand Up @@ -181,4 +199,12 @@ private function setMockTestAndSuiteParserOutput($testData, $suiteData)
$property->setAccessible(true);
$property->setValue($instance, $instance);
}

/**
* clean up function runs after all tests
*/
public static function tearDownAfterClass()
{
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@
use PHPUnit\Framework\TestCase;
use tests\unit\Util\ActionGroupObjectBuilder;
use tests\unit\Util\EntityDataObjectBuilder;
use tests\unit\Util\TestLoggingUtil;

class ActionGroupObjectTest extends TestCase
{
const ACTION_GROUP_MERGE_KEY = 'TestKey';

/**
* Before test functionality
* @return void
*/
public function setUp()
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
}

/**
* Tests a string literal in an action group
*/
Expand Down Expand Up @@ -284,4 +294,13 @@ private function assertOnMergeKeyAndActionValue($actions, $expectedValue, $expec
$this->assertEquals($expectedMergeKey, $action->getStepKey());
$this->assertEquals($expectedValue, $action->getCustomActionAttributes());
}

/**
* After class functionality
* @return void
*/
public static function tearDownAfterClass()
{
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@
use Magento\FunctionalTestingFramework\Page\Handlers\SectionObjectHandler;
use Magento\FunctionalTestingFramework\Page\Objects\SectionObject;
use PHPUnit\Framework\TestCase;
use tests\unit\Util\TestLoggingUtil;

/**
* Class ActionObjectTest
*/
class ActionObjectTest extends TestCase
{
/**
* Before test functionality
* @return void
*/
public function setUp()
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
}

/**
* The order offset should be 0 when the action is instantiated with 'before'
*/
Expand Down Expand Up @@ -234,14 +244,16 @@ public function testResolveUrlWithNoAttribute()
)->make(); // bypass the private constructor
AspectMock::double(PageObjectHandler::class, ['getInstance' => $instance]);

// Expect this warning to get generated
$this->expectOutputString(
"WARNING: Page url attribute not found for {{PageObject}} and is required for amOnPage." . PHP_EOL
);

// Call the method under test
$actionObject->resolveReferences();

// Expect this warning to get generated
TestLoggingUtil::getInstance()->validateMockLogStatement(
"warning",
"page url attribute not found and is required",
['action' => $actionObject->getType(), 'url' => '{{PageObject}}', 'stepKey' => $actionObject->getStepKey()]
);

// Verify
$expected = [
'url' => '{{PageObject}}'
Expand Down Expand Up @@ -371,4 +383,13 @@ private function mockDataHandlerWithData($dataObject)
->make();
AspectMock::double(DataObjectHandler::class, ['getInstance' => $dataInstance]);
}

/**
* After class functionality
* @return void
*/
public static function tearDownAfterClass()
{
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@
use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor;
use PHPUnit\Framework\TestCase;
use tests\unit\Util\DataObjectHandlerReflectionUtil;
use tests\unit\Util\TestLoggingUtil;

class ActionMergeUtilTest extends TestCase
{
/**
* Before test functionality
* @return void
*/
public function setUp()
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
}

/**
* Test to validate actions are properly ordered during a merge.
*
Expand Down Expand Up @@ -161,6 +171,14 @@ public function testInsertWait()
0
);
$this->assertEquals($expected, $actual);
}

/**
* After class functionality
* @return void
*/
public static function tearDownAfterClass()
{
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
}
}
Loading