| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Pyjac\ORM\DatabaseConnectionStringFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | class DatabaseConnectionStringFactoryTest extends PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |      * The instance of DatabaseConnectionStringFactory used in the test. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |      * @var Pyjac\ORM\DatabaseConnectionStringFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     protected $databaseConnectionStringFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * Configuration array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     protected $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $this->config = ['DBNAME' => 'Pyjac', 'DRIVER' => '', 'PASSWORD' => 'secret', 'HOSTNAME' => 'localhost', 'USERNAME' => 'pyjac']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->databaseConnectionStringFactory = new DatabaseConnectionStringFactory(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public function testCreateDatabaseSourceStringReturnsCorrectPostgresDatabaseSourceString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $this->config['DRIVER'] = 'postgres'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->assertEquals('pgsql:host=localhost;dbname=Pyjac', $dsn); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     public function testCreateDatabaseSourceStringReturnsCorrectMYSqlDatabaseSourceString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->config['DRIVER'] = 'mysql'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->assertEquals('mysql:host=localhost;dbname=Pyjac', $dsn); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     public function testCreateDatabaseSourceStringReturnsCorrectMYSqlDatabaseSourceStringWithPort() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->config['DRIVER'] = 'mysql'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->config['PORT'] = '3306'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->assertEquals('mysql:host=localhost;dbname=Pyjac;port=3306', $dsn); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     public function testCreateDatabaseSourceStringReturnsCorrectSQLiteDatabaseSourceString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $this->config['DRIVER'] = 'sqlite'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->assertEquals('sqlite::memory:', $dsn); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @expectedException Pyjac\ORM\Exception\DatabaseDriverNotSupportedException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |     public function testCreateDatabaseSourceStringThrowsDatabaseDriverNotSupportedExceptionWhenUnknownDriverIsPassed() | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |         $this->config['DRIVER'] = 'pyjac'; | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |         $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 65 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  | 
            
                        
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.