Implemented support for closure return on EntityManager::transactional. Fixes DDC-1125
This commit is contained in:
parent
4d561651a1
commit
26bd3e3811
@ -203,13 +203,18 @@ class EntityManager implements ObjectManager
|
||||
public function transactional(Closure $func)
|
||||
{
|
||||
$this->conn->beginTransaction();
|
||||
|
||||
try {
|
||||
$func($this);
|
||||
$return = $func($this);
|
||||
|
||||
$this->flush();
|
||||
$this->conn->commit();
|
||||
|
||||
return $return ?: true;
|
||||
} catch (Exception $e) {
|
||||
$this->close();
|
||||
$this->conn->rollback();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
@ -143,4 +143,16 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->_em->close();
|
||||
$this->_em->$methodName(new \stdClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1125
|
||||
*/
|
||||
public function testTransactionalAcceptsReturn()
|
||||
{
|
||||
$return = $this->_em->transactional(function ($em) {
|
||||
return 'foo';
|
||||
});
|
||||
|
||||
$this->assertEquals('foo', $return);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user