Exemple #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;
 }
    }
}, 'check' => function ($workers, $responses, $parentState) use($config) {
    $redis = redis_create_testing();
    $count = $redis->get('counter/count');
    $expected = $config->workerCount * $config->counterRuns;
    if ($count != $expected) {
        return [false, "Count was {$count}, expected {$expected}"];
    } else {
        return [true];
    }
}], 'sqliteCounterTest' => ['setupParent' => function () {
    $initialState = (object) [];
    $initialState->temp = tempnam(sys_get_temp_dir(), '');
    $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;