Skip to content

Commit 119c56d

Browse files
ShradddhaShradddha
authored andcommitted
AC-11979:: Remove Deprecations- PhpUnit10 Integration Tests
1 parent b311865 commit 119c56d

File tree

4 files changed

+73
-134
lines changed

4 files changed

+73
-134
lines changed

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQlAbstract.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class GraphQlAbstract extends WebapiAbstract
1919
*
2020
* @var \Magento\TestFramework\TestCase\GraphQl\Client
2121
*/
22-
private static $graphQlClient;
22+
private $graphQlClient;
2323

2424
/**
2525
* @var \Magento\Framework\App\Cache
@@ -37,17 +37,17 @@ abstract class GraphQlAbstract extends WebapiAbstract
3737
* @return array|int|string|float|bool GraphQL call results
3838
* @throws \Exception
3939
*/
40-
public static function graphQlQuery(
40+
public function graphQlQuery(
4141
string $query,
4242
array $variables = [],
4343
string $operationName = '',
4444
array $headers = []
4545
) {
46-
return self::getGraphQlClient()->get(
46+
return $this->getGraphQlClient()->get(
4747
$query,
4848
$variables,
4949
$operationName,
50-
self::composeHeaders($headers)
50+
$this->composeHeaders($headers)
5151
);
5252
}
5353

@@ -62,17 +62,17 @@ public static function graphQlQuery(
6262
* @return array|int|string|float|bool GraphQL call results
6363
* @throws \Exception
6464
*/
65-
public static function graphQlMutation(
65+
public function graphQlMutation(
6666
string $query,
6767
array $variables = [],
6868
string $operationName = '',
6969
array $headers = []
7070
) {
71-
return self::getGraphQlClient()->post(
71+
return $this->getGraphQlClient()->post(
7272
$query,
7373
$variables,
7474
$operationName,
75-
self::composeHeaders($headers)
75+
$this->composeHeaders($headers)
7676
);
7777
}
7878

@@ -128,7 +128,7 @@ public function graphQlMutationWithResponseHeaders(
128128
* @param array $headers
129129
* @return string[]
130130
*/
131-
private static function composeHeaders(array $headers): array
131+
private function composeHeaders(array $headers): array
132132
{
133133
$headersArray = [];
134134
foreach ($headers as $key => $value) {
@@ -165,14 +165,14 @@ private function getAppCache()
165165
*
166166
* @return \Magento\TestFramework\TestCase\GraphQl\Client
167167
*/
168-
private static function getGraphQlClient()
168+
private function getGraphQlClient()
169169
{
170-
if (self::$graphQlClient === null) {
171-
self::$graphQlClient = Bootstrap::getObjectManager()->get(
170+
if ($this->graphQlClient === null) {
171+
$this->graphQlClient = Bootstrap::getObjectManager()->get(
172172
\Magento\TestFramework\TestCase\GraphQl\Client::class
173173
);
174174
}
175-
return self::$graphQlClient;
175+
return $this->graphQlClient;
176176
}
177177

178178
/**

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ResolverCache/MediaGalleryTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class MediaGalleryTest extends ResolverCacheAbstract
5858
/**
5959
* @var Integration
6060
*/
61-
private static $integration;
61+
private $integration;
6262

6363
/**
6464
* @var StoreManagerInterface
@@ -337,7 +337,7 @@ public function testMediaGalleryForProductVideos(callable $actionMechanismCallab
337337
* @return array[]
338338
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
339339
*/
340-
public static function actionMechanismProvider(): array
340+
public function actionMechanismProvider(): array
341341
{
342342
// provider is invoked before setUp() is called so need to init here
343343
$objectManager = Bootstrap::getObjectManager();
@@ -353,7 +353,7 @@ public static function actionMechanismProvider(): array
353353
function (ProductInterface $product) {
354354
// create an integration so that cache is not cleared in
355355
// Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call
356-
$integration = self::getOauthIntegration();
356+
$integration = $this->getOauthIntegration();
357357

358358
$serviceInfo = [
359359
'rest' => [
@@ -376,7 +376,7 @@ function (ProductInterface $product) {
376376
function (ProductInterface $product) {
377377
// create an integration so that cache is not cleared in
378378
// Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call
379-
$integration = self::getOauthIntegration();
379+
$integration = $this->getOauthIntegration();
380380

381381
$galleryEntry = $product->getMediaGalleryEntries()[0];
382382
$galleryEntryId = $galleryEntry->getId();
@@ -742,19 +742,19 @@ private function getProductWithMediaGalleryQuery(ProductInterface $product): str
742742
* @return Integration
743743
* @throws \Magento\Framework\Exception\IntegrationException
744744
*/
745-
private static function getOauthIntegration(): Integration
745+
private function getOauthIntegration(): Integration
746746
{
747-
if (!isset(self::$integration)) {
747+
if (!isset($this->integration)) {
748748
$params = [
749749
'all_resources' => true,
750750
'status' => Integration::STATUS_ACTIVE,
751751
'name' => 'Integration' . microtime()
752752
];
753753

754-
self::$integration = Bootstrap::getObjectManager()->get(IntegrationServiceInterface::class)
754+
$this->integration = Bootstrap::getObjectManager()->get(IntegrationServiceInterface::class)
755755
->create($params);
756756
}
757757

758-
return self::$integration;
758+
return $this->integration;
759759
}
760760
}

dev/tests/api-functional/testsuite/Magento/GraphQl/CustomerGraphQl/Model/Resolver/CustomerTest.php

Lines changed: 30 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,13 @@ public function testCustomerResolverCacheInvalidationOnStoreChange()
299299
* @param CustomerInterface $customer
300300
* @return void
301301
*/
302-
private static function assertCurrentCustomerCacheRecordExists(CustomerInterface $customer)
302+
private function assertCurrentCustomerCacheRecordExists(CustomerInterface $customer)
303303
{
304-
$cacheKey = self::getCacheKeyForCustomerResolver();
305-
306-
if(is_callable($cacheKey[1]))
307-
{
308-
$cacheKey[1] = $cacheKey[1](CustomerTest::class);
309-
}
310-
$cacheKey = strtoupper(implode('_', $cacheKey));
304+
$cacheKey = $this->getCacheKeyForCustomerResolver();
311305
$cacheEntry = Bootstrap::getObjectManager()->get(GraphQlResolverCache::class)->load($cacheKey);
312306
$cacheEntryDecoded = json_decode($cacheEntry, true);
313307

314-
self::assertEquals(
308+
$this->assertEquals(
315309
$customer->getEmail(),
316310
$cacheEntryDecoded['email']
317311
);
@@ -324,13 +318,7 @@ private static function assertCurrentCustomerCacheRecordExists(CustomerInterface
324318
*/
325319
private function assertCurrentCustomerCacheRecordDoesNotExist()
326320
{
327-
$cacheKey = self::getCacheKeyForCustomerResolver();
328-
329-
if(is_callable($cacheKey[1]))
330-
{
331-
$cacheKey[1] = $cacheKey[1](CustomerTest::class);
332-
}
333-
$cacheKey = strtoupper(implode('_', $cacheKey));
321+
$cacheKey = $this->getCacheKeyForCustomerResolver();
334322
$this->assertFalse(
335323
Bootstrap::getObjectManager()->get(GraphQlResolverCache::class)->test($cacheKey)
336324
);
@@ -362,13 +350,7 @@ public function testCustomerResolverCacheGeneratesSeparateEntriesForEachCustomer
362350
['Authorization' => 'Bearer ' . $customer1Token]
363351
);
364352

365-
$customer1CacheKey = self::getCacheKeyForCustomerResolver();
366-
367-
if(is_callable($customer1CacheKey[1]))
368-
{
369-
$customer1CacheKey[1] = $customer1CacheKey[1]($this);
370-
}
371-
$customer1CacheKey = strtoupper(implode('_', $customer1CacheKey));
353+
$customer1CacheKey = $this->getCacheKeyForCustomerResolver();
372354

373355
$this->assertIsNumeric(
374356
$this->graphQlResolverCache->test($customer1CacheKey)
@@ -388,13 +370,7 @@ public function testCustomerResolverCacheGeneratesSeparateEntriesForEachCustomer
388370
['Authorization' => 'Bearer ' . $customer2Token]
389371
);
390372

391-
$customer2CacheKey = self::getCacheKeyForCustomerResolver();
392-
393-
if(is_callable($customer2CacheKey[1]))
394-
{
395-
$customer2CacheKey[1] = $customer2CacheKey[1]($this);
396-
}
397-
$customer2CacheKey = strtoupper(implode('_', $customer2CacheKey));
373+
$customer2CacheKey = $this->getCacheKeyForCustomerResolver();
398374

399375
$this->assertIsNumeric(
400376
$this->graphQlResolverCache->test($customer2CacheKey)
@@ -441,13 +417,7 @@ public function testCustomerResolverCacheInvalidatesWhenCustomerGetsDeleted()
441417
['Authorization' => 'Bearer ' . $token]
442418
);
443419

444-
$cacheKey = self::getCacheKeyForCustomerResolver();
445-
446-
if(is_callable($cacheKey[1]))
447-
{
448-
$cacheKey[1] = $cacheKey[1]($this);
449-
}
450-
$cacheKey = strtoupper(implode('_', $cacheKey));
420+
$cacheKey = $this->getCacheKeyForCustomerResolver();
451421

452422
$this->assertIsNumeric(
453423
$this->graphQlResolverCache->test($cacheKey)
@@ -511,13 +481,7 @@ public function testCustomerWithSameEmailInTwoSeparateWebsitesKeepsSeparateCache
511481
['Authorization' => 'Bearer ' . $customer1Token]
512482
);
513483

514-
$customer1CacheKey = self::getCacheKeyForCustomerResolver();
515-
516-
if(is_callable($customer1CacheKey[1]))
517-
{
518-
$customer1CacheKey[1] = $customer1CacheKey[1]($this);
519-
}
520-
$customer1CacheKey = strtoupper(implode('_', $customer1CacheKey));
484+
$customer1CacheKey = $this->getCacheKeyForCustomerResolver();
521485
$customer1CacheEntry = $this->graphQlResolverCache->load($customer1CacheKey);
522486
$customer1CacheEntryDecoded = json_decode($customer1CacheEntry, true);
523487
$this->assertEquals(
@@ -543,13 +507,7 @@ public function testCustomerWithSameEmailInTwoSeparateWebsitesKeepsSeparateCache
543507
]
544508
);
545509

546-
$customer2CacheKey = self::getCacheKeyForCustomerResolver();
547-
548-
if(is_callable($customer2CacheKey[1]))
549-
{
550-
$customer2CacheKey[1] = $customer2CacheKey[1]($this);
551-
}
552-
$customer2CacheKey = strtoupper(implode('_', $customer2CacheKey));
510+
$customer2CacheKey = $this->getCacheKeyForCustomerResolver();
553511

554512
$customer2CacheEntry = $this->graphQlResolverCache->load($customer2CacheKey);
555513
$customer2CacheEntryDecoded = json_decode($customer2CacheEntry, true);
@@ -588,13 +546,7 @@ public function testGuestQueryingCustomerDoesNotGenerateResolverCacheEntry()
588546
// expected exception
589547
}
590548

591-
$cacheKey = self::getCacheKeyForCustomerResolver();
592-
593-
if(is_callable($cacheKey[1]))
594-
{
595-
$cacheKey[1] = $cacheKey[1]($this);
596-
}
597-
$cacheKey = strtoupper(implode('_', $cacheKey));
549+
$cacheKey = $this->getCacheKeyForCustomerResolver();
598550

599551
$this->assertFalse(
600552
$this->graphQlResolverCache->test($cacheKey)
@@ -666,7 +618,7 @@ public function testCustomerQueryingCustomerWithDifferentStoreHeaderDoesNotGener
666618
);
667619
}
668620

669-
public static function invalidationMechanismProvider(): array
621+
public function invalidationMechanismProvider(): array
670622
{
671623
// provider is invoked before setUp() is called so need to init here
672624
$repo = Bootstrap::getObjectManager()->get(
@@ -689,51 +641,51 @@ function (CustomerInterface $customer) use ($repo) {
689641
'add and delete address' => [
690642
function (CustomerInterface $customer, $tokenString) {
691643
// create new address because default billing address cannot be deleted
692-
self::graphQlMutation(
693-
self::getCreateAddressMutation("4000 Polk St"),
644+
$this->graphQlMutation(
645+
$this->getCreateAddressMutation("4000 Polk St"),
694646
[],
695647
'',
696648
['Authorization' => 'Bearer ' . $tokenString]
697649
);
698650
// query for customer to cache data after address creation
699-
$result = self::graphQlQuery(
700-
self::getCustomerQuery(),
651+
$result = $this->graphQlQuery(
652+
$this->getCustomerQuery(),
701653
[],
702654
'',
703655
['Authorization' => 'Bearer ' . $tokenString]
704656
);
705657
// assert that cache record exists for given customer
706-
self::assertCurrentCustomerCacheRecordExists($customer);
658+
$this->assertCurrentCustomerCacheRecordExists($customer);
707659

708660
$addressId = $result['customer']['addresses'][1]['id'];
709-
$result = self::graphQlMutation(
710-
self::getDeleteAddressMutation($addressId),
661+
$result = $this->graphQlMutation(
662+
$this->getDeleteAddressMutation($addressId),
711663
[],
712664
'',
713665
['Authorization' => 'Bearer ' . $tokenString]
714666
);
715-
self::assertTrue($result['deleteCustomerAddress']);
667+
$this->assertTrue($result['deleteCustomerAddress']);
716668
},
717669
],
718670
'update address' => [
719671
function (CustomerInterface $customer, $tokenString) {
720672
// query for customer to cache data after address creation
721-
$result = self::graphQlQuery(
722-
self::getCustomerQuery(),
673+
$result = $this->graphQlQuery(
674+
$this->getCustomerQuery(),
723675
[],
724676
'',
725677
['Authorization' => 'Bearer ' . $tokenString]
726678
);
727679

728680
$addressId = $result['customer']['addresses'][0]['id'];
729-
$result = self::graphQlMutation(
730-
self::getUpdateAddressStreetMutation($addressId, "8000 New St"),
681+
$result = $this->graphQlMutation(
682+
$this->getUpdateAddressStreetMutation($addressId, "8000 New St"),
731683
[],
732684
'',
733685
['Authorization' => 'Bearer ' . $tokenString]
734686
);
735-
self::assertEquals($addressId, $result['updateCustomerAddress']['id']);
736-
self::assertEquals("8000 New St", $result['updateCustomerAddress']['street'][0]);
687+
$this->assertEquals($addressId, $result['updateCustomerAddress']['id']);
688+
$this->assertEquals("8000 New St", $result['updateCustomerAddress']['street'][0]);
737689
},
738690
],
739691
];
@@ -743,7 +695,7 @@ function (CustomerInterface $customer, $tokenString) {
743695
* @param string $streetAddress
744696
* @return string
745697
*/
746-
private static function getCreateAddressMutation($streetAddress)
698+
private function getCreateAddressMutation($streetAddress)
747699
{
748700
return <<<MUTATIONCREATE
749701
mutation{
@@ -781,7 +733,7 @@ private static function getCreateAddressMutation($streetAddress)
781733
* @param string $streetAddress
782734
* @return string
783735
*/
784-
private static function getUpdateAddressStreetMutation($addressId, $streetAddress)
736+
private function getUpdateAddressStreetMutation($addressId, $streetAddress)
785737
{
786738
return <<<MUTATIONUPDATE
787739
mutation{
@@ -828,7 +780,7 @@ private function assertTagsByCacheKeyAndCustomer(string $cacheKey, CustomerInter
828780
);
829781
}
830782

831-
private function getProviderInterfaceMock()
783+
private function getCacheKeyForCustomerResolver(): string
832784
{
833785
$resolverMock = $this->getMockBuilder(CustomerResolver::class)
834786
->disableOriginalConstructor()
@@ -841,13 +793,6 @@ private function getProviderInterfaceMock()
841793
->getKeyCalculatorForResolver($resolverMock)
842794
->calculateCacheKey();
843795

844-
return $cacheKeyFactor;
845-
}
846-
847-
private static function getCacheKeyForCustomerResolver(): array
848-
{
849-
$cacheKeyFactor = static fn (self $testCase) => $testCase->getProviderInterfaceMock();
850-
851796
$cacheKeyQueryPayloadMetadata = CustomerResolver::class . '\Interceptor[]';
852797

853798
$cacheKeyParts = [
@@ -857,10 +802,10 @@ private static function getCacheKeyForCustomerResolver(): array
857802
];
858803

859804
// strtoupper is called in \Magento\Framework\Cache\Frontend\Adapter\Zend::_unifyId
860-
return $cacheKeyParts;
805+
return strtoupper(implode('_', $cacheKeyParts));
861806
}
862807

863-
private static function getCustomerQuery(): string
808+
private function getCustomerQuery(): string
864809
{
865810
return <<<QUERY
866811
{

0 commit comments

Comments
 (0)