Exemplo n.º 1
0
<?php

namespace Gielfeldt\TransactionalPHP\Example;

require 'vendor/autoload.php';
use Gielfeldt\TransactionalPHP\Connection;
$connection = new Connection();
// Start outer transaction.
$connection->startTransaction();
$connection->onCommit(function () {
    print "THIS WILL BE PRINTED, BECAUSE THIS WILL BE COMMITTED\n";
});
// Start inner transaction.
$connection->startTransaction();
$connection->onCommit(function () {
    print "THIS WILL NOT BE PRINTED, BECAUSE THIS WILL BE ROLLED BACK\n";
});
// Rollback inner transaction.
$connection->rollbackTransaction();
// Commit inner transaction.
$connection->commitTransaction();
Exemplo n.º 2
0
 /**
  * Test get operations
  *
  * @param Connection $connection
  *   The connection to perform tests on.
  *
  * @dataProvider connectionDataProvider
  */
 public function testGetOperations(Connection $connection)
 {
     $indexer = new Indexer($connection);
     $connection->startTransaction();
     $operation1 = $connection->addMetadata('value', 'value1');
     $operation2 = $connection->addMetadata('value', 'value2');
     $operation3 = $connection->addMetadata('value', 'value3');
     $indexer->index($operation1, 'test1');
     $indexer->index($operation2, 'test1');
     $indexer->index($operation3, 'test3');
     $expected = [$operation1->idx($connection) => $operation1, $operation2->idx($connection) => $operation2, $operation3->idx($connection) => $operation3];
     $check = $indexer->getOperations();
     $this->assertSame($expected, $check, 'Correct operations not found in indexer.');
     $expected = ['test1' => [$operation1->idx($connection) => $operation1, $operation2->idx($connection) => $operation2], 'test3' => [$operation3->idx($connection) => $operation3]];
     $check = $indexer->getIndex();
     $this->assertSame($expected, $check, 'Correct operations not found in indexer.');
 }
Exemplo n.º 3
0
 /**
  * Test transaction depth.
  *
  * @param Connection $connection
  *   The connection to perform tests on.
  *
  * @dataProvider connectionDataProvider
  */
 public function testDepth(Connection $connection)
 {
     $this->assertEquals(0, $connection->getDepth(), 'Depth was not correct');
     $connection->startTransaction();
     $this->assertEquals(1, $connection->getDepth(), 'Depth was not correct');
     $connection->startTransaction();
     $this->assertEquals(2, $connection->getDepth(), 'Depth was not correct');
     $connection->rollbackTransaction();
     $this->assertEquals(1, $connection->getDepth(), 'Depth was not correct');
     $connection->commitTransaction();
     $this->assertEquals(0, $connection->getDepth(), 'Depth was not correct');
 }