@@ -299,19 +299,13 @@ public function testCustomerResolverCacheInvalidationOnStoreChange()
299
299
* @param CustomerInterface $customer
300
300
* @return void
301
301
*/
302
- private static function assertCurrentCustomerCacheRecordExists (CustomerInterface $ customer )
302
+ private function assertCurrentCustomerCacheRecordExists (CustomerInterface $ customer )
303
303
{
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 ();
311
305
$ cacheEntry = Bootstrap::getObjectManager ()->get (GraphQlResolverCache::class)->load ($ cacheKey );
312
306
$ cacheEntryDecoded = json_decode ($ cacheEntry , true );
313
307
314
- self :: assertEquals (
308
+ $ this -> assertEquals (
315
309
$ customer ->getEmail (),
316
310
$ cacheEntryDecoded ['email ' ]
317
311
);
@@ -324,13 +318,7 @@ private static function assertCurrentCustomerCacheRecordExists(CustomerInterface
324
318
*/
325
319
private function assertCurrentCustomerCacheRecordDoesNotExist ()
326
320
{
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 ();
334
322
$ this ->assertFalse (
335
323
Bootstrap::getObjectManager ()->get (GraphQlResolverCache::class)->test ($ cacheKey )
336
324
);
@@ -362,13 +350,7 @@ public function testCustomerResolverCacheGeneratesSeparateEntriesForEachCustomer
362
350
['Authorization ' => 'Bearer ' . $ customer1Token ]
363
351
);
364
352
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 ();
372
354
373
355
$ this ->assertIsNumeric (
374
356
$ this ->graphQlResolverCache ->test ($ customer1CacheKey )
@@ -388,13 +370,7 @@ public function testCustomerResolverCacheGeneratesSeparateEntriesForEachCustomer
388
370
['Authorization ' => 'Bearer ' . $ customer2Token ]
389
371
);
390
372
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 ();
398
374
399
375
$ this ->assertIsNumeric (
400
376
$ this ->graphQlResolverCache ->test ($ customer2CacheKey )
@@ -441,13 +417,7 @@ public function testCustomerResolverCacheInvalidatesWhenCustomerGetsDeleted()
441
417
['Authorization ' => 'Bearer ' . $ token ]
442
418
);
443
419
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 ();
451
421
452
422
$ this ->assertIsNumeric (
453
423
$ this ->graphQlResolverCache ->test ($ cacheKey )
@@ -511,13 +481,7 @@ public function testCustomerWithSameEmailInTwoSeparateWebsitesKeepsSeparateCache
511
481
['Authorization ' => 'Bearer ' . $ customer1Token ]
512
482
);
513
483
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 ();
521
485
$ customer1CacheEntry = $ this ->graphQlResolverCache ->load ($ customer1CacheKey );
522
486
$ customer1CacheEntryDecoded = json_decode ($ customer1CacheEntry , true );
523
487
$ this ->assertEquals (
@@ -543,13 +507,7 @@ public function testCustomerWithSameEmailInTwoSeparateWebsitesKeepsSeparateCache
543
507
]
544
508
);
545
509
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 ();
553
511
554
512
$ customer2CacheEntry = $ this ->graphQlResolverCache ->load ($ customer2CacheKey );
555
513
$ customer2CacheEntryDecoded = json_decode ($ customer2CacheEntry , true );
@@ -588,13 +546,7 @@ public function testGuestQueryingCustomerDoesNotGenerateResolverCacheEntry()
588
546
// expected exception
589
547
}
590
548
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 ();
598
550
599
551
$ this ->assertFalse (
600
552
$ this ->graphQlResolverCache ->test ($ cacheKey )
@@ -666,7 +618,7 @@ public function testCustomerQueryingCustomerWithDifferentStoreHeaderDoesNotGener
666
618
);
667
619
}
668
620
669
- public static function invalidationMechanismProvider (): array
621
+ public function invalidationMechanismProvider (): array
670
622
{
671
623
// provider is invoked before setUp() is called so need to init here
672
624
$ repo = Bootstrap::getObjectManager ()->get (
@@ -689,51 +641,51 @@ function (CustomerInterface $customer) use ($repo) {
689
641
'add and delete address ' => [
690
642
function (CustomerInterface $ customer , $ tokenString ) {
691
643
// 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 " ),
694
646
[],
695
647
'' ,
696
648
['Authorization ' => 'Bearer ' . $ tokenString ]
697
649
);
698
650
// query for customer to cache data after address creation
699
- $ result = self :: graphQlQuery (
700
- self :: getCustomerQuery (),
651
+ $ result = $ this -> graphQlQuery (
652
+ $ this -> getCustomerQuery (),
701
653
[],
702
654
'' ,
703
655
['Authorization ' => 'Bearer ' . $ tokenString ]
704
656
);
705
657
// assert that cache record exists for given customer
706
- self :: assertCurrentCustomerCacheRecordExists ($ customer );
658
+ $ this -> assertCurrentCustomerCacheRecordExists ($ customer );
707
659
708
660
$ addressId = $ result ['customer ' ]['addresses ' ][1 ]['id ' ];
709
- $ result = self :: graphQlMutation (
710
- self :: getDeleteAddressMutation ($ addressId ),
661
+ $ result = $ this -> graphQlMutation (
662
+ $ this -> getDeleteAddressMutation ($ addressId ),
711
663
[],
712
664
'' ,
713
665
['Authorization ' => 'Bearer ' . $ tokenString ]
714
666
);
715
- self :: assertTrue ($ result ['deleteCustomerAddress ' ]);
667
+ $ this -> assertTrue ($ result ['deleteCustomerAddress ' ]);
716
668
},
717
669
],
718
670
'update address ' => [
719
671
function (CustomerInterface $ customer , $ tokenString ) {
720
672
// query for customer to cache data after address creation
721
- $ result = self :: graphQlQuery (
722
- self :: getCustomerQuery (),
673
+ $ result = $ this -> graphQlQuery (
674
+ $ this -> getCustomerQuery (),
723
675
[],
724
676
'' ,
725
677
['Authorization ' => 'Bearer ' . $ tokenString ]
726
678
);
727
679
728
680
$ 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 " ),
731
683
[],
732
684
'' ,
733
685
['Authorization ' => 'Bearer ' . $ tokenString ]
734
686
);
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 ]);
737
689
},
738
690
],
739
691
];
@@ -743,7 +695,7 @@ function (CustomerInterface $customer, $tokenString) {
743
695
* @param string $streetAddress
744
696
* @return string
745
697
*/
746
- private static function getCreateAddressMutation ($ streetAddress )
698
+ private function getCreateAddressMutation ($ streetAddress )
747
699
{
748
700
return <<<MUTATIONCREATE
749
701
mutation{
@@ -781,7 +733,7 @@ private static function getCreateAddressMutation($streetAddress)
781
733
* @param string $streetAddress
782
734
* @return string
783
735
*/
784
- private static function getUpdateAddressStreetMutation ($ addressId , $ streetAddress )
736
+ private function getUpdateAddressStreetMutation ($ addressId , $ streetAddress )
785
737
{
786
738
return <<<MUTATIONUPDATE
787
739
mutation{
@@ -828,7 +780,7 @@ private function assertTagsByCacheKeyAndCustomer(string $cacheKey, CustomerInter
828
780
);
829
781
}
830
782
831
- private function getProviderInterfaceMock ()
783
+ private function getCacheKeyForCustomerResolver (): string
832
784
{
833
785
$ resolverMock = $ this ->getMockBuilder (CustomerResolver::class)
834
786
->disableOriginalConstructor ()
@@ -841,13 +793,6 @@ private function getProviderInterfaceMock()
841
793
->getKeyCalculatorForResolver ($ resolverMock )
842
794
->calculateCacheKey ();
843
795
844
- return $ cacheKeyFactor ;
845
- }
846
-
847
- private static function getCacheKeyForCustomerResolver (): array
848
- {
849
- $ cacheKeyFactor = static fn (self $ testCase ) => $ testCase ->getProviderInterfaceMock ();
850
-
851
796
$ cacheKeyQueryPayloadMetadata = CustomerResolver::class . '\Interceptor[] ' ;
852
797
853
798
$ cacheKeyParts = [
@@ -857,10 +802,10 @@ private static function getCacheKeyForCustomerResolver(): array
857
802
];
858
803
859
804
// strtoupper is called in \Magento\Framework\Cache\Frontend\Adapter\Zend::_unifyId
860
- return $ cacheKeyParts ;
805
+ return strtoupper ( implode ( ' _ ' , $ cacheKeyParts)) ;
861
806
}
862
807
863
- private static function getCustomerQuery (): string
808
+ private function getCustomerQuery (): string
864
809
{
865
810
return <<<QUERY
866
811
{
0 commit comments