| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Tests\AppBundle\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | class SurveyControllerTest extends WebTestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     public function testSurveys() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         $client = static::createClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |         $client->request('GET', '/surveys', array(), array(), array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |             'PHP_AUTH_USER' => '[email protected]', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |             'PHP_AUTH_PW' => 'admin', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 21 |  | View Code Duplication |     public function testSurvey() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         $client = static::createClient(); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         $crawler = $client->request('GET', '/survey/1', array(), array(), array( | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             'PHP_AUTH_USER' => '[email protected]', | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |             'PHP_AUTH_PW' => 'admin', | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         )); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         $this->assertEquals(1, $crawler | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |             ->filter('h3:contains("Internship survey")') | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |             ->count()); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 37 |  | View Code Duplication |     public function testSurveyCreate() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $client = static::createClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $crawler = $client->request('GET', '/survey/create/internship', array(), array(), array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             'PHP_AUTH_USER' => '[email protected]', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             'PHP_AUTH_PW' => 'admin', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $form = $crawler->selectButton('Create survey')->form(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $form['survey[user]']->select('3'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $client->submit($form); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $client->followRedirects(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->assertTrue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             $client->getResponse()->isRedirect('/'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             'response is a redirect to homepage' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 61 |  | View Code Duplication |     public function testSurveyDelete() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $client = static::createClient(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $crawler = $client->request('GET', '/survey/delete/4', array(), array(), array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             'PHP_AUTH_USER' => '[email protected]', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             'PHP_AUTH_PW' => 'admin', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $form = $crawler->selectButton('Delete survey')->form(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $client->submit($form); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $client->followRedirects(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $this->assertTrue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             $client->getResponse()->isRedirect('/'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             'response is a redirect to homepage' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 82 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |  | 
            
                        
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.