| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace advancedhosters\hipanel\tests\acceptance\module\finance\manager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use hipanel\modules\finance\tests\_support\Page\plan\Create; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use hipanel\modules\finance\tests\_support\Page\plan\View; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use hipanel\modules\finance\tests\_support\Page\plan\Update; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use hipanel\modules\finance\tests\_support\Page\plan\Delete; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use hipanel\modules\finance\tests\_support\Page\plan\Index; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use hipanel\tests\_support\Step\Acceptance\Manager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class TariffPlansCrudCest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     private $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     private $fields; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 24 |  | View Code Duplication |     public function ensureThatICanCreateTariffPlan(Manager $I) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->fields = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             'name' => uniqid(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             'type' => 'Template', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             'client' => 'hipanel_test_manager', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             'currency' => 'USD', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             'note' => 'test note', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $plan = new Create($I, $this->fields); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $plan->seeFields(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->id = $plan->createPlan(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->ensureThatICanSeeTariffPlan($I); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     private function ensureThatICanSeeTariffPlan(Manager $I) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $plan = new View($I, $this->fields, $this->id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $plan->visitPlan(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $plan->seePlan(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $search = new Index($I); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $search->ensurePageWorks(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $search->ensurePlanCanBeFound($this->fields['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 49 |  | View Code Duplication |     public function ensureThatICanUpdateTariffPlan(Manager $I) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->fields = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             'name' => uniqid(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             'type' => 'Server', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             'client' => 'hipanel_test_manager', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             'currency' => 'EUR', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             'note' => 'new_test_note', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $plan = new Update($I, $this->fields); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->id = $plan->updatePlan($this->id); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->ensureThatICanSeeTariffPlan($I); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     public function ensureThatICanDeleteTariffPlan(Manager $I) | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         (new Delete($I, null, $this->id))->deletePlan(); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         $this->ensureThatIDontSeeTariffPlan($I); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     private function ensureThatIDontSeeTariffPlan(Manager $I) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $search = new Index($I); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $search->ensurePageWorks(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $search->ensurePlanNotFound($this->fields['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 75 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |  | 
            
                        
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.