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
2080599b
Unverified
Commit
2080599b
authored
Mar 05, 2019
by
Marco Pivetta
Committed by
GitHub
Mar 05, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3473 from morozov/issues/3471
Avoid database connection from PHPUnit data providers
parents
6a9edc9f
8a1b0a2d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
31 deletions
+30
-31
AbstractDriverTest.php
...trine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php
+2
-5
DriverTest.php
...rine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php
+7
-4
DriverTest.php
...ine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php
+1
-1
DriverTest.php
...ctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php
+1
-1
TestUtil.php
tests/Doctrine/Tests/TestUtil.php
+19
-20
No files found.
tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php
View file @
2080599b
...
@@ -55,7 +55,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase
...
@@ -55,7 +55,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase
);
);
self
::
assertSame
(
self
::
assertSame
(
$this
->
getDatabaseNameForConnectionWithoutDatabaseNameParameter
(),
static
::
getDatabaseNameForConnectionWithoutDatabaseNameParameter
(),
$this
->
driver
->
getDatabase
(
$connection
)
$this
->
driver
->
getDatabase
(
$connection
)
);
);
}
}
...
@@ -65,10 +65,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase
...
@@ -65,10 +65,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase
*/
*/
abstract
protected
function
createDriver
();
abstract
protected
function
createDriver
();
/**
protected
static
function
getDatabaseNameForConnectionWithoutDatabaseNameParameter
()
:
?
string
* @return string|null
*/
protected
function
getDatabaseNameForConnectionWithoutDatabaseNameParameter
()
{
{
return
null
;
return
null
;
}
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php
View file @
2080599b
...
@@ -50,9 +50,12 @@ class DriverTest extends AbstractDriverTest
...
@@ -50,9 +50,12 @@ class DriverTest extends AbstractDriverTest
);
);
}
}
public
function
getDatabaseParameter
()
/**
* @return mixed[][]
*/
public
static
function
getDatabaseParameter
()
:
iterable
{
{
$params
=
TestUtil
::
getConnection
()
->
get
Params
();
$params
=
TestUtil
::
getConnectionParams
();
$realDatabaseName
=
$params
[
'dbname'
]
??
''
;
$realDatabaseName
=
$params
[
'dbname'
]
??
''
;
$dummyDatabaseName
=
$realDatabaseName
.
'a'
;
$dummyDatabaseName
=
$realDatabaseName
.
'a'
;
...
@@ -61,7 +64,7 @@ class DriverTest extends AbstractDriverTest
...
@@ -61,7 +64,7 @@ class DriverTest extends AbstractDriverTest
[
$realDatabaseName
,
null
,
$realDatabaseName
],
[
$realDatabaseName
,
null
,
$realDatabaseName
],
[
$realDatabaseName
,
$dummyDatabaseName
,
$realDatabaseName
],
[
$realDatabaseName
,
$dummyDatabaseName
,
$realDatabaseName
],
[
null
,
$realDatabaseName
,
$realDatabaseName
],
[
null
,
$realDatabaseName
,
$realDatabaseName
],
[
null
,
null
,
$this
->
getDatabaseNameForConnectionWithoutDatabaseNameParameter
()],
[
null
,
null
,
static
::
getDatabaseNameForConnectionWithoutDatabaseNameParameter
()],
];
];
}
}
...
@@ -108,7 +111,7 @@ class DriverTest extends AbstractDriverTest
...
@@ -108,7 +111,7 @@ class DriverTest extends AbstractDriverTest
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
protected
function
getDatabaseNameForConnectionWithoutDatabaseNameParameter
()
protected
static
function
getDatabaseNameForConnectionWithoutDatabaseNameParameter
()
:
?
string
{
{
return
'postgres'
;
return
'postgres'
;
}
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php
View file @
2080599b
...
@@ -36,7 +36,7 @@ class DriverTest extends AbstractDriverTest
...
@@ -36,7 +36,7 @@ class DriverTest extends AbstractDriverTest
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
protected
function
getDatabaseNameForConnectionWithoutDatabaseNameParameter
()
protected
static
function
getDatabaseNameForConnectionWithoutDatabaseNameParameter
()
:
?
string
{
{
return
'master'
;
return
'master'
;
}
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php
View file @
2080599b
...
@@ -34,7 +34,7 @@ class DriverTest extends AbstractDriverTest
...
@@ -34,7 +34,7 @@ class DriverTest extends AbstractDriverTest
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
protected
function
getDatabaseNameForConnectionWithoutDatabaseNameParameter
()
protected
static
function
getDatabaseNameForConnectionWithoutDatabaseNameParameter
()
:
?
string
{
{
return
'master'
;
return
'master'
;
}
}
...
...
tests/Doctrine/Tests/TestUtil.php
View file @
2080599b
...
@@ -40,6 +40,11 @@ class TestUtil
...
@@ -40,6 +40,11 @@ class TestUtil
*/
*/
public
static
function
getConnection
()
public
static
function
getConnection
()
{
{
if
(
self
::
hasRequiredConnectionParams
()
&&
!
self
::
$initialized
)
{
self
::
initializeDatabase
();
self
::
$initialized
=
true
;
}
$conn
=
DriverManager
::
getConnection
(
self
::
getConnectionParams
());
$conn
=
DriverManager
::
getConnection
(
self
::
getConnectionParams
());
self
::
addDbEventSubscribers
(
$conn
);
self
::
addDbEventSubscribers
(
$conn
);
...
@@ -47,10 +52,10 @@ class TestUtil
...
@@ -47,10 +52,10 @@ class TestUtil
return
$conn
;
return
$conn
;
}
}
p
rivate
static
function
getConnectionParams
()
p
ublic
static
function
getConnectionParams
()
{
{
if
(
self
::
hasRequiredConnectionParams
())
{
if
(
self
::
hasRequiredConnectionParams
())
{
return
self
::
get
SpecifiedConnectionParams
();
return
self
::
get
ParamsForMainConnection
();
}
}
return
self
::
getFallbackConnectionParams
();
return
self
::
getFallbackConnectionParams
();
...
@@ -75,7 +80,7 @@ class TestUtil
...
@@ -75,7 +80,7 @@ class TestUtil
);
);
}
}
private
static
function
getSpecifiedConnectionParams
()
private
static
function
initializeDatabase
()
:
void
{
{
$realDbParams
=
self
::
getParamsForMainConnection
();
$realDbParams
=
self
::
getParamsForMainConnection
();
$tmpDbParams
=
self
::
getParamsForTemporaryConnection
();
$tmpDbParams
=
self
::
getParamsForTemporaryConnection
();
...
@@ -87,29 +92,23 @@ class TestUtil
...
@@ -87,29 +92,23 @@ class TestUtil
$platform
=
$tmpConn
->
getDatabasePlatform
();
$platform
=
$tmpConn
->
getDatabasePlatform
();
if
(
!
self
::
$initialized
)
{
if
(
$platform
->
supportsCreateDropDatabase
())
{
if
(
$platform
->
supportsCreateDropDatabase
())
{
$dbname
=
$realConn
->
getDatabase
();
$dbname
=
$realConn
->
getDatabase
();
$realConn
->
close
();
$realConn
->
close
();
$tmpConn
->
getSchemaManager
()
->
dropAndCreateDatabase
(
$dbname
);
$tmpConn
->
getSchemaManager
()
->
dropAndCreateDatabase
(
$dbname
);
$tmpConn
->
close
();
$tmpConn
->
close
();
}
else
{
}
else
{
$sm
=
$realConn
->
getSchemaManager
();
$sm
=
$realConn
->
getSchemaManager
();
$schema
=
$sm
->
createSchema
();
$schema
=
$sm
->
createSchema
();
$stmts
=
$schema
->
toDropSql
(
$realConn
->
getDatabasePlatform
());
$stmts
=
$schema
->
toDropSql
(
$realConn
->
getDatabasePlatform
());
foreach
(
$stmts
as
$stmt
)
{
foreach
(
$stmts
as
$stmt
)
{
$realConn
->
exec
(
$stmt
);
$realConn
->
exec
(
$stmt
);
}
}
}
self
::
$initialized
=
true
;
}
}
return
$realDbParams
;
}
}
private
static
function
getFallbackConnectionParams
()
private
static
function
getFallbackConnectionParams
()
...
...
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