Skip to content

Commit d50f5b9

Browse files
committed
33293: Eliminated AspectMock usage from PersistedObjectHandlerTest.php
1 parent 9dfd3e3 commit d50f5b9

File tree

3 files changed

+172
-76
lines changed

3 files changed

+172
-76
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php

Lines changed: 139 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace tests\unit\Magento\FunctionalTestFramework\DataGenerator\Handlers;
89

9-
use AspectMock\Test as AspectMock;
10-
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
10+
use Exception;
1111
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
12-
use Magento\FunctionalTestingFramework\DataGenerator\Parsers\DataProfileSchemaParser;
1312
use Magento\FunctionalTestingFramework\DataGenerator\Persist\CurlHandler;
14-
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1513
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
16-
use Magento\FunctionalTestingFramework\ObjectManager;
17-
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
14+
use ReflectionProperty;
1815
use tests\unit\Util\MagentoTestCase;
1916
use tests\unit\Util\ObjectHandlerUtil;
2017
use tests\unit\Util\TestLoggingUtil;
@@ -25,28 +22,31 @@
2522
class PersistedObjectHandlerTest extends MagentoTestCase
2623
{
2724
/**
28-
* Before test functionality
29-
* @return void
25+
* @inheritDoc
3026
*/
3127
public function setUp(): void
3228
{
3329
TestLoggingUtil::getInstance()->setMockLoggingUtil();
3430
}
3531

36-
public function testCreateEntityWithNonExistingName()
32+
/**
33+
* Validate testCreateEntityWithNonExistingName.
34+
*
35+
* @return void
36+
* @throws TestReferenceException
37+
*/
38+
public function testCreateEntityWithNonExistingName(): void
3739
{
3840
// Test Data and Variables
39-
$entityName = "InvalidEntity";
40-
$entityStepKey = "StepKey";
41+
$entityName = 'InvalidEntity';
42+
$entityStepKey = 'StepKey';
4143
$scope = PersistedObjectHandler::TEST_SCOPE;
4244

4345
$exceptionMessage = "Entity \"" . $entityName . "\" does not exist." .
4446
"\nException occurred executing action at StepKey \"" . $entityStepKey . "\"";
4547

4648
$this->expectException(TestReferenceException::class);
47-
4849
$this->expectExceptionMessage($exceptionMessage);
49-
5050
$handler = PersistedObjectHandler::getInstance();
5151

5252
// Call method
@@ -57,13 +57,19 @@ public function testCreateEntityWithNonExistingName()
5757
);
5858
}
5959

60-
public function testCreateSimpleEntity()
60+
/**
61+
* Validate testCreateSimpleEntity.
62+
*
63+
* @return void
64+
* @throws TestReferenceException
65+
*/
66+
public function testCreateSimpleEntity(): void
6167
{
6268
// Test Data and Variables
63-
$entityName = "EntityOne";
64-
$entityStepKey = "StepKey";
65-
$dataKey = "testKey";
66-
$dataValue = "testValue";
69+
$entityName = 'EntityOne';
70+
$entityStepKey = 'StepKey';
71+
$dataKey = 'testKey';
72+
$dataValue = 'testValue';
6773
$scope = PersistedObjectHandler::TEST_SCOPE;
6874
$parserOutput = [
6975
'entity' => [
@@ -78,7 +84,7 @@ public function testCreateSimpleEntity()
7884
]
7985
]
8086
];
81-
$jsonResponse = "
87+
$jsonResponse = "
8288
{
8389
\"" . strtolower($dataKey) . "\" : \"{$dataValue}\"
8490
}
@@ -100,13 +106,19 @@ public function testCreateSimpleEntity()
100106
$this->assertEquals($dataValue, $persistedValue);
101107
}
102108

103-
public function testDeleteSimpleEntity()
109+
/**
110+
* Validate testDeleteSimpleEntity.
111+
*
112+
* @return void
113+
* @throws TestReferenceException
114+
*/
115+
public function testDeleteSimpleEntity(): void
104116
{
105117
// Test Data and Variables
106-
$entityName = "EntityOne";
107-
$entityStepKey = "StepKey";
108-
$dataKey = "testKey";
109-
$dataValue = "testValue";
118+
$entityName = 'EntityOne';
119+
$entityStepKey = 'StepKey';
120+
$dataKey = 'testKey';
121+
$dataValue = 'testValue';
110122
$scope = PersistedObjectHandler::TEST_SCOPE;
111123
$parserOutput = [
112124
'entity' => [
@@ -121,7 +133,7 @@ public function testDeleteSimpleEntity()
121133
]
122134
]
123135
];
124-
$jsonResponse = "
136+
$jsonResponse = "
125137
{
126138
\"" . strtolower($dataKey) . "\" : \"{$dataValue}\"
127139
}
@@ -148,13 +160,19 @@ public function testDeleteSimpleEntity()
148160
$this->addToAssertionCount(1);
149161
}
150162

151-
public function testGetSimpleEntity()
163+
/**
164+
* Validate testGetSimpleEntity.
165+
*
166+
* @return void
167+
* @throws Exception
168+
*/
169+
public function testGetSimpleEntity(): void
152170
{
153171
// Test Data and Variables
154-
$entityName = "EntityOne";
155-
$entityStepKey = "StepKey";
156-
$dataKey = "testKey";
157-
$dataValue = "testValue";
172+
$entityName = 'EntityOne';
173+
$entityStepKey = 'StepKey';
174+
$dataKey = 'testKey';
175+
$dataValue = 'testValue';
158176
$scope = PersistedObjectHandler::TEST_SCOPE;
159177
$parserOutput = [
160178
'entity' => [
@@ -169,7 +187,7 @@ public function testGetSimpleEntity()
169187
]
170188
]
171189
];
172-
$jsonResponse = "
190+
$jsonResponse = "
173191
{
174192
\"" . strtolower($dataKey) . "\" : \"{$dataValue}\"
175193
}
@@ -191,16 +209,22 @@ public function testGetSimpleEntity()
191209
$this->assertEquals($dataValue, $persistedValue);
192210
}
193211

194-
public function testUpdateSimpleEntity()
212+
/**
213+
* Validate testUpdateSimpleEntity.
214+
*
215+
* @return void
216+
* @throws TestReferenceException
217+
*/
218+
public function testUpdateSimpleEntity(): void
195219
{
196-
$this->markTestSkipped("Potential Bug in DataPersistenceHandler class");
220+
$this->markTestSkipped('Potential Bug in DataPersistenceHandler class');
197221
// Test Data and Variables
198-
$entityName = "EntityOne";
199-
$entityStepKey = "StepKey";
200-
$dataKey = "testKey";
201-
$dataValue = "testValue";
202-
$updateName = "EntityTwo";
203-
$updateValue = "newValue";
222+
$entityName = 'EntityOne';
223+
$entityStepKey = 'StepKey';
224+
$dataKey = 'testKey';
225+
$dataValue = 'testValue';
226+
$updateName = 'EntityTwo';
227+
$updateValue = 'newValue';
204228
$scope = PersistedObjectHandler::TEST_SCOPE;
205229
$parserOutput = [
206230
'entity' => [
@@ -224,7 +248,7 @@ public function testUpdateSimpleEntity()
224248
]
225249
]
226250
];
227-
$jsonResponse = "
251+
$jsonResponse = "
228252
{
229253
\"" . strtolower($dataKey) . "\" : \"{$dataValue}\"
230254
}
@@ -257,21 +281,27 @@ public function testUpdateSimpleEntity()
257281
$this->assertEquals($updateValue, $persistedValue);
258282
}
259283

260-
public function testRetrieveEntityAcrossScopes()
284+
/**
285+
* Validate testRetrieveEntityAcrossScopes.
286+
*
287+
* @return void
288+
* @throws TestReferenceException
289+
*/
290+
public function testRetrieveEntityAcrossScopes(): void
261291
{
262292
// Test Data and Variables
263-
$entityNameOne = "EntityOne";
264-
$entityStepKeyOne = "StepKeyOne";
265-
$dataKeyOne = "testKeyOne";
266-
$dataValueOne = "testValueOne";
267-
$entityNameTwo = "EntityTwo";
268-
$entityStepKeyTwo = "StepKeyTwo";
269-
$dataKeyTwo = "testKeyTwo";
270-
$dataValueTwo = "testValueTwo";
271-
$entityNameThree = "EntityThree";
272-
$entityStepKeyThree = "StepKeyThree";
273-
$dataKeyThree = "testKeyThree";
274-
$dataValueThree = "testValueThree";
293+
$entityNameOne = 'EntityOne';
294+
$entityStepKeyOne = 'StepKeyOne';
295+
$dataKeyOne = 'testKeyOne';
296+
$dataValueOne = 'testValueOne';
297+
$entityNameTwo = 'EntityTwo';
298+
$entityStepKeyTwo = 'StepKeyTwo';
299+
$dataKeyTwo = 'testKeyTwo';
300+
$dataValueTwo = 'testValueTwo';
301+
$entityNameThree = 'EntityThree';
302+
$entityStepKeyThree = 'StepKeyThree';
303+
$dataKeyThree = 'testKeyThree';
304+
$dataValueThree = 'testValueThree';
275305

276306
$parserOutputOne = [
277307
'entity' => [
@@ -368,16 +398,27 @@ public function testRetrieveEntityAcrossScopes()
368398
}
369399

370400
/**
401+
* Validate testRetrieveEntityValidField.
402+
*
371403
* @param string $name
372404
* @param string $key
373405
* @param string $value
374406
* @param string $type
375407
* @param string $scope
376408
* @param string $stepKey
377409
* @dataProvider entityDataProvider
410+
*
411+
* @return void
412+
* @throws TestReferenceException
378413
*/
379-
public function testRetrieveEntityValidField($name, $key, $value, $type, $scope, $stepKey)
380-
{
414+
public function testRetrieveEntityValidField(
415+
string $name,
416+
string $key,
417+
string $value,
418+
string $type,
419+
string $scope,
420+
string $stepKey
421+
): void {
381422
$parserOutputOne = [
382423
'entity' => [
383424
$name => [
@@ -411,21 +452,30 @@ public function testRetrieveEntityValidField($name, $key, $value, $type, $scope,
411452
}
412453

413454
/**
455+
* Validate testRetrieveEntityInValidField.
456+
*
414457
* @param string $name
415458
* @param string $key
416459
* @param string $value
417460
* @param string $type
418461
* @param string $scope
419462
* @param string $stepKey
420463
* @dataProvider entityDataProvider
464+
*
465+
* @return void
421466
* @throws TestReferenceException
422-
* @throws TestFrameworkException
423467
*/
424-
public function testRetrieveEntityInValidField($name, $key, $value, $type, $scope, $stepKey)
425-
{
426-
$invalidDataKey = "invalidDataKey";
468+
public function testRetrieveEntityInValidField(
469+
string $name,
470+
string $key,
471+
string $value,
472+
string $type,
473+
string $scope,
474+
string $stepKey
475+
): void {
476+
$invalidDataKey = 'invalidDataKey';
427477
$warnMsg = "Undefined field {$invalidDataKey} in entity object with a stepKey of {$stepKey}\n";
428-
$warnMsg .= "Please fix the invalid reference. This will result in fatal error in next major release.";
478+
$warnMsg .= 'Please fix the invalid reference. This will result in fatal error in next major release.';
429479

430480
$parserOutputOne = [
431481
'entity' => [
@@ -465,8 +515,10 @@ public function testRetrieveEntityInValidField($name, $key, $value, $type, $scop
465515

466516
/**
467517
* Data provider for testRetrieveEntityField
518+
*
519+
* @return array
468520
*/
469-
public static function entityDataProvider()
521+
public static function entityDataProvider(): array
470522
{
471523
return [
472524
['Entity1', 'testKey1', 'testValue1', 'testType', PersistedObjectHandler::HOOK_SCOPE, 'StepKey1'],
@@ -475,29 +527,45 @@ public static function entityDataProvider()
475527
];
476528
}
477529

478-
public function mockCurlHandler($response)
530+
/**
531+
* Create mock curl handler.
532+
*
533+
* @param string $response
534+
* @throws Exception
535+
*/
536+
public function mockCurlHandler(string $response): void
479537
{
480-
AspectMock::double(CurlHandler::class, [
481-
"__construct" => null,
482-
"executeRequest" => $response,
483-
"getRequestDataArray" => [],
484-
"isContentTypeJson" => true
485-
]);
538+
$mockCurlHandler = $this->createMock(CurlHandler::class);
539+
$mockCurlHandler->expects($this->any())
540+
->method('executeRequest')
541+
->willReturn($response);
542+
$mockCurlHandler->expects($this->once())
543+
->method('getRequestDataArray')
544+
->willReturn([]);
545+
$mockCurlHandler->expects($this->once())
546+
->method('isContentTypeJson')
547+
->willReturn(true);
548+
549+
$property = new ReflectionProperty(CurlHandler::class, "INSTANCE");
550+
$property->setAccessible(true);
551+
$property->setValue($mockCurlHandler);
486552
}
487553

554+
/**
555+
* @inheritDoc
556+
*/
488557
public function tearDown(): void
489558
{
490559
// Clear out Singleton between tests
491-
$property = new \ReflectionProperty(PersistedObjectHandler::class, "INSTANCE");
560+
$property = new ReflectionProperty(PersistedObjectHandler::class, 'INSTANCE');
492561
$property->setAccessible(true);
493562
$property->setValue(null);
494563

495564
parent::tearDown(); // TODO: Change the autogenerated stub
496565
}
497566

498567
/**
499-
* After class functionality
500-
* @return void
568+
* @inheritDoc
501569
*/
502570
public static function tearDownAfterClass(): void
503571
{

0 commit comments

Comments
 (0)