From 5e2f5f7a71436d110b4b446585b33fbd807f2c1a Mon Sep 17 00:00:00 2001 From: michalsn Date: Fri, 20 Sep 2024 20:12:25 +0200 Subject: [PATCH] update tests --- src/Models/QueueJobModel.php | 9 +++++---- tests/Models/QueueJobModelTest.php | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Models/QueueJobModel.php b/src/Models/QueueJobModel.php index adf6742..ed7d26f 100644 --- a/src/Models/QueueJobModel.php +++ b/src/Models/QueueJobModel.php @@ -101,11 +101,12 @@ private function skipLocked(string $sql): string } if ($this->db->DBDriver === 'OCI8') { - $sql = preg_replace('/ OFFSET .*/', '', $sql); - $sql = "SELECT * FROM ({$sql}) WHERE ROWNUM = 1"; + $sql = str_replace('SELECT *', 'SELECT "id"', $sql); + // prepare final query + $sql = sprintf('SELECT * FROM "%s" WHERE "id" = (%s)', $this->db->prefixTable($this->table), $sql); } - return $sql .= ' FOR UPDATE SKIP LOCKED'; + return $sql . ' FOR UPDATE SKIP LOCKED'; } /** @@ -118,7 +119,7 @@ private function setPriority(BaseBuilder $builder, array $priority): BaseBuilder if ($priority !== ['default']) { if ($this->db->DBDriver !== 'MySQLi') { $builder->orderBy( - 'CASE priority ' + sprintf('CASE %s ', $this->db->protectIdentifiers('priority')) . implode( ' ', array_map(static fn ($value, $key) => "WHEN '{$value}' THEN {$key}", $priority, array_keys($priority)) diff --git a/tests/Models/QueueJobModelTest.php b/tests/Models/QueueJobModelTest.php index 01c8532..cf829d3 100644 --- a/tests/Models/QueueJobModelTest.php +++ b/tests/Models/QueueJobModelTest.php @@ -41,11 +41,9 @@ public function testSkipLocked(): void if ($model->db->DBDriver === 'SQLite3') { $this->assertSame($sql, $result); } elseif ($model->db->DBDriver === 'SQLSRV') { - $expected = 'SELECT * FROM queue_jobs WITH (ROWLOCK,UPDLOCK,READPAST) WHERE queue = "test" AND status = 0 AND available_at < 123456 LIMIT 1'; - $this->assertSame($expected, $result); + $this->assertStringContainsString('WITH (ROWLOCK,UPDLOCK,READPAST) WHERE', $result); } else { - $expected = 'SELECT * FROM queue_jobs WHERE queue = "test" AND status = 0 AND available_at < 123456 LIMIT 1 FOR UPDATE SKIP LOCKED'; - $this->assertSame($expected, $result); + $this->assertStringContainsString('FOR UPDATE SKIP LOCKED', $result); } }