| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Loevgaard\DandomainAltapayBundle\Tests\Handler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Loevgaard\AltaPay\Client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Loevgaard\AltaPay\Payload\OrderLine; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Loevgaard\AltaPay\Payload\RefundCapturedReservation as RefundCapturedReservationPayload; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Loevgaard\AltaPay\Response\RefundCapturedReservation as RefundCapturedReservationResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Loevgaard\DandomainAltapayBundle\Entity\Payment; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Loevgaard\DandomainAltapayBundle\Entity\PaymentLine; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Loevgaard\DandomainAltapayBundle\Handler\PaymentHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Loevgaard\DandomainAltapayBundle\Manager\PaymentManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | final class PaymentHandlerTest extends TestCase | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 17 |  | View Code Duplication |     public function testRefund1() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         $amount = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         $orderLines = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         $altapayClient = $this->getAltapayClient(); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         $altapayClient | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |             ->expects($this->any()) | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |             ->method('refundCapturedReservation') | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             ->willReturnCallback(function ($val) use (&$amount, &$orderLines) { | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |                 /** @var RefundCapturedReservationPayload $val */ | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |                 $amount = $val->getAmount(); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |                 $orderLines = $val->getOrderLines(); | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |                 $response = $this->getMockBuilder(RefundCapturedReservationResponse::class) | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |                     ->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |                     ->getMock() | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |                 ; | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |                 return $response; | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |             }) | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         ; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         $payment = $this->getPayment(); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         $payment->setAltapayId('altapayid'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $paymentHandler = $this->getPaymentHandler($altapayClient); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         $paymentHandler->refund($payment); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         $this->assertSame(null, $amount); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         $this->assertSame([], $orderLines); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 50 |  | View Code Duplication |     public function testRefund2() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $amount = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $orderLines = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $altapayClient = $this->getAltapayClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $altapayClient | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             ->expects($this->any()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             ->method('refundCapturedReservation') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             ->willReturnCallback(function ($val) use (&$amount, &$orderLines) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 /** @var RefundCapturedReservationPayload $val */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                 $amount = $val->getAmount(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 $orderLines = $val->getOrderLines(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 $response = $this->getMockBuilder(RefundCapturedReservationResponse::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                     ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                     ->getMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $payment = $this->getPayment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $payment->setAltapayId('altapayid'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $paymentHandler = $this->getPaymentHandler($altapayClient); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $paymentHandler->refund($payment, null, 100.55); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $this->assertSame(100.55, $amount); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $this->assertSame([], $orderLines); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 83 |  | View Code Duplication |     public function testRefundAmountMatchesPaymentLineAmount() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $amount = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $orderLines = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $altapayClient = $this->getAltapayClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $altapayClient | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             ->expects($this->any()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             ->method('refundCapturedReservation') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             ->willReturnCallback(function ($val) use (&$amount, &$orderLines) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                 /** @var RefundCapturedReservationPayload $val */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                 $amount = $val->getAmount(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                 $orderLines = $val->getOrderLines(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 $response = $this->getMockBuilder(RefundCapturedReservationResponse::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                     ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                     ->getMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                 ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                 return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $payment = $this->getPayment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $payment->setAltapayId('altapayid'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $paymentLines = []; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         /** @var PaymentLine|\PHPUnit_Framework_MockObject_MockObject $paymentLine */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $paymentLine = $this->getMockForAbstractClass(PaymentLine::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         $paymentLine->setPrice(79.96) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             ->setVat(25) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             ->setQuantity(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |             ->setName('name') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             ->setProductNumber('productnumber') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $paymentHandler = $this->getPaymentHandler($altapayClient); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         $paymentHandler->refund($payment, [$paymentLine], 99.95); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $this->assertSame(99.95, $amount); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         /** @var OrderLine $orderLine */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $orderLine = $orderLines[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $this->assertSame(99.95, $orderLine->getUnitPrice()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         $this->assertSame(25.0, $orderLine->getTaxPercent()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $this->assertSame(1.0, $orderLine->getQuantity()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $this->assertSame('name', $orderLine->getDescription()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $this->assertSame('productnumber', $orderLine->getItemId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 133 |  | View Code Duplication |     public function testRefundAmountDoesNotMatchPaymentLineAmount() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         $amount = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         $orderLines = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $altapayClient = $this->getAltapayClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         $altapayClient | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |             ->expects($this->any()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             ->method('refundCapturedReservation') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             ->willReturnCallback(function ($val) use (&$amount, &$orderLines) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                 /** @var RefundCapturedReservationPayload $val */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                 $amount = $val->getAmount(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                 $orderLines = $val->getOrderLines(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |                 $response = $this->getMockBuilder(RefundCapturedReservationResponse::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |                     ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |                     ->getMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |                 ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |                 return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         $payment = $this->getPayment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         $payment->setAltapayId('altapayid'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         $paymentLines = []; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         /** @var PaymentLine|\PHPUnit_Framework_MockObject_MockObject $paymentLine */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         $paymentLine = $this->getMockForAbstractClass(PaymentLine::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         $paymentLine->setPrice(100) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             ->setVat(25) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |             ->setQuantity(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             ->setName('name') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             ->setProductNumber('productnumber') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         $paymentHandler = $this->getPaymentHandler($altapayClient); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         $paymentHandler->refund($payment, [$paymentLine], 80); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |         $this->assertSame(80.0, $amount); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         /** @var OrderLine $orderLine */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         $orderLine = $orderLines[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         $this->assertSame(80.0, $orderLine->getUnitPrice()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         $this->assertSame(1.0, $orderLine->getQuantity()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         $this->assertSame('refund', $orderLine->getDescription()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |         $this->assertSame('refund', $orderLine->getItemId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |      * @return Payment|\PHPUnit_Framework_MockObject_MockObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |     private function getPayment() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         return $this->getMockForAbstractClass(Payment::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |      * @return Client|\PHPUnit_Framework_MockObject_MockObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     private function getAltapayClient() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         /** @var Client|\PHPUnit_Framework_MockObject_MockObject $altapayClient */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $altapayClient = $this->getMockBuilder(Client::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |             ->getMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         return $altapayClient; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |      * @return PaymentHandler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |     private function getPaymentHandler($altapayClient): PaymentHandler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |         /** @var PaymentManager|\PHPUnit_Framework_MockObject_MockObject $paymentManager */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         $paymentManager = $this->getMockBuilder(PaymentManager::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |             ->getMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         return new PaymentHandler($altapayClient, $paymentManager); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 217 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 218 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.