diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c2acc1ac..68ad40d4 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -37,7 +37,7 @@ jobs: #- "8.3" services: mysql: - image: mysql:5.7-debian + image: mysql:5.7.42-debian env: MYSQL_DATABASE: 'doctrine1_test' MYSQL_USER: 'doctrine1' diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 73a7e5fa..2befcef6 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -52,6 +52,8 @@ * @version $Revision$ * @author Konsta Vesterinen * @author Lukas Smith (MDB2 library) + * + * @property Doctrine_Export $export */ abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate, Serializable { @@ -241,11 +243,9 @@ public function isConnected() } /** - * getOptions - * * Get array of all options * - * @return void + * @return array */ public function getOptions() { @@ -253,14 +253,9 @@ public function getOptions() } /** - * getOption - * - * Retrieves option - * - * @param string $option - * @return void + * @return null|mixed */ - public function getOption($option) + public function getOption(string $option) { if (isset($this->options[$option])) { return $this->options[$option]; @@ -268,14 +263,11 @@ public function getOption($option) } /** - * setOption - * * Set option value * - * @param string $option - * @return void + * @return mixed */ - public function setOption($option, $value) + public function setOption(string $option, $value) { return $this->options[$option] = $value; } @@ -1545,8 +1537,8 @@ public function dropDatabase() * which is always guaranteed to exist. Mysql: 'mysql', PostgreSQL: 'postgres', etc. * This value is set in the Doctrine_Export_{DRIVER} classes if required * - * @param string $info - * @return void + * @param array $info + * @return Doctrine_Connection */ public function getTmpConnection($info) { @@ -1556,7 +1548,9 @@ public function getTmpConnection($info) $pdoDsn .= 'unix_socket=' . $info['unix_socket'] . ';'; } - $pdoDsn .= 'host=' . $info['host']; + if ($info['host']) { + $pdoDsn .= 'host=' . $info['host']; + } if ($info['port']) { $pdoDsn .= ';port=' . $info['port']; @@ -1566,10 +1560,10 @@ public function getTmpConnection($info) $pdoDsn .= ';dbname=' . $this->export->tmpConnectionDatabase; } - $username = $this->getOption('username'); - $password = $this->getOption('password'); + $username = $info['user'] ?: $this->getOption('username'); + $password = $info['password'] ?: $this->getOption('password'); - $conn = $this->getManager()->openConnection(array($pdoDsn, $username, $password), 'doctrine_tmp_connection', false); + $conn = $this->getManager()->openConnection([$pdoDsn, $username, $password], 'doctrine_tmp_connection', false); $conn->setOption('username', $username); $conn->setOption('password', $password); diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index a2b08944..9c07f8d3 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -274,7 +274,7 @@ public static function connection($adapter = null, $name = null) /** * Opens a new connection and saves it to Doctrine_Manager->connections * - * @param PDO|Doctrine_Adapter_Interface $adapter database driver + * @param array|string|PDO|Doctrine_Adapter_Interface $adapter database driver * @param string $name name of the connection, if empty numeric key is used * @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name * @throws Doctrine_Manager_Exception if trying to open connection for unknown driver @@ -292,17 +292,17 @@ public function openConnection($adapter, $name = null, $setCurrent = true) if ( ! isset($adapter[0])) { throw new Doctrine_Manager_Exception('Empty data source name given.'); } - $e = explode(':', $adapter[0]); + $schema = explode(':', $adapter[0]); - if ($e[0] == 'uri') { - $e[0] = 'odbc'; + if ($schema[0] === 'uri') { + $schema[0] = 'odbc'; } $parts['dsn'] = $adapter[0]; - $parts['scheme'] = $e[0]; - $parts['user'] = (isset($adapter[1])) ? $adapter[1] : null; - $parts['pass'] = (isset($adapter[2])) ? $adapter[2] : null; - $driverName = $e[0]; + $parts['scheme'] = $schema[0]; + $parts['user'] = $adapter[1] ?? null; + $parts['pass'] = $adapter[2] ?? null; + $driverName = $schema[0]; $adapter = $parts; } else { $parts = $this->parseDsn($adapter); @@ -329,7 +329,7 @@ public function openConnection($adapter, $name = null, $setCurrent = true) return $this->_connections[$name]; } } else { - $name = $this->_index; + $name = (string) $this->_index; $this->_index++; } @@ -352,11 +352,23 @@ public function openConnection($adapter, $name = null, $setCurrent = true) /** * Parse a pdo style dsn in to an array of parts * - * @param array $dsn An array of dsn information - * @return array The array parsed + * @param string $dsn An array of dsn information + * @return array{ + * dsn: string, + * scheme: string, + * host: ?string, + * user: ?string, + * pass: ?string, + * password: ?string, + * port: ?string, + * path: ?string, + * query: ?string, + * fragment: ?string, + * unix_socket: ?string, + * } * @todo package:dbal */ - public function parsePdoDsn($dsn) + public function parsePdoDsn($dsn): array { $parts = array(); @@ -401,7 +413,7 @@ public function parsePdoDsn($dsn) * @param string $dsn * @return array $parts */ - protected function _buildDsnPartsArray($dsn) + protected function _buildDsnPartsArray(string $dsn) { // fix sqlite dsn so that it will parse correctly $dsn = str_replace("////", "/", $dsn); @@ -437,7 +449,7 @@ protected function _buildDsnPartsArray($dsn) * @return array Parsed contents of DSN * @todo package:dbal */ - public function parseDsn($dsn) + public function parseDsn(string $dsn) { $parts = $this->_buildDsnPartsArray($dsn); diff --git a/tests/MigrationMysqlTestCase.php b/tests/MigrationMysqlTestCase.php index 5e753ac0..5ca70b0e 100644 --- a/tests/MigrationMysqlTestCase.php +++ b/tests/MigrationMysqlTestCase.php @@ -32,6 +32,14 @@ */ class Doctrine_MigrationMysql_TestCase extends Doctrine_UnitTestCase { + public function prepareTables() + { + $this->tables[] = 'MigrationPhonenumber'; + $this->tables[] = 'MigrationUser'; + $this->tables[] = 'MigrationProfile'; + parent::prepareTables(); + } + public function setUp() { parent::setUp(); @@ -41,6 +49,8 @@ public function setUp() $this->connection->setOption('dsn', $dsn); $this->connection->dropDatabase(); $this->connection->createDatabase(); + + $this->connection->export->exportClasses($this->tables); } public function testAfterSuccessfullMigrationItWillSetMigratedVersionAsCurrentVersionInMysqlDB()