Skip to content

Commit

Permalink
fix stub
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaukutsu committed Dec 13, 2023
1 parent 8d084d5 commit a94f5ed
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
8 changes: 4 additions & 4 deletions tests/service/StageCommandStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function create(EntityUuid $uuid, StageModelCreate $model): StageModel
$stmt->bindValue(':uuid', $uuid->getUuid());
$stmt->bindValue(':uuid_task', $model->taskUuid);
$stmt->bindValue(':flag', $model->flag, SQLITE3_INTEGER);
$stmt->bindValue(':state', $model->state);
$stmt->bindValue(':handler', $model->handler);
$stmt->bindValue(':state', $model->state, SQLITE3_BLOB);
$stmt->bindValue(':handler', $model->handler, SQLITE3_BLOB);
$stmt->bindValue(':order', $model->order, SQLITE3_INTEGER);
$stmt->bindValue(':created_at', gmdate('c'));
$stmt->bindValue(':updated_at', gmdate('c'));
Expand All @@ -60,7 +60,7 @@ public function state(EntityUuid $uuid, StageModelState $model): StageModel

$stmt->bindValue(':uuid', $uuid->getUuid());
$stmt->bindValue(':flag', $model->flag, SQLITE3_INTEGER);
$stmt->bindValue(':state', $model->state);
$stmt->bindValue(':state', $model->state, SQLITE3_BLOB);
$stmt->bindValue(':updated_at', gmdate('c'));
if ($stmt->execute() === false) {
$this->mutex->unlock();
Expand All @@ -83,7 +83,7 @@ public function stateByTask(EntityUuid $uuid, StageModelState $model): bool
);

$stmt->bindValue(':flag', $model->flag, SQLITE3_INTEGER);
$stmt->bindValue(':state', $model->state);
$stmt->bindValue(':state', $model->state, SQLITE3_BLOB);
$stmt->bindValue(':updated_at', gmdate('c'));
$stmt->bindValue(':uuid', $uuid->getUuid());
$stmt->bindValue(':running', (new TaskFlag())->setRunning()->toValue(), SQLITE3_INTEGER);
Expand Down
32 changes: 19 additions & 13 deletions tests/service/StageStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,56 +87,62 @@ private function prepareData(array $data): StageModel

private function prepareSql(array $conditions): string
{
$stmttConditions = '';
$stmtConditions = '';
foreach ($conditions as $key => $value) {
if ($stmttConditions !== '') {
$stmttConditions .= ' AND ';
if ($stmtConditions !== '') {
$stmtConditions .= ' AND ';
}

if (is_array($value)) {
$stmttConditions .= '( ';
$stmtConditions .= '( ';
$row = 0;
foreach ($value as $ignored) {
if ($row > 0) {
$stmttConditions .= ' OR ';
$stmtConditions .= ' OR ';
}

$stmttConditions .= "\"$key\"=:" . $key . $row;
$stmtConditions .= "\"$key\"=:" . $key . $row;
$row++;
}
$stmttConditions .= ') ';
$stmtConditions .= ') ';
} else {
$stmttConditions .= "\"$key\"=:" . $key;
$stmtConditions .= "\"$key\"=:" . $key;
}
}

return 'SELECT * FROM stage WHERE ' . trim($stmttConditions);
return 'SELECT * FROM stage WHERE ' . trim($stmtConditions);
}

private function prepareConditions(string $prepareSql, array $conditions, SQLite3 $db): SQLite3Result
{
$stmtt = $db->prepare($prepareSql);
$stmt = $db->prepare($prepareSql);
foreach ($conditions as $key => $value) {
if (is_array($value)) {
$row = 0;
foreach ($value as $itemValue) {
$stmtt->bindValue(
$stmt->bindValue(
':' . $key . $row,
$itemValue,
is_int($itemValue) ? SQLITE3_INTEGER : SQLITE3_TEXT,
);
$row++;
}
} elseif ($key === 'handler' || $key === 'state') {
$stmt->bindValue(
':' . $key,
$value,
SQLITE3_BLOB,
);
} else {
$stmtt->bindValue(
$stmt->bindValue(
':' . $key,
$value,
is_int($value) ? SQLITE3_INTEGER : SQLITE3_TEXT,
);
}
}

$result = $stmtt->execute();
$result = $stmt->execute();
if ($result === false) {
throw new RuntimeException('ModelRead error: ' . $this->connection->lastErrorMsg());
}
Expand Down
6 changes: 3 additions & 3 deletions tests/service/TaskCommandStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function create(EntityUuid $uuid, TaskModelCreate $model): TaskModel
$stmt->bindValue(':uuid', $uuid->getUuid());
$stmt->bindValue(':title', $model->title);
$stmt->bindValue(':flag', $model->flag, SQLITE3_INTEGER);
$stmt->bindValue(':state', $model->state);
$stmt->bindValue(':state', $model->state, SQLITE3_BLOB);
$stmt->bindValue(':checksum', $model->checksum);
$stmt->bindValue(':created_at', gmdate('c'));
$stmt->bindValue(':updated_at', gmdate('c'));
Expand Down Expand Up @@ -70,7 +70,7 @@ public function state(EntityUuid $uuid, TaskModelState $model): TaskModel
);

$stmt->bindValue(':flag', $model->flag, SQLITE3_INTEGER);
$stmt->bindValue(':state', $model->state);
$stmt->bindValue(':state', $model->state, SQLITE3_BLOB);
$stmt->bindValue(':updated_at', gmdate('c'));
$stmt->bindValue(':uuid', $uuid->getUuid());
if ($stmt->execute() === false) {
Expand All @@ -93,7 +93,7 @@ public function terminate(array $indexUuid, TaskModelState $model): bool
);

$stmt->bindValue(':flag', $model->flag, SQLITE3_INTEGER);
$stmt->bindValue(':state', $model->state);
$stmt->bindValue(':state', $model->state, SQLITE3_BLOB);
$stmt->bindValue(':updated_at', gmdate('c'));
$stmt->bindValue(':uuid', $uuid);
$stmt->bindValue(':running', (new TaskFlag())->setRunning()->toValue(), SQLITE3_INTEGER);
Expand Down
32 changes: 19 additions & 13 deletions tests/service/TaskStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,56 +91,62 @@ private function prepareData(array $data): TaskModel

private function prepareSql(array $conditions): string
{
$stmttConditions = '';
$stmtConditions = '';
foreach ($conditions as $key => $value) {
if ($stmttConditions !== '') {
$stmttConditions .= ' AND ';
if ($stmtConditions !== '') {
$stmtConditions .= ' AND ';
}

if (is_array($value)) {
$stmttConditions .= '( ';
$stmtConditions .= '( ';
$row = 0;
foreach ($value as $ignored) {
if ($row > 0) {
$stmttConditions .= ' OR ';
$stmtConditions .= ' OR ';
}

$stmttConditions .= $key . '=:' . $key . $row;
$stmtConditions .= $key . '=:' . $key . $row;
$row++;
}
$stmttConditions .= ') ';
$stmtConditions .= ') ';
} else {
$stmttConditions .= $key . '=:' . $key;
$stmtConditions .= $key . '=:' . $key;
}
}

return 'SELECT * FROM task WHERE ' . trim($stmttConditions);
return 'SELECT * FROM task WHERE ' . trim($stmtConditions);
}

private function prepareConditions(string $prepareSql, array $conditions, SQLite3 $db): SQLite3Result
{
$stmtt = $db->prepare($prepareSql);
$stmt = $db->prepare($prepareSql);
foreach ($conditions as $key => $value) {
if (is_array($value)) {
$row = 0;
foreach ($value as $itemValue) {
$stmtt->bindValue(
$stmt->bindValue(
':' . $key . $row,
$itemValue,
is_int($itemValue) ? SQLITE3_INTEGER : SQLITE3_TEXT,
);
$row++;
}
} elseif ($key === 'state') {
$stmt->bindValue(
':' . $key,
$value,
SQLITE3_BLOB,
);
} else {
$stmtt->bindValue(
$stmt->bindValue(
':' . $key,
$value,
is_int($value) ? SQLITE3_INTEGER : SQLITE3_TEXT,
);
}
}

$result = $stmtt->execute();
$result = $stmt->execute();
if ($result === false) {
throw new RuntimeException('ModelRead error: ' . $this->connection->lastErrorMsg());
}
Expand Down

0 comments on commit a94f5ed

Please sign in to comment.