$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";
if (!isset($seller_id)) { $seller_id = uniqueUserId(); } if (!isset($buyer_id)) { $buyer_id = uniqueUserId(); } if (!isset($item_id)) { $item_id = uniqueNumber(1, 100000); } Transaction::start(); $souk = souk($app, $seller_id); $listings = array(); for ($i = 1; $i <= 16; $i++) { $listing = $souk->auction(array($i % 2 == 0 ? 'bid' : 'price' => ($i * 10 + 1) % 9, 'item_id' => $item_id)); $listings[$listing->id] = $listing; Time::offset(3600 * 12 + 91); } Transaction::commit(); $ids = souk($app)->search(array('sort' => 'expires_soon', 'item_id' => $item_id, 'seller' => $seller_id)); Tap::cmp_ok(count($ids), '>', 12, 'search expires_soon found results'); $found = TRUE; foreach ($ids as $id) { if (isset($listings[$id])) { continue; } $found = FALSE; break; } Tap::ok($found, 'returned only rows we created'); $owned = TRUE; foreach ($ids as $id) {
function advanceCurrentTime($secs = 1) { \Gaia\Time::offset($secs); }
use Gaia\Time; if (!isset($extra_tests)) { $extra_tests = 0; } Tap::plan(27 + $extra_tests); Tap::ok($skein instanceof Skein\Iface, 'created new skein object, implements expected interface'); $id = $skein->add($data = array('foo' => mt_rand(1, 100000000))); Tap::ok(ctype_digit($id), 'added data, got back an id'); Tap::is($skein->get($id), $data, 'read back the data I stored'); Tap::is($skein->get(array($id)), array($id => $data), 'multi-get interface works too'); $data = array('foo' => mt_rand(1, 100000000)); $skein->store($id, $data); Tap::is($skein->get($id), $data, 'stored the data with new values, get returns what I wrote'); $batch = array($id => $data); for ($i = 0; $i < 10; $i++) { Time::offset(86400 * 5); $id = $skein->add($data = array('foo' => mt_rand(1, 100000000))); $batch[$id] = $data; } $ids = array_keys($batch); $res = $skein->get($ids); Tap::is($res, $batch, 'added a bunch of keys and read them back using get( ids ) interface'); Tap::is($skein->ids(array('limit' => 100)), $ids, 'got the keys back in ascending order'); Tap::is($res = $skein->ids(array('sort' => 'ascending', 'limit' => 5)), array_slice($ids, 0, 5), 'got the keys back in ascending order, limit 5'); Tap::is($res = $skein->ids(array('sort' => 'ascending', 'limit' => 5, 'start_after' => $ids[5])), array_slice($ids, 6, 5), 'got the keys back in ascending order, limit 5, starting after the 5th id'); Tap::is($res = $skein->ids(array('limit' => 1)), array($ids[0]), 'with limit 1, got back the 1st id'); $ids = array_reverse($ids); Tap::is($skein->ids(array('sort' => 'descending', 'limit' => 100)), $ids, 'got the keys back in descending order'); Tap::is($res = $skein->ids(array('sort' => 'descending', 'limit' => 5)), array_slice($ids, 0, 5), 'got the keys back in descending order, limit 5'); Tap::is($res = $skein->ids(array('sort' => 'descending', 'limit' => 5, 'start_after' => $ids[5])), array_slice($ids, 5, 5), 'got the keys back in descending order, limit 5, starting with the 5th id'); Tap::is($res = $skein->ids(array('sort' => 'descending', 'limit' => 1)), array($ids[0]), 'with limit 1, got back the last id');
Tap::ok($res, 'checked each key and got back what I wrote'); $ret = $cache->get(array_keys($data)); $res = TRUE; foreach ($data as $k => $v) { if ($ret[$k] != $v) { $res = FALSE; } } Tap::ok($res, 'grabbed the keys all at once, got what I wrote'); $k = 'gaia/cache/test/' . microtime(TRUE) . '/' . mt_rand(1, 10000); Tap::ok($cache->add($k, 1, 10), 'adding a non-existent key'); Tap::ok(!$cache->add($k, 1, 10), 'second time, the add fails'); if ($skip_expiration_tests || !method_exists($cache, 'ttlEnabled') || !$cache->ttlEnabled()) { Tap::ok(TRUE, 'skipping expire test'); } else { Time::offset(11); Tap::ok($cache->add($k, 1, 10), 'after expiration time, add works'); } Tap::ok($cache->replace($k, 1, 10), 'replace works after the successful add'); Tap::ok($cache->delete($k), 'successfully deleted the key'); Tap::ok(!$cache->replace($k, 1, 10), 'replace fails after key deletion'); Tap::ok($cache->add($k, 1, 10), 'add works after key deletion'); Tap::ok($cache->replace($k, 1, 10), 'replace works after key is added'); $k = 'gaia/cache/test/' . microtime(TRUE) . '/' . mt_rand(1, 10000); Tap::ok($cache->get($k) === NULL, 'cache get on a non-existent key returns NULL (not false)'); $k = 'gaia/cache/test/' . microtime(TRUE) . '/' . mt_rand(1, 10000); Tap::is($cache->increment($k, 1), FALSE, 'increment a new key returns (bool) FALSE'); Tap::is($cache->decrement($k, 1), FALSE, 'decrement a new key returns (bool) FALSE'); Tap::cmp_ok($cache->set($k, 'test'), '===', TRUE, 'setting a key returns bool TRUE'); Tap::cmp_ok($cache->replace($k, 'test1'), '===', TRUE, 'replacing a key returns bool TRUE'); Tap::cmp_ok($cache->{$k} = '11', '===', '11', 'setting using the magic method property approach returns value');
} if (!isset($buyer_id)) { $buyer_id = uniqueUserId(); } if (!isset($item_id)) { $item_id = uniqueNumber(1, 100000); } Transaction::reset(); Connection::reset(); Transaction::start(); $souk = souk($app, $seller_id); $listing = $souk->auction(array('price' => 10, 'bid' => 0, 'item_id' => $item_id)); $read = $souk->get($listing->id); Tap::is($listing, $read, 'new auction is readable before transaction is committed, while in the transaction'); Transaction::rollback(); Transaction::reset(); Connection::reset(); $read = $souk->get($listing->id); Tap::is($read, NULL, 'after transaction rollback, no entry found'); Transaction::reset(); Transaction::start(); $souk = souk($app, $seller_id); $listing = $souk->auction(array('price' => 10, 'bid' => 0, 'item_id' => $item_id)); Time::offset(86400 * 15); $listing = $souk->close($listing->id); Transaction::commit(); Tap::is($listing->closed, 1, 'creating and closing a listing works inside a transaction'); unset($seller_id); unset($buyer_id); unset($item_id); //print "\n\n";