From a94f5eded2bd90eb5504de9e32d8d34f9c7ea1dd Mon Sep 17 00:00:00 2001 From: Dmitriy Krivopalov Date: Wed, 13 Dec 2023 10:22:35 +0300 Subject: [PATCH] fix stub --- tests/service/StageCommandStub.php | 8 ++++---- tests/service/StageStorage.php | 32 ++++++++++++++++++------------ tests/service/TaskCommandStub.php | 6 +++--- tests/service/TaskStorage.php | 32 ++++++++++++++++++------------ 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/tests/service/StageCommandStub.php b/tests/service/StageCommandStub.php index 8481f58..dc90327 100644 --- a/tests/service/StageCommandStub.php +++ b/tests/service/StageCommandStub.php @@ -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')); @@ -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(); @@ -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); diff --git a/tests/service/StageStorage.php b/tests/service/StageStorage.php index ce142af..bf3c07f 100644 --- a/tests/service/StageStorage.php +++ b/tests/service/StageStorage.php @@ -87,48 +87,54 @@ 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, @@ -136,7 +142,7 @@ private function prepareConditions(string $prepareSql, array $conditions, SQLite } } - $result = $stmtt->execute(); + $result = $stmt->execute(); if ($result === false) { throw new RuntimeException('ModelRead error: ' . $this->connection->lastErrorMsg()); } diff --git a/tests/service/TaskCommandStub.php b/tests/service/TaskCommandStub.php index 9d56b51..962dc7c 100644 --- a/tests/service/TaskCommandStub.php +++ b/tests/service/TaskCommandStub.php @@ -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')); @@ -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) { @@ -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); diff --git a/tests/service/TaskStorage.php b/tests/service/TaskStorage.php index 59bdc5d..03f7ef2 100644 --- a/tests/service/TaskStorage.php +++ b/tests/service/TaskStorage.php @@ -91,48 +91,54 @@ 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, @@ -140,7 +146,7 @@ private function prepareConditions(string $prepareSql, array $conditions, SQLite } } - $result = $stmtt->execute(); + $result = $stmt->execute(); if ($result === false) { throw new RuntimeException('ModelRead error: ' . $this->connection->lastErrorMsg()); }