예제 #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();
예제 #2
0
 /**
  * Test automatic de-index.
  *
  * @param Connection $connection
  *   The connection to perform tests on.
  *
  * @dataProvider connectionDataProvider
  */
 public function testAutoDeIndex(Connection $connection)
 {
     $indexer = new Indexer($connection);
     $connection->startTransaction();
     $operation1 = $indexer->index($connection->addMetadata('value', 'value1'), 'test1');
     $connection->startTransaction();
     $indexer->index($connection->addMetadata('value', 'value2'), 'test2');
     $connection->rollbackTransaction();
     $check = $indexer->lookup('test1');
     $this->assertSame([$operation1->idx($connection) => $operation1], $check, 'Operations not found during lookup.');
     $check = $indexer->lookup('test2');
     $this->assertSame([], $check, 'Operations found during lookup.');
     $connection->commitTransaction();
     $check = $indexer->lookup('test1');
     $this->assertSame([], $check, 'Operations found during lookup.');
 }
예제 #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');
 }