diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionMergeUtilTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionMergeUtilTest.php index 8c55210a4..56bb0f0c5 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionMergeUtilTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionMergeUtilTest.php @@ -3,9 +3,10 @@ * 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; @@ -13,16 +14,18 @@ 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(); } @@ -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; @@ -46,7 +51,6 @@ public function testResolveActionStepOrdering() $stepKey = 'stepKey'. $i; $type = 'testType'; $actionAttributes = []; - $actions[] = new ActionObject($stepKey, $type, $actionAttributes); } @@ -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'; @@ -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', @@ -149,8 +154,7 @@ 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); } @@ -158,11 +162,11 @@ public function testNoActionException() /** * Verify that a 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); @@ -185,10 +189,11 @@ public function testInsertWait() /** * Verify that a action is replaced by when secret _CREDS are referenced. * + * @return void * @throws TestReferenceException * @throws XmlException */ - public function testValidFillFieldSecretFunction() + public function testValidFillFieldSecretFunction(): void { $actionObjectOne = new ActionObject( 'actionKey1', @@ -198,7 +203,6 @@ public function testValidFillFieldSecretFunction() $actionObject = [$actionObjectOne]; $actionMergeUtil = new ActionMergeUtil('actionMergeUtilTest', 'TestCase'); - $result = $actionMergeUtil->resolveActionSteps($actionObject); $expectedValue = new ActionObject( @@ -212,10 +216,11 @@ public function testValidFillFieldSecretFunction() /** * Verify that a action uses when secret _CREDS are referenced. * + * @return void * @throws TestReferenceException * @throws XmlException */ - public function testValidMagentoCLISecretFunction() + public function testValidMagentoCLISecretFunction(): void { $actionObjectOne = new ActionObject( 'actionKey1', @@ -225,7 +230,6 @@ public function testValidMagentoCLISecretFunction() $actionObject = [$actionObjectOne]; $actionMergeUtil = new ActionMergeUtil('actionMergeUtilTest', 'TestCase'); - $result = $actionMergeUtil->resolveActionSteps($actionObject); $expectedValue = new ActionObject( @@ -239,10 +243,11 @@ public function testValidMagentoCLISecretFunction() /** * Verify that a override in a action uses when secret _CREDS are referenced. * + * @return void * @throws TestReferenceException * @throws XmlException */ - public function testValidCreateDataSecretFunction() + public function testValidCreateDataSecretFunction(): void { $actionObjectOne = new ActionObject( 'actionKey1', @@ -252,7 +257,6 @@ public function testValidCreateDataSecretFunction() $actionObject = [$actionObjectOne]; $actionMergeUtil = new ActionMergeUtil('actionMergeUtilTest', 'TestCase'); - $result = $actionMergeUtil->resolveActionSteps($actionObject); $expectedValue = new ActionObject( @@ -266,10 +270,11 @@ public function testValidCreateDataSecretFunction() /** * Verify that a 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( @@ -288,7 +293,8 @@ public function testInvalidSecretFunctions() } /** - * After class functionality + * After class functionality. + * * @return void */ public static function tearDownAfterClass(): void diff --git a/dev/tests/unit/Util/MagentoTestCase.php b/dev/tests/unit/Util/MagentoTestCase.php index 7760acfc6..bb38a0b5c 100644 --- a/dev/tests/unit/Util/MagentoTestCase.php +++ b/dev/tests/unit/Util/MagentoTestCase.php @@ -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(); }