2323use Magento \ReCaptchaUi \Model \ValidationConfigResolverInterface ;
2424use Magento \ReCaptchaValidationApi \Api \ValidatorInterface ;
2525use Magento \ReCaptchaValidationApi \Model \ValidationErrorMessagesProvider ;
26+ use PHPUnit \Framework \Attributes \DataProvider ;
2627use PHPUnit \Framework \MockObject \MockObject ;
2728use PHPUnit \Framework \TestCase ;
2829use Psr \Log \LoggerInterface ;
30+ use Magento \Framework \TestFramework \Unit \Helper \MockCreationTrait ;
2931
3032/**
3133 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3234 */
3335class PayPalObserverTest extends TestCase
3436{
37+ use MockCreationTrait;
38+
3539 /**
3640 * @var ValidatorInterface|MockObject
3741 */
@@ -68,14 +72,14 @@ class PayPalObserverTest extends TestCase
6872 protected function setUp (): void
6973 {
7074 parent ::setUp ();
71- $ captchaResponseResolver = $ this ->getMockForAbstractClass (CaptchaResponseResolverInterface::class);
72- $ validationConfigResolver = $ this ->getMockForAbstractClass (ValidationConfigResolverInterface::class);
73- $ this ->captchaValidator = $ this ->getMockForAbstractClass (ValidatorInterface::class);
75+ $ captchaResponseResolver = $ this ->createMock (CaptchaResponseResolverInterface::class);
76+ $ validationConfigResolver = $ this ->createMock (ValidationConfigResolverInterface::class);
77+ $ this ->captchaValidator = $ this ->createMock (ValidatorInterface::class);
7478 $ actionFlag = $ this ->createMock (ActionFlag::class);
75- $ serializer = $ this ->getMockForAbstractClass (SerializerInterface::class);
76- $ this ->isCaptchaEnabled = $ this ->getMockForAbstractClass (IsCaptchaEnabledInterface::class);
77- $ logger = $ this ->getMockForAbstractClass (LoggerInterface::class);
78- $ errorMessageConfig = $ this ->getMockForAbstractClass (ErrorMessageConfigInterface::class);
79+ $ serializer = $ this ->createMock (SerializerInterface::class);
80+ $ this ->isCaptchaEnabled = $ this ->createMock (IsCaptchaEnabledInterface::class);
81+ $ logger = $ this ->createMock (LoggerInterface::class);
82+ $ errorMessageConfig = $ this ->createMock (ErrorMessageConfigInterface::class);
7983 $ validationErrorMessagesProvider = $ this ->createMock (ValidationErrorMessagesProvider::class);
8084 $ this ->reCaptchaSession = $ this ->createMock (ReCaptchaSession::class);
8185 $ this ->model = new PayPalObserver (
@@ -90,15 +94,15 @@ protected function setUp(): void
9094 $ validationErrorMessagesProvider ,
9195 $ this ->reCaptchaSession
9296 );
93- $ controller = $ this ->getMockBuilder (AbstractAction::class)
94- -> disableOriginalConstructor ()
95- -> onlyMethods ( ['getRequest ' , 'getResponse ' ])
96- -> getMockForAbstractClass ( );
97- $ request = $ this ->getMockForAbstractClass (RequestInterface::class);
98- $ response = $ this ->getMockBuilder (ResponseInterface::class)
99- -> disableOriginalConstructor ()
100- -> addMethods ( ['representJson ' ])
101- -> getMockForAbstractClass ( );
97+ $ controller = $ this ->createPartialMockWithReflection (
98+ AbstractAction::class,
99+ ['getRequest ' , 'getResponse ' , ' dispatch ' , ' execute ' ]
100+ );
101+ $ request = $ this ->createMock (RequestInterface::class);
102+ $ response = $ this ->createPartialMockWithReflection (
103+ ResponseInterface::class,
104+ ['representJson ' , ' sendResponse ' ]
105+ );
102106 $ controller ->method ('getRequest ' )->willReturn ($ request );
103107 $ controller ->method ('getResponse ' )->willReturn ($ response );
104108 $ this ->observer = new Observer (['controller_action ' => $ controller ]);
@@ -107,8 +111,8 @@ protected function setUp(): void
107111
108112 /**
109113 * @param array $mocks
110- * @dataProvider executeDataProvider
111114 */
115+ #[DataProvider('executeDataProvider ' )]
112116 public function testExecute (array $ mocks ): void
113117 {
114118 $ this ->configureMock ($ mocks );
@@ -132,7 +136,7 @@ public static function executeDataProvider(): array
132136 'reCaptchaSession ' => [
133137 [
134138 'method ' => 'save ' ,
135- 'expects ' => self :: never () ,
139+ 'expects ' => ' never ' ,
136140 ]
137141 ]
138142 ]
@@ -151,20 +155,20 @@ public static function executeDataProvider(): array
151155 'reCaptchaSession ' => [
152156 [
153157 'method ' => 'save ' ,
154- 'expects ' => self :: never () ,
158+ 'expects ' => ' never ' ,
155159 ]
156160 ],
157161 'captchaValidator ' => [
158162 [
159163 'method ' => 'isValid ' ,
160- 'expects ' => self :: once () ,
164+ 'expects ' => ' once ' ,
161165 'willReturnProperty ' => 'validationResult '
162166 ]
163167 ],
164168 'validationResult ' => [
165169 [
166170 'method ' => 'isValid ' ,
167- 'expects ' => self :: once () ,
171+ 'expects ' => ' once ' ,
168172 'willReturn ' => true ,
169173 ]
170174 ]
@@ -184,20 +188,20 @@ public static function executeDataProvider(): array
184188 'reCaptchaSession ' => [
185189 [
186190 'method ' => 'save ' ,
187- 'expects ' => self :: once () ,
191+ 'expects ' => ' once ' ,
188192 ]
189193 ],
190194 'captchaValidator ' => [
191195 [
192196 'method ' => 'isValid ' ,
193- 'expects ' => self :: once () ,
197+ 'expects ' => ' once ' ,
194198 'willReturnProperty ' => 'validationResult '
195199 ]
196200 ],
197201 'validationResult ' => [
198202 [
199203 'method ' => 'isValid ' ,
200- 'expects ' => self :: once () ,
204+ 'expects ' => ' once ' ,
201205 'willReturn ' => true ,
202206 ]
203207 ]
@@ -210,7 +214,9 @@ private function configureMock(array $mocks): void
210214 {
211215 foreach ($ mocks as $ prop => $ propMocks ) {
212216 foreach ($ propMocks as $ mock ) {
213- $ builder = $ this ->$ prop ->expects ($ mock ['expects ' ] ?? $ this ->any ());
217+ $ expectsValue = $ mock ['expects ' ] ?? 'any ' ;
218+ $ expects = $ this ->createInvocationMatcher ($ expectsValue );
219+ $ builder = $ this ->$ prop ->expects ($ expects );
214220 unset($ mock ['expects ' ]);
215221 foreach ($ mock as $ method => $ args ) {
216222 if ($ method === 'willReturnProperty ' ) {
0 commit comments