/**
  * Test add value.
  *
  * @param Connection $connection
  *   The connection to perform tests on.
  *
  * @dataProvider connectionDataProvider
  */
 public function testAddMetadata(Connection $connection)
 {
     $operation = $connection->addMetadata('value', 'testresult');
     $check = $operation->getMetadata('value');
     $this->assertSame('testresult', $check, 'Operation was not properly added.');
     $check = $operation->getMetadata('nonvalue');
     $this->assertNotSame('testresult', $check, 'Operation was not properly added.');
 }
Esempio 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.');
 }
<?php

namespace Gielfeldt\TransactionalPHP\Example;

require 'vendor/autoload.php';
use Gielfeldt\TransactionalPHP\Connection;
use Gielfeldt\TransactionalPHP\Indexer;
$connection = new Connection();
$indexer = new Indexer($connection);
// Start outer transaction.
$connection->startTransaction();
print "Started outer transaction\n";
$indexer->index($connection->addMetadata('value', 'value1'), 'test1');
$indexer->index($connection->addMetadata('value', 'value2'), 'test1');
$indexer->index($connection->addMetadata('value', 'value1'), 'test2');
$indexer->index($connection->addMetadata('value', 'value2'), 'test2');
print "Added data to indexer\n";
foreach ($indexer->lookup('test1') as $operation) {
    print "Looked up test1 - found: " . $operation->getMetadata('value') . "\n";
}
foreach ($indexer->lookup('test2') as $operation) {
    print "Looked up test2 - found: " . $operation->getMetadata('value') . "\n";
}
// Start inner transaction.
$connection->startTransaction();
print "Started inner transaction\n";
$indexer->index($connection->addMetadata('value', 'value3'), 'test1');
$indexer->index($connection->addMetadata('value', 'value3'), 'test2');
print "Added data to indexer\n";
foreach ($indexer->lookup('test1') as $operation) {
    print "Looked up test1 - found: " . $operation->getMetadata('value') . "\n";