Skip to content

Commit 46edec4

Browse files
ShradddhaShradddha
authored andcommitted
AC-11979:: Remove Deprecations- PhpUnit10 Integration Tests
1 parent dc5aaee commit 46edec4

File tree

46 files changed

+296
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+296
-237
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 $graphQlClient;
22+
private static $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 function graphQlQuery(
40+
public static function graphQlQuery(
4141
string $query,
4242
array $variables = [],
4343
string $operationName = '',
4444
array $headers = []
4545
) {
46-
return $this->getGraphQlClient()->get(
46+
return self::getGraphQlClient()->get(
4747
$query,
4848
$variables,
4949
$operationName,
50-
$this->composeHeaders($headers)
50+
self::composeHeaders($headers)
5151
);
5252
}
5353

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

@@ -128,7 +128,7 @@ public function graphQlMutationWithResponseHeaders(
128128
* @param array $headers
129129
* @return string[]
130130
*/
131-
private function composeHeaders(array $headers): array
131+
private static 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 function getGraphQlClient()
168+
private static function getGraphQlClient()
169169
{
170-
if ($this->graphQlClient === null) {
171-
$this->graphQlClient = Bootstrap::getObjectManager()->get(
170+
if (self::$graphQlClient === null) {
171+
self::$graphQlClient = Bootstrap::getObjectManager()->get(
172172
\Magento\TestFramework\TestCase\GraphQl\Client::class
173173
);
174174
}
175-
return $this->graphQlClient;
175+
return self::$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 $integration;
61+
private static $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 function actionMechanismProvider(): array
340+
public static 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 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 = $this->getOauthIntegration();
356+
$integration = self::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 = $this->getOauthIntegration();
379+
$integration = self::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 function getOauthIntegration(): Integration
745+
private static function getOauthIntegration(): Integration
746746
{
747-
if (!isset($this->integration)) {
747+
if (!isset(self::$integration)) {
748748
$params = [
749749
'all_resources' => true,
750750
'status' => Integration::STATUS_ACTIVE,
751751
'name' => 'Integration' . microtime()
752752
];
753753

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

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

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

Lines changed: 85 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,19 @@ public function testCustomerResolverCacheInvalidationOnStoreChange()
299299
* @param CustomerInterface $customer
300300
* @return void
301301
*/
302-
private function assertCurrentCustomerCacheRecordExists(CustomerInterface $customer)
302+
private static function assertCurrentCustomerCacheRecordExists(CustomerInterface $customer)
303303
{
304-
$cacheKey = $this->getCacheKeyForCustomerResolver();
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));
305311
$cacheEntry = Bootstrap::getObjectManager()->get(GraphQlResolverCache::class)->load($cacheKey);
306312
$cacheEntryDecoded = json_decode($cacheEntry, true);
307313

308-
$this->assertEquals(
314+
self::assertEquals(
309315
$customer->getEmail(),
310316
$cacheEntryDecoded['email']
311317
);
@@ -318,7 +324,13 @@ private function assertCurrentCustomerCacheRecordExists(CustomerInterface $custo
318324
*/
319325
private function assertCurrentCustomerCacheRecordDoesNotExist()
320326
{
321-
$cacheKey = $this->getCacheKeyForCustomerResolver();
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));
322334
$this->assertFalse(
323335
Bootstrap::getObjectManager()->get(GraphQlResolverCache::class)->test($cacheKey)
324336
);
@@ -350,7 +362,13 @@ public function testCustomerResolverCacheGeneratesSeparateEntriesForEachCustomer
350362
['Authorization' => 'Bearer ' . $customer1Token]
351363
);
352364

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

355373
$this->assertIsNumeric(
356374
$this->graphQlResolverCache->test($customer1CacheKey)
@@ -370,7 +388,13 @@ public function testCustomerResolverCacheGeneratesSeparateEntriesForEachCustomer
370388
['Authorization' => 'Bearer ' . $customer2Token]
371389
);
372390

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

375399
$this->assertIsNumeric(
376400
$this->graphQlResolverCache->test($customer2CacheKey)
@@ -417,7 +441,13 @@ public function testCustomerResolverCacheInvalidatesWhenCustomerGetsDeleted()
417441
['Authorization' => 'Bearer ' . $token]
418442
);
419443

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

422452
$this->assertIsNumeric(
423453
$this->graphQlResolverCache->test($cacheKey)
@@ -481,7 +511,13 @@ public function testCustomerWithSameEmailInTwoSeparateWebsitesKeepsSeparateCache
481511
['Authorization' => 'Bearer ' . $customer1Token]
482512
);
483513

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

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

512554
$customer2CacheEntry = $this->graphQlResolverCache->load($customer2CacheKey);
513555
$customer2CacheEntryDecoded = json_decode($customer2CacheEntry, true);
@@ -546,7 +588,13 @@ public function testGuestQueryingCustomerDoesNotGenerateResolverCacheEntry()
546588
// expected exception
547589
}
548590

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

551599
$this->assertFalse(
552600
$this->graphQlResolverCache->test($cacheKey)
@@ -618,7 +666,7 @@ public function testCustomerQueryingCustomerWithDifferentStoreHeaderDoesNotGener
618666
);
619667
}
620668

621-
public function invalidationMechanismProvider(): array
669+
public static function invalidationMechanismProvider(): array
622670
{
623671
// provider is invoked before setUp() is called so need to init here
624672
$repo = Bootstrap::getObjectManager()->get(
@@ -641,51 +689,51 @@ function (CustomerInterface $customer) use ($repo) {
641689
'add and delete address' => [
642690
function (CustomerInterface $customer, $tokenString) {
643691
// create new address because default billing address cannot be deleted
644-
$this->graphQlMutation(
645-
$this->getCreateAddressMutation("4000 Polk St"),
692+
self::graphQlMutation(
693+
self::getCreateAddressMutation("4000 Polk St"),
646694
[],
647695
'',
648696
['Authorization' => 'Bearer ' . $tokenString]
649697
);
650698
// query for customer to cache data after address creation
651-
$result = $this->graphQlQuery(
652-
$this->getCustomerQuery(),
699+
$result = self::graphQlQuery(
700+
self::getCustomerQuery(),
653701
[],
654702
'',
655703
['Authorization' => 'Bearer ' . $tokenString]
656704
);
657705
// assert that cache record exists for given customer
658-
$this->assertCurrentCustomerCacheRecordExists($customer);
706+
self::assertCurrentCustomerCacheRecordExists($customer);
659707

660708
$addressId = $result['customer']['addresses'][1]['id'];
661-
$result = $this->graphQlMutation(
662-
$this->getDeleteAddressMutation($addressId),
709+
$result = self::graphQlMutation(
710+
self::getDeleteAddressMutation($addressId),
663711
[],
664712
'',
665713
['Authorization' => 'Bearer ' . $tokenString]
666714
);
667-
$this->assertTrue($result['deleteCustomerAddress']);
715+
self::assertTrue($result['deleteCustomerAddress']);
668716
},
669717
],
670718
'update address' => [
671719
function (CustomerInterface $customer, $tokenString) {
672720
// query for customer to cache data after address creation
673-
$result = $this->graphQlQuery(
674-
$this->getCustomerQuery(),
721+
$result = self::graphQlQuery(
722+
self::getCustomerQuery(),
675723
[],
676724
'',
677725
['Authorization' => 'Bearer ' . $tokenString]
678726
);
679727

680728
$addressId = $result['customer']['addresses'][0]['id'];
681-
$result = $this->graphQlMutation(
682-
$this->getUpdateAddressStreetMutation($addressId, "8000 New St"),
729+
$result = self::graphQlMutation(
730+
self::getUpdateAddressStreetMutation($addressId, "8000 New St"),
683731
[],
684732
'',
685733
['Authorization' => 'Bearer ' . $tokenString]
686734
);
687-
$this->assertEquals($addressId, $result['updateCustomerAddress']['id']);
688-
$this->assertEquals("8000 New St", $result['updateCustomerAddress']['street'][0]);
735+
self::assertEquals($addressId, $result['updateCustomerAddress']['id']);
736+
self::assertEquals("8000 New St", $result['updateCustomerAddress']['street'][0]);
689737
},
690738
],
691739
];
@@ -695,7 +743,7 @@ function (CustomerInterface $customer, $tokenString) {
695743
* @param string $streetAddress
696744
* @return string
697745
*/
698-
private function getCreateAddressMutation($streetAddress)
746+
private static function getCreateAddressMutation($streetAddress)
699747
{
700748
return <<<MUTATIONCREATE
701749
mutation{
@@ -733,7 +781,7 @@ private function getCreateAddressMutation($streetAddress)
733781
* @param string $streetAddress
734782
* @return string
735783
*/
736-
private function getUpdateAddressStreetMutation($addressId, $streetAddress)
784+
private static function getUpdateAddressStreetMutation($addressId, $streetAddress)
737785
{
738786
return <<<MUTATIONUPDATE
739787
mutation{
@@ -780,7 +828,7 @@ private function assertTagsByCacheKeyAndCustomer(string $cacheKey, CustomerInter
780828
);
781829
}
782830

783-
private function getCacheKeyForCustomerResolver(): string
831+
private function getProviderInterfaceMock()
784832
{
785833
$resolverMock = $this->getMockBuilder(CustomerResolver::class)
786834
->disableOriginalConstructor()
@@ -793,6 +841,13 @@ private function getCacheKeyForCustomerResolver(): string
793841
->getKeyCalculatorForResolver($resolverMock)
794842
->calculateCacheKey();
795843

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

798853
$cacheKeyParts = [
@@ -802,10 +857,10 @@ private function getCacheKeyForCustomerResolver(): string
802857
];
803858

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

808-
private function getCustomerQuery(): string
863+
private static function getCustomerQuery(): string
809864
{
810865
return <<<QUERY
811866
{

0 commit comments

Comments
 (0)