Skip to content

Eliminated Aspect Mock usage from ActionMergeUtilTest #837

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace tests\unit\Magento\FunctionalTestFramework\Test\Util;

use AspectMock\Test as AspectMock;
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
use Magento\FunctionalTestingFramework\Test\Util\ActionMergeUtil;
use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor;
use ReflectionProperty;
use tests\unit\Util\MagentoTestCase;
use tests\unit\Util\TestLoggingUtil;

class ActionMergeUtilTest extends MagentoTestCase
{
/**
* Before test functionality
* Before test functionality.
*
* @return void
*/
public function setUp(): void
protected function setUp(): void
{
TestLoggingUtil::getInstance()->setMockLoggingUtil();
}
Expand All @@ -31,8 +34,10 @@ public function setUp(): void
* Test to validate actions are properly ordered during a merge.
*
* @return void
* @throws TestReferenceException
* @throws XmlException
*/
public function testResolveActionStepOrdering()
public function testResolveActionStepOrdering(): void
{
$actions = [];
$actionsLength = 11;
Expand All @@ -46,7 +51,6 @@ public function testResolveActionStepOrdering()
$stepKey = 'stepKey'. $i;
$type = 'testType';
$actionAttributes = [];

$actions[] = new ActionObject($stepKey, $type, $actionAttributes);
}

Expand Down Expand Up @@ -93,8 +97,10 @@ public function testResolveActionStepOrdering()
* Test to validate action steps properly resolve entity data references.
*
* @return void
* @throws TestReferenceException
* @throws XmlException
*/
public function testResolveActionStepEntityData()
public function testResolveActionStepEntityData(): void
{
$dataObjectName = 'myObject';
$dataObjectType = 'testObject';
Expand All @@ -110,36 +116,35 @@ public function testResolveActionStepEntityData()
$mockDataObject = new EntityDataObject($dataObjectName, $dataObjectType, $mockData, null, null, null);

// Set up mock DataObject Handler
$mockDOHInstance = AspectMock::double(DataObjectHandler::class, ['getObject' => $mockDataObject])->make();
AspectMock::double(DataObjectHandler::class, ['getInstance' => $mockDOHInstance]);
$mockDOHInstance = $this->createMock(DataObjectHandler::class);
$mockDOHInstance
->expects($this->any())
->method('getObject')
->willReturn($mockDataObject);
$property = new ReflectionProperty(DataObjectHandler::class, 'INSTANCE');
$property->setAccessible(true);
$property->setValue($mockDOHInstance, $mockDOHInstance);

// Create test object and action object
$actionAttributes = [$userInputKey => $userInputValue];
$actions[$actionName] = new ActionObject($actionName, $actionType, $actionAttributes);

$this->assertEquals($userInputValue, $actions[$actionName]->getCustomActionAttributes()[$userInputKey]);

$mergeUtil = new ActionMergeUtil("test", "TestCase");
$resolvedActions = $mergeUtil->resolveActionSteps($actions);

$this->assertEquals($dataFieldValue, $resolvedActions[$actionName]->getCustomActionAttributes()[$userInputKey]);
}

/**
* Verify that an XmlException is thrown when an action references a non-existant action.
*
* @throws TestReferenceException
* @throws XmlException
* @return void
*/
/**
* @throws TestReferenceException
* @throws XmlException
*/
public function testNoActionException()
public function testNoActionException(): void
{
$actionObjects = [];

$actionObjects[] = new ActionObject('actionKey1', 'bogusType', []);
$actionObjects[] = new ActionObject(
'actionKey2',
Expand All @@ -149,20 +154,19 @@ public function testNoActionException()
ActionObject::MERGE_ACTION_ORDER_BEFORE
);

$this->expectException(\Magento\FunctionalTestingFramework\Exceptions\XmlException::class);

$this->expectException(XmlException::class);
$actionMergeUtil = new ActionMergeUtil("actionMergeUtilTest", "TestCase");
$actionMergeUtil->resolveActionSteps($actionObjects);
}

/**
* Verify that a <waitForPageLoad> action is added after actions that have a wait (timeout property).
*
* @return void
* @throws TestReferenceException
* @throws XmlException
* @return void
*/
public function testInsertWait()
public function testInsertWait(): void
{
$actionObjectOne = new ActionObject('actionKey1', 'bogusType', []);
$actionObjectOne->setTimeout(42);
Expand All @@ -185,10 +189,11 @@ public function testInsertWait()
/**
* Verify that a <fillField> action is replaced by <fillSecretField> when secret _CREDS are referenced.
*
* @return void
* @throws TestReferenceException
* @throws XmlException
*/
public function testValidFillFieldSecretFunction()
public function testValidFillFieldSecretFunction(): void
{
$actionObjectOne = new ActionObject(
'actionKey1',
Expand All @@ -198,7 +203,6 @@ public function testValidFillFieldSecretFunction()
$actionObject = [$actionObjectOne];

$actionMergeUtil = new ActionMergeUtil('actionMergeUtilTest', 'TestCase');

$result = $actionMergeUtil->resolveActionSteps($actionObject);

$expectedValue = new ActionObject(
Expand All @@ -212,10 +216,11 @@ public function testValidFillFieldSecretFunction()
/**
* Verify that a <magentoCLI> action uses <magentoCLI> when secret _CREDS are referenced.
*
* @return void
* @throws TestReferenceException
* @throws XmlException
*/
public function testValidMagentoCLISecretFunction()
public function testValidMagentoCLISecretFunction(): void
{
$actionObjectOne = new ActionObject(
'actionKey1',
Expand All @@ -225,7 +230,6 @@ public function testValidMagentoCLISecretFunction()
$actionObject = [$actionObjectOne];

$actionMergeUtil = new ActionMergeUtil('actionMergeUtilTest', 'TestCase');

$result = $actionMergeUtil->resolveActionSteps($actionObject);

$expectedValue = new ActionObject(
Expand All @@ -239,10 +243,11 @@ public function testValidMagentoCLISecretFunction()
/**
* Verify that a <field> override in a <createData> action uses <field> when secret _CREDS are referenced.
*
* @return void
* @throws TestReferenceException
* @throws XmlException
*/
public function testValidCreateDataSecretFunction()
public function testValidCreateDataSecretFunction(): void
{
$actionObjectOne = new ActionObject(
'actionKey1',
Expand All @@ -252,7 +257,6 @@ public function testValidCreateDataSecretFunction()
$actionObject = [$actionObjectOne];

$actionMergeUtil = new ActionMergeUtil('actionMergeUtilTest', 'TestCase');

$result = $actionMergeUtil->resolveActionSteps($actionObject);

$expectedValue = new ActionObject(
Expand All @@ -266,10 +270,11 @@ public function testValidCreateDataSecretFunction()
/**
* Verify that a <click> action throws an exception when secret _CREDS are referenced.
*
* @return void
* @throws TestReferenceException
* @throws XmlException
*/
public function testInvalidSecretFunctions()
public function testInvalidSecretFunctions(): void
{
$this->expectException(TestReferenceException::class);
$this->expectExceptionMessage(
Expand All @@ -288,7 +293,8 @@ public function testInvalidSecretFunctions()
}

/**
* After class functionality
* After class functionality.
*
* @return void
*/
public static function tearDownAfterClass(): void
Expand Down
2 changes: 2 additions & 0 deletions dev/tests/unit/Util/MagentoTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public static function setUpBeforeClass(): void
if (!self::fileExists(DOCS_OUTPUT_DIR)) {
mkdir(DOCS_OUTPUT_DIR, 0755, true);
}
// Should be used to clean AspectMock mocking before using PHPUnit mocking and Reflection.
AspectMock::clean();
parent::setUpBeforeClass();
}

Expand Down