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
66e9cfde
Commit
66e9cfde
authored
Feb 16, 2015
by
Jan Rosier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unneeded connect calls
parent
a5e885af
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
9 deletions
+40
-9
Connection.php
lib/Doctrine/DBAL/Connection.php
+5
-9
ConnectionTest.php
tests/Doctrine/Tests/DBAL/ConnectionTest.php
+35
-0
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
66e9cfde
...
...
@@ -349,7 +349,9 @@ class Connection implements DriverConnection
*/
public
function
connect
()
{
if
(
$this
->
_isConnected
)
return
false
;
if
(
$this
->
_isConnected
)
{
return
false
;
}
$driverOptions
=
isset
(
$this
->
_params
[
'driverOptions'
])
?
$this
->
_params
[
'driverOptions'
]
:
array
();
...
...
@@ -580,8 +582,6 @@ class Connection implements DriverConnection
throw
InvalidArgumentException
::
fromEmptyCriteria
();
}
$this
->
connect
();
$criteria
=
array
();
foreach
(
array_keys
(
$identifier
)
as
$columnName
)
{
...
...
@@ -649,7 +649,6 @@ class Connection implements DriverConnection
*/
public
function
update
(
$tableExpression
,
array
$data
,
array
$identifier
,
array
$types
=
array
())
{
$this
->
connect
();
$set
=
array
();
foreach
(
$data
as
$columnName
=>
$value
)
{
...
...
@@ -682,8 +681,6 @@ class Connection implements DriverConnection
*/
public
function
insert
(
$tableExpression
,
array
$data
,
array
$types
=
array
())
{
$this
->
connect
();
if
(
empty
(
$data
))
{
return
$this
->
executeUpdate
(
'INSERT INTO '
.
$tableExpression
.
' ()'
.
' VALUES ()'
);
}
...
...
@@ -749,6 +746,7 @@ class Connection implements DriverConnection
$this
->
connect
();
list
(
$value
,
$bindingType
)
=
$this
->
getBindingInfo
(
$input
,
$type
);
return
$this
->
_conn
->
quote
(
$value
,
$bindingType
);
}
...
...
@@ -771,14 +769,12 @@ class Connection implements DriverConnection
*
* @param string $statement The SQL statement to prepare.
*
* @return \Doctrine\DBAL\
Driver\
Statement The prepared statement.
* @return \Doctrine\DBAL\Statement The prepared statement.
*
* @throws \Doctrine\DBAL\DBALException
*/
public
function
prepare
(
$statement
)
{
$this
->
connect
();
try
{
$stmt
=
new
Statement
(
$statement
,
$this
);
}
catch
(
\Exception
$ex
)
{
...
...
tests/Doctrine/Tests/DBAL/ConnectionTest.php
View file @
66e9cfde
...
...
@@ -480,4 +480,39 @@ SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\"");
$this
->
setExpectedException
(
'Doctrine\DBAL\Exception\InvalidArgumentException'
);
$conn
->
delete
(
'kittens'
,
array
());
}
public
function
dataCallConnectOnce
()
{
return
array
(
array
(
'delete'
,
array
(
'tbl'
,
array
(
'id'
=>
12345
))),
array
(
'insert'
,
array
(
'tbl'
,
array
(
'data'
=>
'foo'
))),
array
(
'update'
,
array
(
'tbl'
,
array
(
'data'
=>
'bar'
),
array
(
'id'
=>
12345
))),
array
(
'prepare'
,
array
(
'select * from dual'
)),
array
(
'executeUpdate'
,
array
(
'insert into tbl (id) values (?)'
),
array
(
123
)),
);
}
/**
* @dataProvider dataCallConnectOnce
*/
public
function
testCallConnectOnce
(
$method
,
$params
)
{
$driverMock
=
$this
->
getMock
(
'Doctrine\DBAL\Driver'
);
$pdoMock
=
$this
->
getMock
(
'Doctrine\DBAL\Driver\Connection'
);
$platformMock
=
new
Mocks\MockPlatform
();
$stmtMock
=
$this
->
getMock
(
'Doctrine\DBAL\Driver\Statement'
);
$pdoMock
->
expects
(
$this
->
any
())
->
method
(
'prepare'
)
->
will
(
$this
->
returnValue
(
$stmtMock
));
$conn
=
$this
->
getMockBuilder
(
'Doctrine\DBAL\Connection'
)
->
setConstructorArgs
(
array
(
array
(
'pdo'
=>
$pdoMock
,
'platform'
=>
$platformMock
),
$driverMock
))
->
setMethods
(
array
(
'connect'
))
->
getMock
();
$conn
->
expects
(
$this
->
once
())
->
method
(
'connect'
);
call_user_func_array
(
array
(
$conn
,
$method
),
$params
);
}
}
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