-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathQueueJobModelTest.php
More file actions
62 lines (49 loc) · 1.76 KB
/
QueueJobModelTest.php
File metadata and controls
62 lines (49 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter Queue.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Tests\Models;
use CodeIgniter\Queue\Models\QueueJobModel;
use CodeIgniter\Test\ReflectionHelper;
use Tests\Support\TestCase;
/**
* @internal
*/
final class QueueJobModelTest extends TestCase
{
use ReflectionHelper;
public function testQueueJobModel(): void
{
$model = model(QueueJobModel::class);
$this->assertInstanceOf(QueueJobModel::class, $model);
}
public function testSkipLocked(): void
{
$model = model(QueueJobModel::class);
$method = $this->getPrivateMethodInvoker($model, 'skipLocked');
$sql = 'SELECT * FROM queue_jobs WHERE queue = "test" AND status = 0 AND available_at < 123456 LIMIT 1';
$result = $method($sql);
if ($model->db->DBDriver === 'SQLite3') {
$this->assertSame($sql, $result);
} elseif ($model->db->DBDriver === 'SQLSRV') {
$this->assertStringContainsString('WITH (ROWLOCK,UPDLOCK,READPAST) WHERE', (string) $result);
} else {
$this->assertStringContainsString('FOR UPDATE SKIP LOCKED', (string) $result);
}
}
public function testSkipLockedFalse(): void
{
config('Queue')->database['skipLocked'] = false;
$model = model(QueueJobModel::class);
$method = $this->getPrivateMethodInvoker($model, 'skipLocked');
$sql = 'SELECT * FROM queue_jobs WHERE queue = "test" AND status = 0 AND available_at < 123456 LIMIT 1';
$result = $method($sql);
$this->assertSame($sql, $result);
}
}