Alfonso Alba García avatar Alfonso Alba García committed aa8c40b

Replacing host/port/dbname by DSN

Comments (0)

Files changed (3)

src/AAlba/PleskBackup/DomainList/Factory/PleskDBFactory.php

     private $_pdo;
 
     private
-        $_host,
-        $_port,
-        $_database,
+        $_dsn,
         $_username,
         $_password;
 
             $parser = new Parser();
             try{
                 $databaseData = $parser->parse(file_get_contents($data));
-                $this->_host = $databaseData['host'];
-                $this->_port = $databaseData['port'];
-                $this->_database = $databaseData['database'];
+                $this->_dsn = $databaseData['dsn'];
                 $this->_username = $databaseData['username'];
                 $this->_password = $databaseData['password'];
             } catch (\Exception $e) {
 
         } else if(is_array($data))
         {
-            $this->_host = $data['host'];
-            $this->_port = $data['port'];
-            $this->_database = $data['database'];
+            $this->_dsn = $data['dsn'];
             $this->_username = $data['username'];
             $this->_password = $data['password'];
         }
     {
         try
         {
-            $this->_pdo = new PDO('mysql:host='.$this->_host.';port='.$this->_port.';dbname='.$this->_database,$this->_username,$this->_password);
+            $this->_pdo = new \PDO('mysql:host='.$this->_host.';port='.$this->_port.';dbname='.$this->_database,$this->_username,$this->_password);
         } catch (\Exception $e)
         {
             throw $e;
         $this->_pdo = null;
     }
 
-    public function getHost()
+    public function getDSN()
     {
-        return $this->_host;
+        return $this->_dsn;
     }
-    public function setHost($host)
+    public function setDSN($dsn)
     {
-        $this->_host = $host;
-    }
-
-    public function getPort()
-    {
-        return $this->_port;
-    }
-
-    public function setPort($port)
-    {
-        $this->_port = $port;
-    }
-
-    public function getDatabase()
-    {
-        return $this->_database;
-    }
-
-    public function setDatabase($database)
-    {
-        $this->_database = $database;
+        $this->_dsn = $dsn;
     }
 
     public function getUsername()

tests/DomainListPleskDBTest.php

 
     public function testThatICanGetTheDatabaseConnectionParameters()
     {
-        $this->_factory->setHost("FAKEHOST");
-        $this->_factory->setPort("FAKEPORT");
-        $this->_factory->setDatabase("FAKEDATABASE");
+        $this->_factory->setDSN("FAKEDSN");
         $this->_factory->setUsername("FAKEUSERNAME");
         $this->_factory->setPassword("FAKEPASSWORD");
 
-        $this->assertEquals("FAKEHOST", $this->_factory->getHost(),'I get the host I set');
-        $this->assertEquals("FAKEPORT", $this->_factory->getPort(),'I get the port I set');
-        $this->assertEquals("FAKEDATABASE", $this->_factory->getDatabase(),'I get the database I set');
+        $this->assertEquals("FAKEDSN", $this->_factory->getDSN(),'I get the DSN I set');
         $this->assertEquals("FAKEUSERNAME", $this->_factory->getUsername(),'I get the username I set');
         $this->assertEquals("FAKEPASSWORD", $this->_factory->getPassword(),'I get the password I set');
     }
         $factory = new PleskDBFactory($file);
 
         $testData = $parser->parse(file_get_contents($file));
-        $this->assertEquals($testData['host'], $factory->getHost());
-        $this->assertEquals($testData['port'], $factory->getPort());
-        $this->assertEquals($testData['database'], $factory->getDatabase());
+        $this->assertEquals($testData['dsn'], $factory->getDSN());
         $this->assertEquals($testData['username'], $factory->getUsername());
         $this->assertEquals($testData['password'], $factory->getPassword());
     }
     public function testSetDatabaseDataFromArray()
     {
         $testData = array(
-            'host' => 'FAKEHOST',
-            'port' => 'FAKEPORT',
-            'database' => 'FAKEDATABASE',
+            'dsn' => 'FAKEDSN',
             'username' => 'FAKEUSERNAME',
             'password' => 'FAKEPASSWORD'
 
         );
         $factory = new PleskDBFactory($testData);
 
-        $this->assertEquals($testData['host'], $factory->getHost());
-        $this->assertEquals($testData['port'], $factory->getPort());
-        $this->assertEquals($testData['database'], $factory->getDatabase());
+        $this->assertEquals($testData['dsn'], $factory->getDSN());
         $this->assertEquals($testData['username'], $factory->getUsername());
         $this->assertEquals($testData['password'], $factory->getPassword());
     }

tests/config/pleskdb.yml

-host: FAKEHOST
-port: FAKEPORT
-database: FAKEDATABASE
+dsn: FAKEDSN
 username: FAKEUSERNAME
 password: FAKEPASSWORD
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.