<?php

namespace Gaia\Stockpile;

use Gaia\Test\Tap;
// how many tests are we gonna run?
Tap::plan(93);
// utility function for instantiating the object
function stockpile($app, $user_id, $tran = NULL)
{
    return new Serial($app, $user_id, $tran);
}
// wrap in try/catch so we can fail and print out debug.
try {
    $large_number = stockpile($app, 1)->quantity(100);
    include __DIR__ . '/common_tests.php';
    include __DIR__ . '/transaction_extended_tests.php';
    include __DIR__ . '/serial_tests.php';
    include __DIR__ . '/trade_tests.php';
} catch (\Exception $e) {
    Tap::fail('unexpected exception thrown');
    print $e;
}
<?php

use Gaia\Test\Tap;
if (!class_exists('\\MySQLi')) {
    Tap::plan('skip_all', 'php-mysqli not installed');
}
<?php

use Gaia\Stratum;
use Gaia\Test\Tap;
use Gaia\Time;
if (!isset($use_int_keys)) {
    $use_int_keys = FALSE;
}
if (!isset($use_bin_constraint)) {
    $use_bin_constraint = FALSE;
}
if (!isset($plan)) {
    $plan = 0;
}
Tap::plan($plan + 14);
Tap::ok($stratum instanceof Stratum\Iface, 'stratum object instantiated with correct interface');
$pairs = array();
for ($i = 1; $i <= 10; $i++) {
    $key = $use_int_keys ? strval($i + 100000000) : 'foo' . $i;
    do {
        $value = strval(mt_rand(1, 10000000));
    } while (in_array($value, $pairs));
    $pairs[$key] = $value;
    $res = $stratum->store($key, $value);
}
$res = $stratum->query();
asort($pairs, TRUE);
Tap::is($res, $pairs, 'stored a bunch of pairs ... query matches what I stored');
//Tap::debug( $pairs );
//Tap::debug( $res );
Tap::is($stratum->query(array('limit' => '0,1')), array_slice($pairs, 0, 1, TRUE), 'queried the first in the list');
<?php

include __DIR__ . '/../../assert/bcmath_installed.php';
use Gaia\Test\Tap;
// how many tests are we gonna run?
Tap::plan($expected_test_count);
Gaia\Stockpile\Storage::attach(function () {
    return 'test';
});
Gaia\Stockpile\Storage::enableAutoSchema();
function souk($app, $user_id = NULL)
{
    return new Gaia\Souk\Stockpile(new \Gaia\Souk($app, $user_id), binder());
}
class Souk_StockpileHybridBinderTest1 implements Gaia\Souk\Stockpilebinder_Iface
{
    protected static $item_app = 'test1';
    protected static $currency_app = 'test1';
    protected static $currency_id = 1;
    public function itemAccount($user_id)
    {
        return new Gaia\Stockpile\Hybrid(self::$item_app, $user_id);
    }
    public function currencyAccount($user_id)
    {
        return new Gaia\Stockpile\Hybrid(self::$currency_app, $user_id);
    }
    public function currencyId()
    {
        return self::$currency_id;
    }
<?php

use Gaia\Test\Tap;
if (!function_exists('mcrypt_encrypt')) {
    Tap::plan('skip_all', 'php5-mcrypt extension not installed');
}
<?php

use Gaia\Test\Tap;
if (!@fsockopen('api.facebook.com', '443')) {
    Tap::plan('skip_all', 'unable to connect to facebook api');
}
<?php

namespace Gaia\Stockpile;

use Gaia\Test\Tap;
include __DIR__ . '/../../assert/memcache_installed.php';
include __DIR__ . '/../../assert/memcache_running.php';
// how many tests are we gonna run?
Tap::plan(5);
// utility function for instantiating the object
function stockpile($app, $user_id)
{
    return new Cacher(new Tally($app, $user_id), memcache());
}
// wrap in try/catch so we can fail and print out debug.
try {
    include __DIR__ . '/speed_tests.php';
} catch (\Exception $e) {
    Tap::fail('unexpected exception thrown');
    print $e;
}
<?php

namespace Gaia\Stockpile;

use Gaia\Test\Tap;
// how many tests are we gonna run?
Tap::plan(97);
// utility function for instantiating the object
function stockpile($app, $user_id, $tran = NULL)
{
    return new Hybrid($app, $user_id, $tran);
}
// wrap in try/catch so we can fail and print out debug.
try {
    include __DIR__ . '/common_tests.php';
    include __DIR__ . '/transaction_extended_tests.php';
    include __DIR__ . '/trade_tests.php';
    include __DIR__ . '/hybrid_tests.php';
} catch (\Exception $e) {
    Tap::fail('unexpected exception thrown');
    print $e;
}
<?php

use Gaia\Test\Tap;
if (!class_exists('BaseFacebook')) {
    Tap::plan('skip_all', 'basefacebook class not loaded.');
}
<?php

use Gaia\Test\Tap;
if (!in_array('ssl', stream_get_transports())) {
    Tap::plan('skip_all', 'php ssl socket transport not installed');
}
<?php

use Gaia\Skein;
use Gaia\Test\Tap;
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);
Exemplo n.º 12
0
<?php

use Gaia\Identifier;
use Gaia\DB;
use Gaia\Test\Tap;
include __DIR__ . '/../common.php';
include __DIR__ . '/../assert/mysqli_installed.php';
include __DIR__ . '/../assert/mysql_running.php';
$db = new MySQLi('127.0.0.1', NULL, NULL, 'test', '3306');
if ($db->connect_error) {
    Tap::plan('skip_all', 'mysqli: ' . $db->connect_error);
}
$create_identifier = function ($table = NULL) use($db) {
    if ($table === NULL) {
        $table = 'test_identifier';
    }
    $db = new DB($db);
    DB\Connection::add('test', $db);
    $identifier = new Identifier\MySQL(function () use($db) {
        return $db;
    }, $table);
    $schema = $identifier->schema();
    $schema = str_replace('CREATE TABLE', 'CREATE TEMPORARY TABLE', $schema);
    $db->execute($schema);
    return $identifier;
};
Exemplo n.º 13
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');
Exemplo n.º 14
0
<?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');
<?php

use Gaia\Test\Tap;
if (!function_exists('apc_fetch') || !ini_get('apc.enable_cli')) {
    Tap::plan('skip_all', 'php5-apc extension not installed or enabled (check apc.enable_cli=1)');
}
<?php

namespace Gaia\Stockpile;

use Gaia\Test\Tap;
// how many tests are we gonna run?
Tap::plan(95);
// utility function for instantiating the object
function stockpile($app, $user_id)
{
    return new Cacher(new Serial($app, $user_id), cachemock());
}
$user_id = uniqueUserID();
// wrap in try/catch so we can fail and print out debug.
try {
    $large_number = stockpile($app, $user_id)->quantity(100);
    include __DIR__ . '/common_tests.php';
    include __DIR__ . '/cache_tests.php';
    include __DIR__ . '/serial_tests.php';
    include __DIR__ . '/trade_tests.php';
} catch (\Exception $e) {
    Tap::fail('unexpected exception thrown');
    print $e;
}
<?php

use Gaia\Test\Tap;
if (!@fsockopen('127.0.0.1', 5432)) {
    Tap::plan('skip_all', 'postgres not running on 127.0.0.1:5432');
}
Exemplo n.º 18
0
<?php

include_once __DIR__ . '/../common.php';
use Gaia\Test\Tap;
use Gaia\Container;
Tap::plan(22);
$c = new Container();
foreach (array('result_set', 'result_get', 'result_isset', 'result_unset') as $key) {
    ${$key} = array();
}
if (!isset($input) || !is_array($input)) {
    $input = array();
}
foreach ($input as $k => $v) {
    $result_set[$k] = $c->{$k} = $v;
    $result_isset[$k] = isset($c->{$k});
    $result_get[$k] = $c->{$k};
    unset($c->{$k});
    $result_unset[$k] = $c->{$k};
}
Tap::is($input, $result_set, 'set works properly');
Tap::is($input, $result_get, 'get works properly');
Tap::is(array_fill_keys(array_keys($input), TRUE), $result_isset, 'isset works properly');
Tap::is(array_fill_keys(array_keys($input), NULL), $result_unset, 'unset works properly');
Tap::is($c->non_existent, NULL, 'non-existent variables are null');
$c->load($input);
Tap::is($c->get(array_keys($input)), $input, 'multi-get works properly');
Tap::is($c->all(), $input, 'grabbed all of the data at once');
$each = array();
while (list($k, $v) = $c->each()) {
    $each[$k] = $v;
<?php

use Gaia\Test\Tap;
if (!in_array('mysql', PDO::getAvailableDrivers())) {
    Tap::plan('skip_all', 'this version of PDO does not support mysql');
}
<?php

use Gaia\Test\Tap;
if (!@fsockopen('127.0.0.1', '3306')) {
    Tap::plan('skip_all', 'mysql-server not running on localhost');
}
<?php

use Gaia\Test\Tap;
if (!class_exists('domdocument')) {
    Tap::plan('skip_all', 'php dom classes missing. install php5-xml.');
}
<?php

namespace Gaia\Stockpile;

use Gaia\Test\Tap;
// how many tests are we gonna run?
Tap::plan(77);
// utility function for instantiating the object
function stockpile($app, $user_id)
{
    return new Cacher(new Tally($app, $user_id), cachemock());
}
// wrap in try/catch so we can fail and print out debug.
try {
    include __DIR__ . '/common_tests.php';
    include __DIR__ . '/cache_tests.php';
    include __DIR__ . '/trade_tests.php';
} catch (\Exception $e) {
    Tap::fail('unexpected exception thrown');
    print $e;
}
<?php

use Gaia\Test\Tap;
if (!function_exists('dba_open')) {
    Tap::plan('skip_all', 'dba not enabled');
}
<?php

use Gaia\Test\Tap;
if (!@fsockopen('127.0.0.1', '11211')) {
    Tap::plan('skip_all', 'couchbase not running on 127.0.0.1:11211');
}
if (!@fsockopen('127.0.0.1', '8092')) {
    Tap::plan('skip_all', 'couchbase REST API not running on 127.0.0.1:8092');
}
Exemplo n.º 25
0
<?php

use Gaia\Test\Tap;
if (!@fsockopen('127.0.0.1', '8098')) {
    Tap::plan('skip_all', 'Riak not running on localhost');
}
Exemplo n.º 26
0
<?php

use Gaia\Test\Tap;
if (!function_exists('pg_connect')) {
    Tap::plan('skip_all', 'php-postgres not installed');
}
<?php

use Gaia\Test\Tap;
use Gaia\DB;
use Gaia\DB\Transaction;
$original = $db;
Tap::plan(51);
$db = new DB($db);
Tap::is(spl_object_hash($original), $db->hash(), 'the hash function returns the hash of the original db object');
DB\Connection::load(array('test' => function () use($db) {
    return $db;
}));
Tap::ok(DB\Connection::instance('test') === $db, 'db instance returns same object we instantiated at first');
Tap::is($db->isa('mysql'), TRUE, 'driver is mysql');
$rs = $db->execute('SELECT %s as foo, %s as bar', 'dummy\'', 'rummy');
Tap::ok($rs, 'query executed successfully');
Tap::is($rs->fetch(), array('foo' => 'dummy\'', 'bar' => 'rummy'), 'sql query preparation works on strings');
$rs = $db->execute('SELECT %i as test', '1112122445543333333333');
Tap::is($rs->fetch(), array('test' => '1112122445543333333333'), 'query execute works injecting big integer in');
$rs = $db->execute('SELECT %i as test', 'dummy');
Tap::is($rs->fetch(), array('test' => '0'), 'query execute sanitizes non integer');
$rs = $db->execute('SELECT %f as test', '1112.122445543333333333');
Tap::is($rs->fetch(), array('test' => '1112.122445543333333333'), 'query execute works injecting big float in');
$rs = $db->execute('SELECT %f as test', 'dummy');
Tap::is($rs->fetch(), array('test' => '0'), 'query execute sanitizes non float');
$query = $db->prep('%s', array('dummy', 'rummy'));
Tap::is($query, "'dummy', 'rummy'", 'format query handles arrays of strings');
$query = $db->prep('%i', array(1, 2, 3));
Tap::is($query, '1, 2, 3', 'format query handles arrays of integers');
$query = $db->prep('%f', array(1.545, 2.2, 3));
Tap::is($query, '1.545, 2.2, 3', 'format query handles arrays of floats');
<?php

use Gaia\Test\Tap;
if (!function_exists('mb_check_encoding')) {
    Tap::plan('skip_all', 'php5-mbstring not installed. compile php with --enable-mbstring');
}
<?php

use Gaia\Test\Tap;
if (!@fsockopen('127.0.0.1', '11300')) {
    Tap::plan('skip_all', 'Beanstalkd not running on localhost');
}
Exemplo n.º 30
0
<?php

use Gaia\Test\Tap;
define('BASEPATH', 'phar://' . __DIR__ . '/../../vendor/codeigniter.phar/system/');
define('APPPATH', __DIR__ . '/../db/lib/codeigniter/app/');
@(include BASEPATH . 'database/DB.php');
@(include BASEPATH . 'core/Common.php');
if (!function_exists('DB')) {
    Tap::plan('skip_all', 'CodeIgniter database library not loaded');
}