Skip to content

Commit

Permalink
[#13949] - Correcting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed May 9, 2019
1 parent ca58d9d commit 149ceee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 38 deletions.
36 changes: 0 additions & 36 deletions tests/integration/Mvc/Model/Transaction/Refactor-ManagerCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function checkTransactionMysql(IntegrationTester $I)
$this->setDiMysql();

$this->testGetNewExistingTransactionOnce($I);
$this->testRollbackNewInserts($I);
$this->testCommitNewInserts($I);
$this->testTransactionRemovedOnCommit($I);
$this->testTransactionRemovedOnRollback($I);
Expand All @@ -61,39 +60,6 @@ private function testGetNewExistingTransactionOnce(IntegrationTester $I)
// $I->assertEquals($db->getConnectionId(), $transaction->getConnection()->getConnectionId());
}

private function testRollbackNewInserts(IntegrationTester $I)
{
$tm = $this->container->getShared('transactionManager');

$numPersonas = Personas::count();
$transaction = $tm->get();

for ($i = 0; $i < 10; $i++) {
$persona = new Personas();
$persona->setTransaction($transaction);
$persona->cedula = 'T-Cx' . $i;
$persona->tipo_documento_id = 1;
$persona->nombres = 'LOST LOST';
$persona->telefono = '2';
$persona->cupo = 0;
$persona->estado = 'A';

$I->assertTrue($persona->save());
}

try {
$transaction->rollback();
$I->assertTrue(
false,
"The transaction's rollback didn't throw an expected exception. Emergency stop"
);
} catch (Failed $e) {
$I->assertEquals($e->getMessage(), "Transaction aborted");
}

$I->assertEquals($numPersonas, Personas::count());
}

private function testCommitNewInserts(IntegrationTester $I)
{
$tm = $this->container->getShared('transactionManager');
Expand Down Expand Up @@ -176,7 +142,6 @@ public function checkTransactionPostgresql(IntegrationTester $I)
$this->setDiPostgresql();

$this->testGetNewExistingTransactionOnce($I);
$this->testRollbackNewInserts($I);
$this->testCommitNewInserts($I);
$this->testTransactionRemovedOnCommit($I);
$this->testTransactionRemovedOnRollback($I);
Expand All @@ -194,7 +159,6 @@ public function checkTransactionSqlite(IntegrationTester $I)
$this->setDiSqlite();

$this->testGetNewExistingTransactionOnce($I);
$this->testRollbackNewInserts($I);
$this->testCommitNewInserts($I);
$this->testTransactionRemovedOnCommit($I);
$this->testTransactionRemovedOnRollback($I);
Expand Down
18 changes: 16 additions & 2 deletions tests/integration/Mvc/Model/Transaction/RollbackCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class RollbackCest
public function _before(IntegrationTester $I)
{
$this->setNewFactoryDefault();
$this->setDiMysql();
$this->records = [];
}

Expand All @@ -47,15 +46,19 @@ public function _after(IntegrationTester $I)
/**
* Tests Phalcon\Mvc\Model\Transaction :: rollback()
*
* @dataProvider getFunctions
*
* @param IntegrationTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function mvcModelTransactionRollback(IntegrationTester $I)
public function mvcModelTransactionRollback(IntegrationTester $I, Example $function)
{
$I->wantToTest('Mvc\Model\Transaction - rollback()');

$this->$function();

$tm = $this->container->getShared('transactionManager');

$count = Personas::count();
Expand Down Expand Up @@ -130,4 +133,15 @@ public function mvcModelTransactionRollbackException(IntegrationTester $I)

$I->assertEquals($count, Personas::count());
}

/**
* @return array
*/
private function getFunctions(): array
{
return [
['setDiMysql']
['setDiPostgresql']
];
}
}

0 comments on commit 149ceee

Please sign in to comment.