Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

droped typehint from signature

Doctrine\DBAL\Connection::transactional() throws exception for invalid argument
added unit test
  • Loading branch information...
commit 345ba96521d0ef4b9eb6961d121064019bb72751 1 parent 5ef5a37
Daniel Freudenberger authored
View
5 UPGRADE
@@ -1,5 +1,10 @@
# Upgrade to 2.3
+## Doctrine\DBAL\Connection#transactional() changed signature
+
+To match the signature provided by the new Doctrine\DBAL\Transactional interface, the \Closure typehint was dropped.
+In case you have classes overriding Doctrine\DBAL\Connection#transactional() you have to drop the typehint as well.
+
## Doctrine\DBAL\Connection#setCharsetSQL() removed
This method only worked on MySQL and it is considered unsafe on MySQL to use SET NAMES UTF-8 instead
View
8 lib/Doctrine/DBAL/Connection.php
@@ -864,10 +864,14 @@ public function lastInsertId($seqName = null)
* If an exception occurs during execution of the function or transaction commit,
* the transaction is rolled back and the exception re-thrown.
*
- * @param Closure $func The function to execute transactionally.
+ * @param Callable $func The function to execute transactionally.
*/
- public function transactional(Closure $func)
+ public function transactional($func)
{
+ if (!is_callable($func)) {
+ throw ConnectionException::invalidCallback('func');
+ }
+
$this->beginTransaction();
try {
$func($this);
View
10 lib/Doctrine/DBAL/DBALException.php
@@ -92,4 +92,14 @@ public static function typeNotFound($name)
{
return new self('Type to be overwritten '.$name.' does not exist.');
}
+
+ /**
+ * @param string $name
+ * @return DBALException
+ */
+ public static function invalidCallback($name)
+ {
+ $message = sprintf('method expects parameter %s to be callable.', $name);
+ return new self($message);
+ }
}
View
12 lib/Doctrine/DBAL/Transactional.php
@@ -1,7 +1,5 @@
<?php
/*
- * $Id$
- *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -24,12 +22,16 @@
/**
* Interface for transactional aware classes
*
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
- * @version $Revision$
* @author Daniel Freudenberger <d.freudenberger@rebuy.de>
*/
interface Transactional
{
- public function transactional(\Closure $func);
+ /**
+ * wraps the provided callable in a transaction.
+ *
+ * @param Callable $func
+ * @return void
+ */
+ public function transactional($func);
}
View
14 tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
@@ -4,6 +4,7 @@
use Doctrine\DBAL\ConnectionException;
use Doctrine\DBAL\Types\Type;
+use Doctrine\DBAL\DBALException;
require_once __DIR__ . '/../../TestInit.php';
@@ -209,6 +210,19 @@ public function testTransactional()
});
}
+ public function testTransactionalThrowsExceptionForInvalidCallback()
+ {
+ $message = null;
+ try {
+ $this->_conn->transactional('invalid callback');
+ } catch (DBALException $ex) {
+ $message = $ex->getMessage();
+ }
+
+ $expectedMessage = DBALException::invalidCallback('func')->getMessage();
+ $this->assertSame($expectedMessage, $message);
+ }
+
/**
* Tests that the quote function accepts DBAL and PDO types.
*/
Please sign in to comment.
Something went wrong with that request. Please try again.