-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11556 from nsossonko/2.1.x
Fixes #11554 - Transaction Manager transaction accounting
- Loading branch information
Showing
4 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Phalcon\Test\Proxy\Mvc\Model\Transaction; | ||
|
||
use Phalcon\Mvc\Model\Transaction\Manager as PhManager; | ||
|
||
/** | ||
* \Phalcon\Test\Proxy\Mvc\Manager | ||
* Url proxy class for \Phalcon\Mvc\Manager | ||
* | ||
* @copyright (c) 2011-2016 Phalcon Team | ||
* @link http://www.phalconphp.com | ||
* @author Nochum Sossonko <nsossonko@hotmail.com> | ||
* @package Phalcon\Test\Proxy\Mvc\Model\Transaction | ||
* | ||
* The contents of this file are subject to the New BSD License that is | ||
* bundled with this package in the file docs/LICENSE.txt | ||
* | ||
* If you did not receive a copy of the license and are unable to obtain it | ||
* through the world-wide-web, please send an email to license@phalconphp.com | ||
* so that we can send you a copy immediately. | ||
*/ | ||
class Manager extends PhManager | ||
{ | ||
public function getTransactions() | ||
{ | ||
return $this->_transactions; | ||
} | ||
|
||
public function count() | ||
{ | ||
return $this->_number; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace Phalcon\Test\Unit\Mvc\Model\Transaction; | ||
|
||
use Phalcon\Test\Module\UnitTest; | ||
use Phalcon\Test\Proxy\Mvc\Model\Transaction\Manager as TransactionManager; | ||
use Phalcon\Test\Models\Select; | ||
|
||
/** | ||
* \Phalcon\Test\Unit\Mvc\CollectionTest | ||
* Tests the Phalcon\Mvc\Collection component | ||
* | ||
* @copyright (c) 2011-2016 Phalcon Team | ||
* @link http://www.phalconphp.com | ||
* @author Nochum Sossonko <nsossonko@hotmail.com> | ||
* @package Phalcon\Test\Unit\Mvc\Model\Transaction | ||
* | ||
* The contents of this file are subject to the New BSD License that is | ||
* bundled with this package in the file docs/LICENSE.txt | ||
* | ||
* If you did not receive a copy of the license and are unable to obtain it | ||
* through the world-wide-web, please send an email to license@phalconphp.com | ||
* so that we can send you a copy immediately. | ||
*/ | ||
class ManagerTest extends UnitTest | ||
{ | ||
/** | ||
* Tests transaction is removed when rolled back. | ||
* | ||
* @author Nochum Sossonko <nsossonko@hotmail.com> | ||
* @since 2016-04-09 | ||
*/ | ||
public function testTransactionRemovedOnRollback() | ||
{ | ||
$this->specify( | ||
"Test does not remove transaction when rolled back", | ||
function () { | ||
$tm = new TransactionManager(); | ||
$transaction = $tm->get(true); | ||
$select = new Select(); | ||
$select->setTransaction($transaction); | ||
$select->create( | ||
array( | ||
'name' => 'Crack of Dawn' | ||
) | ||
); | ||
expect($tm->count())->equals(1); | ||
expect(count($tm->getTransactions()))->equals(1); | ||
try { | ||
$transaction->rollback(); | ||
} | ||
catch(\Phalcon\Mvc\Model\Transaction\Failed $e) {} | ||
expect($tm->count())->equals(0); | ||
expect(count($tm->getTransactions()))->equals(0); | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* Tests transaction is removed when committed. | ||
* | ||
* @author Nochum Sossonko <nsossonko@hotmail.com> | ||
* @since 2016-04-09 | ||
*/ | ||
public function testTransactionRemovedOnCommit() | ||
{ | ||
$this->specify( | ||
"Test does not remove transaction when committed", | ||
function () { | ||
$tm = new TransactionManager(); | ||
$transaction = $tm->get(true); | ||
$select = new Select(); | ||
$select->setTransaction($transaction); | ||
$select->create( | ||
array( | ||
'name' => 'Crack of Dawn' | ||
) | ||
); | ||
expect($tm->count())->equals(1); | ||
expect(count($tm->getTransactions()))->equals(1); | ||
$transaction->commit(); | ||
expect($tm->count())->equals(0); | ||
expect(count($tm->getTransactions()))->equals(0); | ||
} | ||
); | ||
} | ||
} |