Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
aa56a440
Commit
aa56a440
authored
Jun 26, 2014
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #597 from JeroenDeDauw/cleantestsetup
Some much needed cleanup in the TestUtil class
parents
cf35f193
b71e44a9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
54 deletions
+71
-54
TestUtil.php
tests/Doctrine/Tests/TestUtil.php
+71
-54
No files found.
tests/Doctrine/Tests/TestUtil.php
View file @
aa56a440
...
...
@@ -2,6 +2,8 @@
namespace
Doctrine\Tests
;
use
Doctrine\DBAL\DriverManager
;
/**
* TestUtil is a class with static utility methods used during tests.
*
...
...
@@ -34,51 +36,14 @@ class TestUtil
*/
public
static
function
getConnection
()
{
if
(
isset
(
$GLOBALS
[
'db_type'
],
$GLOBALS
[
'db_username'
],
$GLOBALS
[
'db_password'
],
$GLOBALS
[
'db_host'
],
$GLOBALS
[
'db_name'
],
$GLOBALS
[
'db_port'
])
&&
isset
(
$GLOBALS
[
'tmpdb_type'
],
$GLOBALS
[
'tmpdb_username'
],
$GLOBALS
[
'tmpdb_password'
],
$GLOBALS
[
'tmpdb_host'
],
$GLOBALS
[
'tmpdb_port'
]))
{
$realDbParams
=
array
(
'driver'
=>
$GLOBALS
[
'db_type'
],
'user'
=>
$GLOBALS
[
'db_username'
],
'password'
=>
$GLOBALS
[
'db_password'
],
'host'
=>
$GLOBALS
[
'db_host'
],
'dbname'
=>
$GLOBALS
[
'db_name'
],
'port'
=>
$GLOBALS
[
'db_port'
]
);
$tmpDbParams
=
array
(
'driver'
=>
$GLOBALS
[
'tmpdb_type'
],
'user'
=>
$GLOBALS
[
'tmpdb_username'
],
'password'
=>
$GLOBALS
[
'tmpdb_password'
],
'host'
=>
$GLOBALS
[
'tmpdb_host'
],
'dbname'
=>
null
,
'port'
=>
$GLOBALS
[
'tmpdb_port'
]
);
if
(
self
::
hasRequiredConnectionParams
())
{
$realDbParams
=
self
::
getConnectionParams
();
$tmpDbParams
=
self
::
getTmpConnectionParams
();
if
(
isset
(
$GLOBALS
[
'db_server'
]))
{
$realDbParams
[
'server'
]
=
$GLOBALS
[
'db_server'
];
}
if
(
isset
(
$GLOBALS
[
'db_unix_socket'
]))
{
$realDbParams
[
'unix_socket'
]
=
$GLOBALS
[
'db_unix_socket'
];
}
if
(
isset
(
$GLOBALS
[
'tmpdb_name'
]))
{
$tmpDbParams
[
'dbname'
]
=
$GLOBALS
[
'tmpdb_name'
];
}
if
(
isset
(
$GLOBALS
[
'tmpdb_server'
]))
{
$tmpDbParams
[
'server'
]
=
$GLOBALS
[
'tmpdb_server'
];
}
if
(
isset
(
$GLOBALS
[
'tmpdb_unix_socket'
]))
{
$tmpDbParams
[
'unix_socket'
]
=
$GLOBALS
[
'tmpdb_unix_socket'
];
}
$realConn
=
\Doctrine\DBAL\DriverManager
::
getConnection
(
$realDbParams
);
$realConn
=
DriverManager
::
getConnection
(
$realDbParams
);
// Connect to tmpdb in order to drop and create the real test db.
$tmpConn
=
\Doctrine\DBAL\
DriverManager
::
getConnection
(
$tmpDbParams
);
$tmpConn
=
DriverManager
::
getConnection
(
$tmpDbParams
);
$platform
=
$tmpConn
->
getDatabasePlatform
();
...
...
@@ -92,7 +57,6 @@ class TestUtil
}
else
{
$sm
=
$realConn
->
getSchemaManager
();
/* @var $schema Schema */
$schema
=
$sm
->
createSchema
();
$stmts
=
$schema
->
toDropSql
(
$realConn
->
getDatabasePlatform
());
...
...
@@ -101,7 +65,7 @@ class TestUtil
}
}
$conn
=
\Doctrine\DBAL\
DriverManager
::
getConnection
(
$realDbParams
,
null
,
null
);
$conn
=
DriverManager
::
getConnection
(
$realDbParams
,
null
,
null
);
}
else
{
$params
=
array
(
'driver'
=>
'pdo_sqlite'
,
...
...
@@ -111,7 +75,7 @@ class TestUtil
$params
[
'path'
]
=
$GLOBALS
[
'db_path'
];
unlink
(
$GLOBALS
[
'db_path'
]);
}
$conn
=
\Doctrine\DBAL\
DriverManager
::
getConnection
(
$params
);
$conn
=
DriverManager
::
getConnection
(
$params
);
}
if
(
isset
(
$GLOBALS
[
'db_event_subscribers'
]))
{
...
...
@@ -125,25 +89,78 @@ class TestUtil
return
$conn
;
}
/**
* @return \Doctrine\DBAL\Connection
*/
public
static
function
getTempConnection
()
private
static
function
hasRequiredConnectionParams
()
{
return
isset
(
$GLOBALS
[
'db_type'
],
$GLOBALS
[
'db_username'
],
$GLOBALS
[
'db_password'
],
$GLOBALS
[
'db_host'
],
$GLOBALS
[
'db_name'
],
$GLOBALS
[
'db_port'
]
)
&&
isset
(
$GLOBALS
[
'tmpdb_type'
],
$GLOBALS
[
'tmpdb_username'
],
$GLOBALS
[
'tmpdb_password'
],
$GLOBALS
[
'tmpdb_host'
],
$GLOBALS
[
'tmpdb_port'
]
);
}
private
static
function
getTmpConnectionParams
()
{
$
tmpDb
Params
=
array
(
$
connection
Params
=
array
(
'driver'
=>
$GLOBALS
[
'tmpdb_type'
],
'user'
=>
$GLOBALS
[
'tmpdb_username'
],
'password'
=>
$GLOBALS
[
'tmpdb_password'
],
'host'
=>
$GLOBALS
[
'tmpdb_host'
],
'dbname'
=>
$GLOBALS
[
'tmpdb_name'
]
,
'dbname'
=>
null
,
'port'
=>
$GLOBALS
[
'tmpdb_port'
]
);
if
(
isset
(
$GLOBALS
[
'tmpdb_name'
]))
{
$connectionParams
[
'dbname'
]
=
$GLOBALS
[
'tmpdb_name'
];
}
if
(
isset
(
$GLOBALS
[
'tmpdb_server'
]))
{
$
tmpDb
Params
[
'server'
]
=
$GLOBALS
[
'tmpdb_server'
];
$
connection
Params
[
'server'
]
=
$GLOBALS
[
'tmpdb_server'
];
}
// Connect to tmpdb in order to drop and create the real test db.
return
\Doctrine\DBAL\DriverManager
::
getConnection
(
$tmpDbParams
);
if
(
isset
(
$GLOBALS
[
'tmpdb_unix_socket'
]))
{
$connectionParams
[
'unix_socket'
]
=
$GLOBALS
[
'tmpdb_unix_socket'
];
}
return
$connectionParams
;
}
private
static
function
getConnectionParams
()
{
$connectionParams
=
array
(
'driver'
=>
$GLOBALS
[
'db_type'
],
'user'
=>
$GLOBALS
[
'db_username'
],
'password'
=>
$GLOBALS
[
'db_password'
],
'host'
=>
$GLOBALS
[
'db_host'
],
'dbname'
=>
$GLOBALS
[
'db_name'
],
'port'
=>
$GLOBALS
[
'db_port'
]
);
if
(
isset
(
$GLOBALS
[
'db_server'
]))
{
$connectionParams
[
'server'
]
=
$GLOBALS
[
'db_server'
];
}
if
(
isset
(
$GLOBALS
[
'db_unix_socket'
]))
{
$connectionParams
[
'unix_socket'
]
=
$GLOBALS
[
'db_unix_socket'
];
}
return
$connectionParams
;
}
/**
* @return \Doctrine\DBAL\Connection
*/
public
static
function
getTempConnection
()
{
return
DriverManager
::
getConnection
(
self
::
getTmpConnectionParams
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment