| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Azine\HybridAuthBundle\Services; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Azine\HybridAuthBundle\Entity\HybridAuthSessionData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Bundle\FrameworkBundle\Tests\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | class AzineHybridAuthTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     private $azineHybridAuth; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |     protected function setUp() | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |         $user = $this->getMockBuilder('FOS\UserBundle\Model\User')->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |         $router = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\Router') | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |             ->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |             ->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         $entityManager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |             ->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |             ->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |         $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |             ->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             ->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken') | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |             ->setConstructorArgs(array('key', $user)) | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |             ->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         $tokenStorage->expects($this->any()) | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |             ->method('getToken') | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |             ->will($this->returnValue($token)); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         $config = array('endpoint_route' => 'route', 'providers' => 'providers', 'debug_mode' => 'debug_mode', 'debug_file' => 'debug_file'); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         $this->azineHybridAuth = new AzineHybridAuth($router, $tokenStorage, $entityManager, | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |             $config, false, true, 55); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 42 |  | View Code Duplication |     public function testIsExpiredSession() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $sessionData = new HybridAuthSessionData(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $sessionData->setUsername('dominik'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $expirationDate = new \DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $expirationDate->modify('- 1 day'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $sessionData->setExpiresAt($expirationDate); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $isExpired = $this->azineHybridAuth->isExpiredSession($sessionData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->assertEquals(true, $isExpired); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 57 |  | View Code Duplication |     public function testIsNotExpiredSession() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $sessionData = new HybridAuthSessionData(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $sessionData->setUsername('dominik'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $expirationDate = new \DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $expirationDate->modify('+ 1 day'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $sessionData->setExpiresAt($expirationDate); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $isExpired = $this->azineHybridAuth->isExpiredSession($sessionData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->assertEquals(false, $isExpired); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 72 |  |  | } | 
            
                        
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.