13
13
14
14
class Mysql extends \Magento \TestFramework \Db \AbstractDb
15
15
{
16
+ /**
17
+ * Default port
18
+ */
19
+ const DEFAULT_PORT = 3306 ;
20
+
16
21
/**
17
22
* Defaults extra file name
18
23
*/
@@ -32,12 +37,25 @@ class Mysql extends \Magento\TestFramework\Db\AbstractDb
32
37
*/
33
38
private $ _defaultsExtraFile ;
34
39
40
+ /**
41
+ * Port number for connection
42
+ *
43
+ * @var integer
44
+ */
45
+ private $ _port ;
46
+
35
47
/**
36
48
* {@inheritdoc}
37
49
*/
38
50
public function __construct ($ host , $ user , $ password , $ schema , $ varPath , \Magento \Framework \Shell $ shell )
39
51
{
40
52
parent ::__construct ($ host , $ user , $ password , $ schema , $ varPath , $ shell );
53
+ $ this ->_port = self ::DEFAULT_PORT ;
54
+ if (strpos ($ this ->_host , ': ' ) !== false ) {
55
+ list ($ host , $ port ) = explode (': ' , $ this ->_host );
56
+ $ this ->_host = $ host ;
57
+ $ this ->_port = (int ) $ port ;
58
+ }
41
59
$ this ->_dbDumpFile = $ this ->_varPath . '/setup_dump_ ' . $ this ->_schema . '.sql ' ;
42
60
$ this ->_defaultsExtraFile = rtrim ($ this ->_varPath , '\\/ ' ) . '/ ' . self ::DEFAULTS_EXTRA_FILE_NAME ;
43
61
}
@@ -49,10 +67,11 @@ public function cleanup()
49
67
{
50
68
$ this ->ensureDefaultsExtraFile ();
51
69
$ this ->_shell ->execute (
52
- 'mysql --defaults-file=%s --host=%s %s -e %s ' ,
70
+ 'mysql --defaults-file=%s --host=%s --port=%s %s -e %s ' ,
53
71
[
54
72
$ this ->_defaultsExtraFile ,
55
73
$ this ->_host ,
74
+ $ this ->_port ,
56
75
$ this ->_schema ,
57
76
"DROP DATABASE ` {$ this ->_schema }`; CREATE DATABASE ` {$ this ->_schema }` "
58
77
]
@@ -86,8 +105,8 @@ public function storeDbDump()
86
105
{
87
106
$ this ->ensureDefaultsExtraFile ();
88
107
$ this ->_shell ->execute (
89
- 'mysqldump --defaults-file=%s --host=%s %s > %s ' ,
90
- [$ this ->_defaultsExtraFile , $ this ->_host , $ this ->_schema , $ this ->getSetupDbDumpFilename ()]
108
+ 'mysqldump --defaults-file=%s --host=%s --port=%s %s > %s ' ,
109
+ [$ this ->_defaultsExtraFile , $ this ->_host , $ this ->_port , $ this -> _schema , $ this ->getSetupDbDumpFilename ()]
91
110
);
92
111
}
93
112
@@ -102,8 +121,8 @@ public function restoreFromDbDump()
102
121
throw new \LogicException ("DB dump file does not exist: " . $ this ->getSetupDbDumpFilename ());
103
122
}
104
123
$ this ->_shell ->execute (
105
- 'mysql --defaults-file=%s --host=%s %s < %s ' ,
106
- [$ this ->_defaultsExtraFile , $ this ->_host , $ this ->_schema , $ this ->getSetupDbDumpFilename ()]
124
+ 'mysql --defaults-file=%s --host=%s --port=%s %s < %s ' ,
125
+ [$ this ->_defaultsExtraFile , $ this ->_host , $ this ->_port , $ this -> _schema , $ this ->getSetupDbDumpFilename ()]
107
126
);
108
127
}
109
128
0 commit comments