Example #1
0
 public function getCounter()
 {
     $pdo = new \PDO('sqlite::memory:', null, null, [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
     $counter = new \Cachet\Counter\PDOSQLite($pdo);
     $counter->ensureTableExists();
     return $counter;
 }
Example #2
0
    $pdo = new \PDO('sqlite:' . $initialState->temp);
    $counter = new \Cachet\Counter\PDOSQLite($pdo);
    $counter->ensureTableExists();
    return $initialState;
}, 'setupWorker' => function ($workerState) {
    $pdo = new \PDO('sqlite:' . $workerState->temp);
    $workerState->counter = new \Cachet\Counter\PDOSQLite($pdo);
}, 'test' => function ($workerState) use($config) {
    for ($i = 0; $i < $config->counterRuns; $i++) {
        $workerState->counter->increment('count');
    }
}, 'teardownParent' => function ($parentState, $initialState) {
    unlink($initialState->temp);
}, 'check' => function ($workers, $responses, $parentState, $initialState) use($config) {
    $pdo = new \PDO('sqlite:' . $initialState->temp);
    $sqlite = new \Cachet\Counter\PDOSQLite($pdo);
    $count = $sqlite->value('count');
    $expected = $config->workerCount * $config->counterRuns;
    if ($count != $expected) {
        return [false, "Count was {$count}, expected {$expected}"];
    } else {
        return [true];
    }
}], 'mysqlCounterTest' => ['setupParent' => function ($parentState) {
    $workerState = (object) ['table' => 'cachet_counter_test'];
    $counter = new \Cachet\Counter\PDOMySQL($GLOBALS['settings']['mysql'], $workerState->table);
    $counter->ensureTableExists();
    $pdo = $counter->connector->connect();
    $pdo->exec("TRUNCATE TABLE `{$counter->tableName}`");
    $parentState->counter = $counter;
    return $workerState;