Tap::is(lastElement($q->all()), array(), 'empty properties before callback validator is attached');
$stockpile = new QuantityInspector($stockpile, 'Gaia\\Stockpile\\sanitizeQuantity');
$q = $stockpile->get($item_id);
Tap::is(lastElement($q->all()), array('xp' => 1), 'callback function populated xp into read quantity object');
$stockpile = new QuantityInspector(stockpile($app, $user_id), 'Gaia\\Stockpile\\sanitizeQuantity');
$item_id = uniqueNumber(1, 10000000);
$res = $stockpile->add($item_id, 1);
Tap::is(lastElement($res->all()), array('xp' => 1), 'callback function populated xp into the quantity on add');
$user_id = uniqueUserID();
$item_id = uniqueNumber(1, 10000000);
$stockpile = stockpile($app, $user_id);
$total = $stockpile->add($item_id, 3);
Tap::is($stockpile->set($item_id, $total), $total, 'When calling set with the same set of serials, no items created or subtracted');
$new = $total->grab(array(lastElement($total->serials())));
Tap::is($stockpile->set($item_id, $new), $new, 'When removing  a serial, everything matches up');
Tap::is($stockpile->set($item_id, $total), $total, 'When adding back a serial, everything matches up');
$user_id1 = uniqueUserID();
$user_id2 = uniqueUserID();
$item_id = uniqueNumber(1, 10000000);
Transaction::reset();
Transaction::claimStart();
$stockpile1 = stockpile($app, $user_id1);
$stockpile2 = stockpile($app, $user_id2);
$start = microtime(TRUE);
$total1 = $stockpile1->add($item_id);
$total2 = $stockpile2->add($item_id);
Transaction::commit();
$elapsed = microtime(TRUE) - $start;
Tap::cmp_ok($elapsed, '<', 1, 'two users adding the same item doesnt create deadlock. took ' . number_format($elapsed, 2) . ' seconds');
Tap::isnt($total1, $total2, 'the items created for these two users are different');
$newconn = function () use($instance) {
    return new DB($instance());
};
$table = 'test_' . time() . '_' . mt_rand(10000, 99999);
$dbmain = $newconn();
$dbmain->execute("create table {$table} (id int unsigned not null primary key) engine=innodb");
$conn1 = $newconn();
$conn2 = $newconn();
Tap::ok($conn1 !== $conn2, 'created two db objects');
$rs = $conn1->execute('SELECT CONNECTION_ID() as id');
$row = $rs->fetch();
$id1 = $row['id'];
$rs = $conn2->execute('SELECT CONNECTION_ID() as id');
$row = $rs->fetch();
$id2 = $row['id'];
Tap::isnt($id1, $id2, 'got back connection ids from each and they arent the same');
Tap::ok($conn1->start(), 'started a transaction on conn1');
Tap::ok($conn2->start(), 'started a transaction on conn2');
$rs = $conn1->execute("insert into {$table} values (1)");
Tap::ok($rs, 'inserted a row into test table from conn1');
//if( ! $rs ) Tap::debug( $conn1 );
$rs = $conn2->execute("insert into {$table} values(2)");
Tap::ok($rs, 'inserted a row into test table from conn2');
//if( ! $rs ) Tap::debug( $conn2 );
Tap::ok($rs = $conn1->commit(), 'committed inserted row on conn1');
//if( ! $rs ) Tap::debug( $conn1 );
Tap::ok($rs = $conn2->rollback(), 'rolled back row on conn2');
//if( ! $rs ) Tap::debug( $conn2 );
Tap::ok($rs = $dbmain->execute("select id from {$table}"), 'selected all rows from the table');
$ct = $rs->affected();
Tap::is($ct, 0, 'no rows in the table');
Ejemplo n.º 3
0
<?php

use Gaia\Test\Tap;
use Gaia\affiliate;
Tap::plan(14);
Tap::ok($affiliate instanceof affiliate\Iface, 'object implements the affiliate interface');
$identifiers = array('a' . microtime(TRUE) . '.' . mt_rand(), 'b' . microtime(TRUE) . '.' . mt_rand(), 'c' . microtime(TRUE) . '.' . mt_rand());
$res = $affiliate->join($identifiers);
$affiliate_id = $res[$identifiers[0]];
Tap::is($res, array_fill_keys($identifiers, $affiliate_id), 'ran the join command and got back a key list of identifiers mapping to my affiliate id');
Tap::ok(ctype_digit($affiliate_id), 'affiliate id is a string of digits');
Tap::is($affiliate->related($identifiers), $res, 'affiliate::related() returns same response as join did');
$identifiers[] = $last = 'd' . microtime(TRUE) . '.' . mt_rand();
$res = $affiliate->join($identifiers);
Tap::is($res, array_fill_keys($identifiers, $affiliate_id), 'join a new identifier to the group');
Tap::is($affiliate->related($identifiers), $res, 'affiliate::related() returns same response as join did');
Tap::is($affiliate->identifiers(array($affiliate_id)), array($affiliate_id => $identifiers), 'affiliate::get returns identifiers mapped to the affiliate id');
$unrelated = 'd' . microtime(TRUE) . '.' . mt_rand();
$res = $affiliate->join(array($unrelated));
$new_affiliate_id = $res[$unrelated];
Tap::is($affiliate->identifiers(array($new_affiliate_id)), array($new_affiliate_id => array($unrelated)), 'joining a single identifer, creates an orphaned new affiliateid');
Tap::isnt($affiliate_id, $new_affiliate_id, 'old and new affiliate ids are different');
$res = $affiliate->join(array($last, $unrelated));
Tap::is($res, array_fill_keys(array_merge($identifiers, array($unrelated)), $affiliate_id), 'joined unrelated to the other identifiers');
Tap::is($affiliate->related($identifiers), array_fill_keys(array_merge($identifiers, array($unrelated)), $affiliate_id), 'the new identifer is now related to the rest');
$affiliate->delete($identifiers);
Tap::is($affiliate->related($identifiers), array_fill_keys($identifiers, NULL), 'after deleting the identifiers, no associations');
Tap::is($affiliate->related(array($unrelated)), array_fill_keys(array($unrelated), $affiliate_id), 'the one identifier we didnt delete still remains');
$affiliate->delete(array($unrelated));
Tap::is($affiliate->related(array($unrelated)), array_fill_keys(array($unrelated), NULL), 'deleted the last identifier');