/** * 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.'); }
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"; } foreach ($indexer->lookup('test2') as $operation) {