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
dcdf744e
Commit
dcdf744e
authored
Jan 18, 2015
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initialize database schema only once per phpunit run
parent
dfb44bda
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
14 deletions
+21
-14
TestUtil.php
tests/Doctrine/Tests/TestUtil.php
+21
-14
No files found.
tests/Doctrine/Tests/TestUtil.php
View file @
dcdf744e
...
@@ -12,6 +12,11 @@ use Doctrine\DBAL\DriverManager;
...
@@ -12,6 +12,11 @@ use Doctrine\DBAL\DriverManager;
*/
*/
class
TestUtil
class
TestUtil
{
{
/**
* @var boolean Whether the database schema is initialized.
*/
private
static
$initialized
=
false
;
/**
/**
* Gets a <b>real</b> database connection using the following parameters
* Gets a <b>real</b> database connection using the following parameters
* of the $GLOBALS array:
* of the $GLOBALS array:
...
@@ -29,9 +34,7 @@ class TestUtil
...
@@ -29,9 +34,7 @@ class TestUtil
* on an XML configuration file. If no such parameters exist, an SQLite
* on an XML configuration file. If no such parameters exist, an SQLite
* in-memory database is used.
* in-memory database is used.
*
*
* IMPORTANT:
* IMPORTANT: Each invocation of this method returns a NEW database connection.
* 1) Each invocation of this method returns a NEW database connection.
* 2) The database is dropped and recreated to ensure it's clean.
*
*
* @return Connection The database connection instance.
* @return Connection The database connection instance.
*/
*/
...
@@ -82,22 +85,26 @@ class TestUtil
...
@@ -82,22 +85,26 @@ class TestUtil
$platform
=
$tmpConn
->
getDatabasePlatform
();
$platform
=
$tmpConn
->
getDatabasePlatform
();
if
(
$platform
->
supportsCreateDropDatabase
())
{
if
(
!
self
::
$initialized
)
{
$dbname
=
$realConn
->
getDatabase
();
if
(
$platform
->
supportsCreateDropDatabase
())
{
$realConn
->
close
();
$dbname
=
$realConn
->
getDatabase
();
$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
;
return
$realDbParams
;
...
...
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