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