| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This file is part of the Marlon Ogone package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * (c) Marlon BVBA <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | namespace Ogone\Tests\DirectLink; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Ogone\DirectLink\DirectLinkPaymentResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 15 |  | View Code Duplication | class DirectLinkPaymentResponseTest extends \PHPUnit_Framework_TestCase | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @expectedException InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function CantExistWithoutXmlFile() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $paymentResponse = new DirectLinkPaymentResponse(''); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** @test */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public function ParametersCanBeRetrieved() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $xml = $this->provideXML(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $paymentResponse = new DirectLinkPaymentResponse($xml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this->assertEquals('123', $paymentResponse->getParam('orderid')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @expectedException InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     public function RequestIsFilteredFromNonOgoneParameters() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $xml = $this->provideXML(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $paymentResponse = new DirectLinkPaymentResponse($xml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $paymentResponse->getParam('unknown_param'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @expectedException InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     public function ChecksInvalidXml() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $xml = $this->provideInvalidXML(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $paymentResponse = new DirectLinkPaymentResponse($xml); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** @test */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public function ChecksStatus() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $xml = $this->provideXML(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $paymentResponse = new DirectLinkPaymentResponse($xml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $this->assertTrue($paymentResponse->isSuccessful()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** @test */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     public function AmountIsConvertedToCent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $xml = $this->provideXML(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $paymentResponse = new DirectLinkPaymentResponse($xml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->assertEquals(100, $paymentResponse->getParam('amount')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     public function provideFloats() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             array('17.89', 1789), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             array('65.35', 6535), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             array('12.99', 1299), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @dataProvider provideFloats | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     public function CorrectlyConvertsFloatAmountsToInteger($string, $integer) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $xml = $this->provideXML($string); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $paymentResponse = new DirectLinkPaymentResponse($xml); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $this->assertEquals($integer, $paymentResponse->getParam('amount')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * Helper method to setup an xml-string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |     private function provideXML($amount = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |         $xml = '<?xml version="1.0"?> | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |                 <ncresponse | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |                 ORDERID="123" | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |                 PAYID="0" | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |                 NCSTATUS="5" | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |                 NCERROR="" | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |                 ACCEPTANCE="" | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |                 STATUS="5" | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |                 AMOUNT="'.(($amount) ? $amount : '1').'" | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |                 CURRENCY="EUR" | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |                 PM="" | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |                 BRAND="" | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |                 NCERRORPLUS=""> | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |                 </ncresponse>'; | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |         return $xml; | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * Helper method to setup an invalid xml-string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     private function provideInvalidXML() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $xml = '<?xml version="1.0"?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                 <ncresponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                 </ncresponse>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         return $xml; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 134 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 135 |  |  |  | 
            
                        
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.