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
d6a1237f
Commit
d6a1237f
authored
Jun 04, 2019
by
Andrej Hudec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return result from commit()
parent
0152fbf4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
4 deletions
+75
-4
Connection.php
lib/Doctrine/DBAL/Connection.php
+5
-3
ConnectionTest.php
tests/Doctrine/Tests/DBAL/ConnectionTest.php
+30
-0
ConnectionTest.php
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
+1
-1
TransactionTest.php
tests/Doctrine/Tests/DBAL/Functional/TransactionTest.php
+39
-0
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
d6a1237f
...
...
@@ -1266,6 +1266,8 @@ class Connection implements DriverConnection
throw
ConnectionException
::
commitFailedRollbackOnly
();
}
$result
=
true
;
$connection
=
$this
->
getWrappedConnection
();
$logger
=
$this
->
_config
->
getSQLLogger
();
...
...
@@ -1275,7 +1277,7 @@ class Connection implements DriverConnection
$logger
->
startQuery
(
'"COMMIT"'
);
}
$connection
->
commit
();
$
result
=
$
connection
->
commit
();
if
(
$logger
)
{
$logger
->
stopQuery
();
...
...
@@ -1293,12 +1295,12 @@ class Connection implements DriverConnection
--
$this
->
transactionNestingLevel
;
if
(
$this
->
autoCommit
!==
false
||
$this
->
transactionNestingLevel
!==
0
)
{
return
true
;
return
$result
;
}
$this
->
beginTransaction
();
return
true
;
return
$result
;
}
/**
...
...
tests/Doctrine/Tests/DBAL/ConnectionTest.php
View file @
d6a1237f
...
...
@@ -297,6 +297,36 @@ class ConnectionTest extends DbalTestCase
self
::
assertTrue
(
$conn
->
isTransactionActive
());
}
/**
* @dataProvider resultProvider
*/
public
function
testCommitReturn
(
bool
$expectedResult
)
:
void
{
$driverConnection
=
$this
->
createMock
(
DriverConnection
::
class
);
$driverConnection
->
expects
(
$this
->
once
())
->
method
(
'commit'
)
->
willReturn
(
$expectedResult
);
$driverMock
=
$this
->
createMock
(
Driver
::
class
);
$driverMock
->
expects
(
$this
->
any
())
->
method
(
'connect'
)
->
will
(
$this
->
returnValue
(
$driverConnection
));
$conn
=
new
Connection
([],
$driverMock
);
$conn
->
connect
();
$conn
->
beginTransaction
();
self
::
assertSame
(
$expectedResult
,
$conn
->
commit
());
}
/**
* @return bool[][]
*/
public
function
resultProvider
()
:
array
{
return
[[
true
],
[
false
]];
}
/**
* @group DBAL-81
*/
...
...
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
View file @
d6a1237f
...
...
@@ -88,7 +88,7 @@ class ConnectionTest extends DbalFunctionalTestCase
self
::
assertEquals
(
2
,
$this
->
connection
->
getTransactionNestingLevel
());
$this
->
connection
->
beginTransaction
();
self
::
assertEquals
(
3
,
$this
->
connection
->
getTransactionNestingLevel
());
$this
->
connection
->
commit
(
);
self
::
assertTrue
(
$this
->
connection
->
commit
()
);
self
::
assertEquals
(
2
,
$this
->
connection
->
getTransactionNestingLevel
());
throw
new
Exception
();
$this
->
connection
->
commit
();
// never reached
...
...
tests/Doctrine/Tests/DBAL/Functional/TransactionTest.php
0 → 100644
View file @
d6a1237f
<?php
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\Tests\DbalFunctionalTestCase
;
use
function
sleep
;
class
TransactionTest
extends
DbalFunctionalTestCase
{
protected
function
setUp
()
:
void
{
parent
::
setUp
();
if
(
$this
->
connection
->
getDatabasePlatform
()
instanceof
MySqlPlatform
)
{
return
;
}
$this
->
markTestSkipped
(
'Restricted to MySQL.'
);
}
protected
function
tearDown
()
:
void
{
$this
->
resetSharedConn
();
parent
::
tearDown
();
}
public
function
testCommitFalse
()
:
void
{
$this
->
connection
->
query
(
'SET SESSION wait_timeout=1'
);
$this
->
assertTrue
(
$this
->
connection
->
beginTransaction
());
sleep
(
2
);
// during the sleep mysql will close the connection
$this
->
assertFalse
(
@
$this
->
connection
->
commit
());
// we will ignore `MySQL server has gone away` warnings
}
}
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