2323use Sylius \Component \Core \Model \PaymentInterface ;
2424use Sylius \Component \Core \Repository \PaymentRepositoryInterface ;
2525use Sylius \PayPalPlugin \DependencyInjection \SyliusPayPalExtension ;
26+ use Sylius \PayPalPlugin \Exception \PaymentNotFoundException ;
2627use Sylius \PayPalPlugin \Repository \Query \PaypalPaymentQuery ;
2728
2829final class PaypalPaymentQueryTest extends TestCase
@@ -101,7 +102,7 @@ public function testGetForUpdateByOrderIdReturnsPaymentWhenCastIsNotAvailable():
101102 $ this ->assertSame ($ payment , $ result );
102103 }
103104
104- public function testGetForUpdateByOrderIdReturnsNullWhenNoPaymentFound (): void
105+ public function testGetForUpdateByOrderIdThrowsExceptionWhenNoPaymentFound (): void
105106 {
106107 $ paypalOrderId = 'PAYPAL123 ' ;
107108
@@ -121,12 +122,12 @@ public function testGetForUpdateByOrderIdReturnsNullWhenNoPaymentFound(): void
121122 $ configuration ->method ('getCustomStringFunction ' )->with ('CAST ' )->willReturn (null );
122123 $ this ->entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
123124
124- $ result = $ this ->query -> getForUpdateByOrderId ( $ paypalOrderId );
125+ $ this ->expectException (PaymentNotFoundException::class );
125126
126- $ this ->assertNull ( $ result );
127+ $ this ->query -> getForUpdateByOrderId ( $ paypalOrderId );
127128 }
128129
129- public function testGetForUpdateByOrderIdReturnsNullWhenPaymentDoesNotMatchOrderId (): void
130+ public function testGetForUpdateByOrderIdThrowsExceptionWhenPaymentDoesNotMatchOrderId (): void
130131 {
131132 $ paypalOrderId = 'PAYPAL123 ' ;
132133 $ payment = $ this ->createMock (PaymentInterface::class);
@@ -148,12 +149,12 @@ public function testGetForUpdateByOrderIdReturnsNullWhenPaymentDoesNotMatchOrder
148149 $ configuration ->method ('getCustomStringFunction ' )->with ('CAST ' )->willReturn (null );
149150 $ this ->entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
150151
151- $ result = $ this ->query -> getForUpdateByOrderId ( $ paypalOrderId );
152+ $ this ->expectException (PaymentNotFoundException::class );
152153
153- $ this ->assertNull ( $ result );
154+ $ this ->query -> getForUpdateByOrderId ( $ paypalOrderId );
154155 }
155156
156- public function testGetForUpdateByOrderIdReturnsNullWhenDetailsDoNotContainPaypalOrderId (): void
157+ public function testGetForUpdateByOrderIdThrowsExceptionWhenDetailsDoNotContainPaypalOrderId (): void
157158 {
158159 $ paypalOrderId = 'PAYPAL123 ' ;
159160 $ payment = $ this ->createMock (PaymentInterface::class);
@@ -175,9 +176,9 @@ public function testGetForUpdateByOrderIdReturnsNullWhenDetailsDoNotContainPaypa
175176 $ configuration ->method ('getCustomStringFunction ' )->with ('CAST ' )->willReturn (null );
176177 $ this ->entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
177178
178- $ result = $ this ->query -> getForUpdateByOrderId ( $ paypalOrderId );
179+ $ this ->expectException (PaymentNotFoundException::class );
179180
180- $ this ->assertNull ( $ result );
181+ $ this ->query -> getForUpdateByOrderId ( $ paypalOrderId );
181182 }
182183
183184 public function testGetForCancellationByOrderIdReturnsPaymentWithCancellableStates (): void
@@ -234,7 +235,7 @@ public function testGetForRefundingByOrderIdReturnsPaymentWithRefundableStates()
234235 $ this ->assertSame ($ payment , $ result );
235236 }
236237
237- public function testGetForCancellationByOrderIdReturnsNullWhenNoPaymentFound (): void
238+ public function testGetForCancellationByOrderIdThrowsExceptionWhenNoPaymentFound (): void
238239 {
239240 $ paypalOrderId = 'PAYPAL123 ' ;
240241
@@ -254,12 +255,12 @@ public function testGetForCancellationByOrderIdReturnsNullWhenNoPaymentFound():
254255 $ configuration ->method ('getCustomStringFunction ' )->with ('CAST ' )->willReturn (null );
255256 $ this ->entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
256257
257- $ result = $ this ->query -> getForCancellationByOrderId ( $ paypalOrderId );
258+ $ this ->expectException (PaymentNotFoundException::class );
258259
259- $ this ->assertNull ( $ result );
260+ $ this ->query -> getForCancellationByOrderId ( $ paypalOrderId );
260261 }
261262
262- public function testGetForRefundingByOrderIdReturnsNullWhenNoPaymentFound (): void
263+ public function testGetForRefundingByOrderIdThrowsExceptionWhenNoPaymentFound (): void
263264 {
264265 $ paypalOrderId = 'PAYPAL123 ' ;
265266
@@ -279,9 +280,9 @@ public function testGetForRefundingByOrderIdReturnsNullWhenNoPaymentFound(): voi
279280 $ configuration ->method ('getCustomStringFunction ' )->with ('CAST ' )->willReturn (null );
280281 $ this ->entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
281282
282- $ result = $ this ->query -> getForRefundingByOrderId ( $ paypalOrderId );
283+ $ this ->expectException (PaymentNotFoundException::class );
283284
284- $ this ->assertNull ( $ result );
285+ $ this ->query -> getForRefundingByOrderId ( $ paypalOrderId );
285286 }
286287
287288 public function testGetForUpdateByOrderIdUsesCorrectStates (): void
@@ -317,6 +318,8 @@ public function testGetForUpdateByOrderIdUsesCorrectStates(): void
317318 $ configuration ->method ('getCustomStringFunction ' )->with ('CAST ' )->willReturn (null );
318319 $ this ->entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
319320
321+ $ this ->expectException (PaymentNotFoundException::class);
322+
320323 $ this ->query ->getForUpdateByOrderId ($ paypalOrderId );
321324 }
322325
@@ -353,6 +356,8 @@ public function testGetForCancellationByOrderIdUsesCorrectStates(): void
353356 $ configuration ->method ('getCustomStringFunction ' )->with ('CAST ' )->willReturn (null );
354357 $ this ->entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
355358
359+ $ this ->expectException (PaymentNotFoundException::class);
360+
356361 $ this ->query ->getForCancellationByOrderId ($ paypalOrderId );
357362 }
358363
@@ -386,6 +391,8 @@ public function testGetForRefundingByOrderIdUsesCorrectStates(): void
386391 $ configuration ->method ('getCustomStringFunction ' )->with ('CAST ' )->willReturn (null );
387392 $ this ->entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
388393
394+ $ this ->expectException (PaymentNotFoundException::class);
395+
389396 $ this ->query ->getForRefundingByOrderId ($ paypalOrderId );
390397 }
391398
0 commit comments