Skip to content

Commit 36f0816

Browse files
committed
WIP
1 parent 76bbc85 commit 36f0816

File tree

4 files changed

+52
-36
lines changed

4 files changed

+52
-36
lines changed

.github/workflows/continuous-integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
#- "8.3"
3838
services:
3939
mysql:
40-
image: mysql:5.7-debian
40+
image: mysql:5.7.42-debian
4141
env:
4242
MYSQL_DATABASE: 'doctrine1_test'
4343
MYSQL_USER: 'doctrine1'

lib/Doctrine/Connection.php

+15-21
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
* @version $Revision$
5353
* @author Konsta Vesterinen <[email protected]>
5454
* @author Lukas Smith <[email protected]> (MDB2 library)
55+
*
56+
* @property Doctrine_Export $export
5557
*/
5658
abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate, Serializable
5759
{
@@ -241,41 +243,31 @@ public function isConnected()
241243
}
242244

243245
/**
244-
* getOptions
245-
*
246246
* Get array of all options
247247
*
248-
* @return void
248+
* @return array<string, mixed>
249249
*/
250250
public function getOptions()
251251
{
252252
return $this->options;
253253
}
254254

255255
/**
256-
* getOption
257-
*
258-
* Retrieves option
259-
*
260-
* @param string $option
261-
* @return void
256+
* @return null|mixed
262257
*/
263-
public function getOption($option)
258+
public function getOption(string $option)
264259
{
265260
if (isset($this->options[$option])) {
266261
return $this->options[$option];
267262
}
268263
}
269264

270265
/**
271-
* setOption
272-
*
273266
* Set option value
274267
*
275-
* @param string $option
276-
* @return void
268+
* @return mixed
277269
*/
278-
public function setOption($option, $value)
270+
public function setOption(string $option, $value)
279271
{
280272
return $this->options[$option] = $value;
281273
}
@@ -1545,8 +1537,8 @@ public function dropDatabase()
15451537
* which is always guaranteed to exist. Mysql: 'mysql', PostgreSQL: 'postgres', etc.
15461538
* This value is set in the Doctrine_Export_{DRIVER} classes if required
15471539
*
1548-
* @param string $info
1549-
* @return void
1540+
* @param array $info
1541+
* @return Doctrine_Connection
15501542
*/
15511543
public function getTmpConnection($info)
15521544
{
@@ -1556,7 +1548,9 @@ public function getTmpConnection($info)
15561548
$pdoDsn .= 'unix_socket=' . $info['unix_socket'] . ';';
15571549
}
15581550

1559-
$pdoDsn .= 'host=' . $info['host'];
1551+
if ($info['host']) {
1552+
$pdoDsn .= 'host=' . $info['host'];
1553+
}
15601554

15611555
if ($info['port']) {
15621556
$pdoDsn .= ';port=' . $info['port'];
@@ -1566,10 +1560,10 @@ public function getTmpConnection($info)
15661560
$pdoDsn .= ';dbname=' . $this->export->tmpConnectionDatabase;
15671561
}
15681562

1569-
$username = $this->getOption('username');
1570-
$password = $this->getOption('password');
1563+
$username = $info['user'] ?: $this->getOption('username');
1564+
$password = $info['password'] ?: $this->getOption('password');
15711565

1572-
$conn = $this->getManager()->openConnection(array($pdoDsn, $username, $password), 'doctrine_tmp_connection', false);
1566+
$conn = $this->getManager()->openConnection([$pdoDsn, $username, $password], 'doctrine_tmp_connection', false);
15731567
$conn->setOption('username', $username);
15741568
$conn->setOption('password', $password);
15751569

lib/Doctrine/Manager.php

+26-14
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public static function connection($adapter = null, $name = null)
274274
/**
275275
* Opens a new connection and saves it to Doctrine_Manager->connections
276276
*
277-
* @param PDO|Doctrine_Adapter_Interface $adapter database driver
277+
* @param array|string|PDO|Doctrine_Adapter_Interface $adapter database driver
278278
* @param string $name name of the connection, if empty numeric key is used
279279
* @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name
280280
* @throws Doctrine_Manager_Exception if trying to open connection for unknown driver
@@ -292,17 +292,17 @@ public function openConnection($adapter, $name = null, $setCurrent = true)
292292
if ( ! isset($adapter[0])) {
293293
throw new Doctrine_Manager_Exception('Empty data source name given.');
294294
}
295-
$e = explode(':', $adapter[0]);
295+
$schema = explode(':', $adapter[0]);
296296

297-
if ($e[0] == 'uri') {
298-
$e[0] = 'odbc';
297+
if ($schema[0] === 'uri') {
298+
$schema[0] = 'odbc';
299299
}
300300

301301
$parts['dsn'] = $adapter[0];
302-
$parts['scheme'] = $e[0];
303-
$parts['user'] = (isset($adapter[1])) ? $adapter[1] : null;
304-
$parts['pass'] = (isset($adapter[2])) ? $adapter[2] : null;
305-
$driverName = $e[0];
302+
$parts['scheme'] = $schema[0];
303+
$parts['user'] = $adapter[1] ?? null;
304+
$parts['pass'] = $adapter[2] ?? null;
305+
$driverName = $schema[0];
306306
$adapter = $parts;
307307
} else {
308308
$parts = $this->parseDsn($adapter);
@@ -329,7 +329,7 @@ public function openConnection($adapter, $name = null, $setCurrent = true)
329329
return $this->_connections[$name];
330330
}
331331
} else {
332-
$name = $this->_index;
332+
$name = (string) $this->_index;
333333
$this->_index++;
334334
}
335335

@@ -352,11 +352,23 @@ public function openConnection($adapter, $name = null, $setCurrent = true)
352352
/**
353353
* Parse a pdo style dsn in to an array of parts
354354
*
355-
* @param array $dsn An array of dsn information
356-
* @return array The array parsed
355+
* @param string $dsn An array of dsn information
356+
* @return array{
357+
* dsn: string,
358+
* scheme: string,
359+
* host: ?string,
360+
* user: ?string,
361+
* pass: ?string,
362+
* password: ?string,
363+
* port: ?string,
364+
* path: ?string,
365+
* query: ?string,
366+
* fragment: ?string,
367+
* unix_socket: ?string,
368+
* }
357369
* @todo package:dbal
358370
*/
359-
public function parsePdoDsn($dsn)
371+
public function parsePdoDsn($dsn): array
360372
{
361373
$parts = array();
362374

@@ -401,7 +413,7 @@ public function parsePdoDsn($dsn)
401413
* @param string $dsn
402414
* @return array $parts
403415
*/
404-
protected function _buildDsnPartsArray($dsn)
416+
protected function _buildDsnPartsArray(string $dsn)
405417
{
406418
// fix sqlite dsn so that it will parse correctly
407419
$dsn = str_replace("////", "/", $dsn);
@@ -437,7 +449,7 @@ protected function _buildDsnPartsArray($dsn)
437449
* @return array Parsed contents of DSN
438450
* @todo package:dbal
439451
*/
440-
public function parseDsn($dsn)
452+
public function parseDsn(string $dsn)
441453
{
442454
$parts = $this->_buildDsnPartsArray($dsn);
443455

tests/MigrationMysqlTestCase.php

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
*/
3333
class Doctrine_MigrationMysql_TestCase extends Doctrine_UnitTestCase
3434
{
35+
public function prepareTables()
36+
{
37+
$this->tables[] = 'MigrationPhonenumber';
38+
$this->tables[] = 'MigrationUser';
39+
$this->tables[] = 'MigrationProfile';
40+
parent::prepareTables();
41+
}
42+
3543
public function setUp()
3644
{
3745
parent::setUp();
@@ -41,6 +49,8 @@ public function setUp()
4149
$this->connection->setOption('dsn', $dsn);
4250
$this->connection->dropDatabase();
4351
$this->connection->createDatabase();
52+
53+
$this->connection->export->exportClasses($this->tables);
4454
}
4555

4656
public function testAfterSuccessfullMigrationItWillSetMigratedVersionAsCurrentVersionInMysqlDB()

0 commit comments

Comments
 (0)