Tap::ok(Transaction::rollback(), 'rolled back the transaction at the global level'); Tap::ok($rs = $dbmain->execute("select id from {$table}"), 'selected all rows from the table'); $ct = $rs->affected(); Tap::is($ct, 2, '2 rows in the table, new rows rolled back'); $rs = $conn1->execute("select id from {$table}"); Tap::is($rs, FALSE, 'after rolling back, new queries fail on rolled back db object'); $dbmain->execute("drop table {$table}"); $db = $newconn(); $raw = file_get_contents(__DIR__ . '/../sample/i_can_eat_glass.txt'); $lines = explode("\n", $raw); $lines = array_slice($lines, 0, 10) + array_slice($lines, 100, 10) + array_slice($lines, 200, 10) + array_slice($lines, 200, 10); $raw = implode("\n", $lines); $sql = "CREATE TEMPORARY TABLE t1utf8 (`i` INT UNSIGNED NOT NULL PRIMARY KEY, `line` VARCHAR(5000) ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8"; $db->execute($sql); foreach ($lines as $i => $line) { //$lines[ $i ] = $line = mb_convert_encoding($line, 'UTF-8', 'auto'); $db->execute('INSERT INTO t1utf8 (`i`, `line`) VALUES (%i, %s)', $i, $line); } $rs = $db->execute('SELECT * FROM t1utf8'); $readlines = array(); while ($row = $rs->fetch()) { $readlines[$row['i']] = $row['line']; } $rs->free(); Tap::cmp_ok($readlines, '===', $lines, 'inserted all the rows and read them back, worked as expected'); //Tap::debug( $readlines ); $rs = $db->execute('SELECT %s AS `d`', $raw); $row = $rs->fetch(); $rs->free(); Tap::cmp_ok($row['d'], '===', $raw, 'passed a huge chunk of utf-8 data to db and asked for it back. got what I sent.'); //Tap::debug( $row['d'] );
$e = NULL; try { $listing = $souk->buy($listing->id); } catch (Exception $e) { $e = $e->getMessage(); } Tap::is($e, 'bid only', 'when buying bid-only, fails'); DB\Transaction::reset(); DB\Connection::reset(); $listing = $souk->bid($listing->id, 1); Tap::is($listing->bid, 1, 'bid works fine, tho'); $listing = Souk($app, $seller_id)->auction(array('bid' => 0, 'reserve' => 5, 'item_id' => $item_id)); $listing = Souk($app, $buyer_id)->bid($listing->id, 5); Tap::is($listing->bid, 5, 'without enable_proxy, bid is set, not stepped'); $listing = Souk($app)->close($listing->id); Tap::is($listing->buyer, 0, 'when reserve isnt met, bidder doesnt win listing'); Tap::is($listing->closed, 1, 'even tho reserve wasnt met, closing still ends the bidding.'); unset($seller_id); unset($buyer_id); unset($item_id); Time::offset(86400 * 30); $id = 0; $ct = 0; while ($listings = Souk($app)->pending(0, 5, $id)) { foreach ($listings as $id) { $ct++; //Tap::debug('pending: ' . $id ); } } Tap::cmp_ok($ct, '>=', 1, "found at least 1 item in pending: {$ct} found"); //print "\n\n";
Tap::is(print_r($res, TRUE), print_r($expected, TRUE), 'search sort by low_price returns results sorted by price from low to high'); $res = array(); foreach (souk($app)->fetch(souk($app)->search(array('sort' => 'high_price', 'item_id' => $item_id, 'seller' => $seller_id))) as $id => $listing) { $res[] = $listing->price; } $expected = $res; rsort($expected, SORT_NUMERIC); Tap::is(print_r($res, TRUE), print_r($expected, TRUE), 'search sort by high_price returns results sorted by price from high to low'); $res = array(); foreach (souk($app)->fetch(souk($app)->search(array('sort' => 'expires_soon_delay', 'item_id' => $item_id, 'seller' => $seller_id))) as $id => $listing) { $res[] = $listing->expires; } $expected = $res; sort($expected, SORT_NUMERIC); Tap::is($res, $expected, 'search sort by expired_soon_delay sorted by expires'); Tap::cmp_ok(min($res), '>', Time::now() + 500, 'all of the results expire after now by more than 500 secs'); $res = array(); foreach (souk($app)->fetch(souk($app)->search(array('item_id' => $item_id, 'seller' => $seller_id, 'floor' => 4, 'ceiling' => 6))) as $id => $listing) { $res[$listing->price] = TRUE; } $res = array_keys($res); sort($res); Tap::is($res, array(4, 5, 6), 'setting floor and ceiling limits the result set to prices in the correct range'); $search = souk($app)->search(array('item_id' => $item_id, 'seller' => $seller_id, 'closed' => 0)); $id = array_shift($search); souk($app)->close($id); $ids = souk($app)->search(array('item_id' => $item_id, 'seller' => $seller_id, 'closed' => 0)); Tap::ok(!in_array($id, $ids, TRUE), 'after closing an item, it no longer appears in the list of unclosed items'); $res = souk($app)->fetch(souk($app)->search(array('item_id' => $item_id, 'seller' => $seller_id, 'closed' => 0, 'only' => 'bid'))); $bidonly = TRUE; foreach ($res as $listing) {
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::claimStart(); $stockpile1 = stockpile($app, $user_id1); $stockpile2 = stockpile($app, $user_id2); $start = microtime(TRUE); $total1 = $stockpile1->add($item_id); $total2 = $stockpile2->add($item_id); $elapsed = microtime(TRUE) - $start; Transaction::commit(); Tap::cmp_ok($elapsed, '<', 1, 'two users adding the same item doesnt create deadlock. took ' . number_format($elapsed, 2) . ' seconds'); $user_id = uniqueUserID(); $item_id = uniqueNumber(1, 10000000); $stockpile = stockpile($app, $user_id); $q = $stockpile->quantity(2); $q->set($stockpile->newId(), array('event' => 'summer2010')); $q->set($stockpile->newId(), array('event' => 'fall2010')); $total = $stockpile->add($item_id, $q); $total = $stockpile->subtract($item_id, 3); Tap::is(quantify($total), 1, 'after adding a tally of 2 and 2 serials for a total of 4, then subtracting 3, my total is now 1'); $user_id = uniqueUserID(); $item_id = uniqueNumber(1, 10000000); $stockpile = stockpile($app, $user_id); $stockpile->add($item_id, 3); $total = $stockpile->convert($item_id, 2); Tap::is($total->tally(), 1, 'After adding 3 quantity items and then converting 2 into serials, the tally is 1');
<?php use Gaia\Test\Tap; use Gaia\NewId; Tap::plan(4); $app = 'test'; $new = new NewId\DB($db, $app = 'test'); $res = $new->testInit(); $id = $new->id(); Tap::ok(ctype_digit($id), 'id returned is a string of digits'); $ids = $new->ids(10); Tap::ok(is_array($ids) && count($ids) == 10, 'ids returned a list of 10 items when I asked for 10'); $status = TRUE; foreach ($ids as $id) { if (!ctype_digit($id)) { $status = FALSE; } } Tap::ok($status, 'all of the ids are digits'); $id1 = $new->id(); $id2 = $new->id(); Tap::cmp_ok($id1, '<', $id2, 'an id generated a second later is larger than the first one');
Tap::is($cache->set($k, $v = '0'), TRUE, 'setting a key to zero returns true'); Tap::cmp_ok($cache->get($k), '===', $v, 'after setting the key to 0, get returns zero value'); Tap::cmp_ok($cache->get(array($k)), '===', array($k => $v), 'multi-get returns the key with zero value'); Tap::ok($cache->set($k, 1, $ttl = 3600 * 24 * 30), 'setting with a huge timeout'); Tap::cmp_ok(strval($cache->get($k)), '===', '1', 'get returns correct value'); $incr = 1000000; Tap::ok($cache->increment($k, $incr), 'incrementing with a large number'); Tap::cmp_ok(strval($cache->get($k)), '===', strval($incr + 1), 'get returns correct value'); Tap::ok($cache->decrement($k, $incr), 'decrementing with a large number'); Tap::cmp_ok(intval($cache->get($k)), '===', 1, 'get returns correct value'); $huge_number = 9.223372036854776E+18; if (!is_int($huge_number)) { $huge_number = 2147483646; } Tap::Debug("testing with {$huge_number}"); Tap::ok($cache->set($k, $v = $huge_number), 'setting a huge number'); Tap::cmp_ok(strval($cache->get($k)), '===', strval($v), 'get returns correct value'); $v = $v + 1; Tap::cmp_ok(strval($cache->increment($k, 1)), '===', strval($v), 'increment a huge number by 1'); Tap::cmp_ok(strval($cache->get($k)), '===', strval($v), 'get returns correct value'); $cache->set($k, $v); $v = $v - 1; Tap::cmp_ok(strval($cache->decrement($k, 1)), '===', strval($v), 'decrement a huge number by 1'); Tap::cmp_ok(strval($cache->get($k)), '===', strval($v), 'get returns correct value'); $k = 'gaia/cache/test/' . microtime(TRUE) . '/' . mt_rand(1, 10000); $v = '我能吞下玻璃而不傷身體'; Tap::ok($cache->set($k, $v), 'setting a string with utf-8 chars in it'); Tap::cmp_ok(strval($cache->get($k)), '===', $v, 'get returns correct value'); Tap::ok($cache->delete($k), 'deleting the key'); Tap::cmp_ok($cache->get($k), '===', NULL, 'after deleting, get returns NULL');