27
27
use Magento \TestFramework \Helper \Bootstrap ;
28
28
use Magento \TestFramework \TestCase \GraphQl \ResolverCacheAbstract ;
29
29
use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
30
- use PHPUnit \Framework \MockObject \MockObject ;
31
- use PHPUnit \Framework \TestCase ;
32
30
33
31
/**
34
32
* Test for customer resolver cache
@@ -62,11 +60,6 @@ class CustomerTest extends ResolverCacheAbstract
62
60
*/
63
61
private $ registry ;
64
62
65
- /**
66
- * @var CustomerResolver|MockObject
67
- */
68
- private static $ resolverMock ;
69
-
70
63
protected function setUp (): void
71
64
{
72
65
$ this ->objectManager = Bootstrap::getObjectManager ();
@@ -88,10 +81,6 @@ protected function setUp(): void
88
81
$ this ->registry ->unregister ('isSecureArea ' );
89
82
$ this ->registry ->register ('isSecureArea ' , true );
90
83
91
- self ::$ resolverMock = $ this ->getMockBuilder (CustomerResolver::class)
92
- ->disableOriginalConstructor ()
93
- ->getMock ();
94
-
95
84
parent ::setUp ();
96
85
}
97
86
@@ -310,13 +299,13 @@ public function testCustomerResolverCacheInvalidationOnStoreChange()
310
299
* @param CustomerInterface $customer
311
300
* @return void
312
301
*/
313
- private static function assertCurrentCustomerCacheRecordExists (CustomerInterface $ customer )
302
+ private function assertCurrentCustomerCacheRecordExists (CustomerInterface $ customer )
314
303
{
315
- $ cacheKey = self :: getCacheKeyForCustomerResolver ();
304
+ $ cacheKey = $ this -> getCacheKeyForCustomerResolver ();
316
305
$ cacheEntry = Bootstrap::getObjectManager ()->get (GraphQlResolverCache::class)->load ($ cacheKey );
317
306
$ cacheEntryDecoded = json_decode ($ cacheEntry , true );
318
307
319
- self :: assertEquals (
308
+ $ this -> assertEquals (
320
309
$ customer ->getEmail (),
321
310
$ cacheEntryDecoded ['email ' ]
322
311
);
@@ -629,7 +618,7 @@ public function testCustomerQueryingCustomerWithDifferentStoreHeaderDoesNotGener
629
618
);
630
619
}
631
620
632
- public static function invalidationMechanismProvider (): array
621
+ public function invalidationMechanismProvider (): array
633
622
{
634
623
// provider is invoked before setUp() is called so need to init here
635
624
$ repo = Bootstrap::getObjectManager ()->get (
@@ -652,51 +641,51 @@ function (CustomerInterface $customer) use ($repo) {
652
641
'add and delete address ' => [
653
642
function (CustomerInterface $ customer , $ tokenString ) {
654
643
// create new address because default billing address cannot be deleted
655
- self :: graphQlMutation (
656
- self :: getCreateAddressMutation ("4000 Polk St " ),
644
+ $ this -> graphQlMutation (
645
+ $ this -> getCreateAddressMutation ("4000 Polk St " ),
657
646
[],
658
647
'' ,
659
648
['Authorization ' => 'Bearer ' . $ tokenString ]
660
649
);
661
650
// query for customer to cache data after address creation
662
- $ result = self :: graphQlQuery (
663
- self :: getCustomerQuery (),
651
+ $ result = $ this -> graphQlQuery (
652
+ $ this -> getCustomerQuery (),
664
653
[],
665
654
'' ,
666
655
['Authorization ' => 'Bearer ' . $ tokenString ]
667
656
);
668
657
// assert that cache record exists for given customer
669
- self :: assertCurrentCustomerCacheRecordExists ($ customer );
658
+ $ this -> assertCurrentCustomerCacheRecordExists ($ customer );
670
659
671
660
$ addressId = $ result ['customer ' ]['addresses ' ][1 ]['id ' ];
672
- $ result = self :: graphQlMutation (
673
- self :: getDeleteAddressMutation ($ addressId ),
661
+ $ result = $ this -> graphQlMutation (
662
+ $ this -> getDeleteAddressMutation ($ addressId ),
674
663
[],
675
664
'' ,
676
665
['Authorization ' => 'Bearer ' . $ tokenString ]
677
666
);
678
- self :: assertTrue ($ result ['deleteCustomerAddress ' ]);
667
+ $ this -> assertTrue ($ result ['deleteCustomerAddress ' ]);
679
668
},
680
669
],
681
670
'update address ' => [
682
671
function (CustomerInterface $ customer , $ tokenString ) {
683
672
// query for customer to cache data after address creation
684
- $ result = self :: graphQlQuery (
685
- self :: getCustomerQuery (),
673
+ $ result = $ this -> graphQlQuery (
674
+ $ this -> getCustomerQuery (),
686
675
[],
687
676
'' ,
688
677
['Authorization ' => 'Bearer ' . $ tokenString ]
689
678
);
690
679
691
680
$ addressId = $ result ['customer ' ]['addresses ' ][0 ]['id ' ];
692
- $ result = self :: graphQlMutation (
693
- self :: getUpdateAddressStreetMutation ($ addressId , "8000 New St " ),
681
+ $ result = $ this -> graphQlMutation (
682
+ $ this -> getUpdateAddressStreetMutation ($ addressId , "8000 New St " ),
694
683
[],
695
684
'' ,
696
685
['Authorization ' => 'Bearer ' . $ tokenString ]
697
686
);
698
- self :: assertEquals ($ addressId , $ result ['updateCustomerAddress ' ]['id ' ]);
699
- 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 ]);
700
689
},
701
690
],
702
691
];
@@ -706,7 +695,7 @@ function (CustomerInterface $customer, $tokenString) {
706
695
* @param string $streetAddress
707
696
* @return string
708
697
*/
709
- private static function getCreateAddressMutation ($ streetAddress )
698
+ private function getCreateAddressMutation ($ streetAddress )
710
699
{
711
700
return <<<MUTATIONCREATE
712
701
mutation{
@@ -744,7 +733,7 @@ private static function getCreateAddressMutation($streetAddress)
744
733
* @param string $streetAddress
745
734
* @return string
746
735
*/
747
- private static function getUpdateAddressStreetMutation ($ addressId , $ streetAddress )
736
+ private function getUpdateAddressStreetMutation ($ addressId , $ streetAddress )
748
737
{
749
738
return <<<MUTATIONUPDATE
750
739
mutation{
@@ -765,7 +754,7 @@ private static function getUpdateAddressStreetMutation($addressId, $streetAddres
765
754
* @param int $addressId
766
755
* @return string
767
756
*/
768
- private static function getDeleteAddressMutation ($ addressId )
757
+ private function getDeleteAddressMutation ($ addressId )
769
758
{
770
759
return <<<MUTATIONDELETE
771
760
mutation{
@@ -791,9 +780,11 @@ private function assertTagsByCacheKeyAndCustomer(string $cacheKey, CustomerInter
791
780
);
792
781
}
793
782
794
- private static function getCacheKeyForCustomerResolver (): string
783
+ private function getCacheKeyForCustomerResolver (): string
795
784
{
796
- $ resolverMock = self ::$ resolverMock ;
785
+ $ resolverMock = $ this ->getMockBuilder (CustomerResolver::class)
786
+ ->disableOriginalConstructor ()
787
+ ->getMock ();
797
788
798
789
/** @var ProviderInterface $cacheKeyCalculatorProvider */
799
790
$ cacheKeyCalculatorProvider = Bootstrap::getObjectManager ()->get (ProviderInterface::class);
@@ -814,7 +805,7 @@ private static function getCacheKeyForCustomerResolver(): string
814
805
return strtoupper (implode ('_ ' , $ cacheKeyParts ));
815
806
}
816
807
817
- private static function getCustomerQuery (): string
808
+ private function getCustomerQuery (): string
818
809
{
819
810
return <<<QUERY
820
811
{
0 commit comments