Skip to content

Commit abd1235

Browse files
committed
more tests
1 parent 8b06097 commit abd1235

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

tests/DatabaseHandlerTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,38 @@ public function testPushWithPriority()
9494
]);
9595
}
9696

97+
public function testPushAndPopWithPriority()
98+
{
99+
$handler = new DatabaseHandler($this->config);
100+
$result = $handler->push('queue', 'success', ['key1' => 'value1']);
101+
102+
$this->assertTrue($result);
103+
$this->seeInDatabase('queue_jobs', [
104+
'queue' => 'queue',
105+
'payload' => json_encode(['job' => 'success', 'data' => ['key1' => 'value1']]),
106+
'priority' => 'low',
107+
]);
108+
109+
$result = $handler->setPriority('high')->push('queue', 'success', ['key2' => 'value2']);
110+
111+
$this->assertTrue($result);
112+
$this->seeInDatabase('queue_jobs', [
113+
'queue' => 'queue',
114+
'payload' => json_encode(['job' => 'success', 'data' => ['key2' => 'value2']]),
115+
'priority' => 'high',
116+
]);
117+
118+
$result = $handler->pop('queue', ['high', 'low']);
119+
$this->assertInstanceOf(QueueJob::class, $result);
120+
$payload = ['job' => 'success', 'data' => ['key2' => 'value2']];
121+
$this->assertSame($payload, $result->payload);
122+
123+
$result = $handler->pop('queue', ['high', 'low']);
124+
$this->assertInstanceOf(QueueJob::class, $result);
125+
$payload = ['job' => 'success', 'data' => ['key1' => 'value1']];
126+
$this->assertSame($payload, $result->payload);
127+
}
128+
97129
/**
98130
* @throws ReflectionException
99131
*/
@@ -118,6 +150,30 @@ public function testPushWithPriorityException()
118150
$handler->setPriority('invalid')->push('queue', 'success', ['key' => 'value']);
119151
}
120152

153+
/**
154+
* @throws ReflectionException
155+
*/
156+
public function testPushWithIncorrectQueueFormatException()
157+
{
158+
$this->expectException(QueueException::class);
159+
$this->expectExceptionMessage('The queue name should consists only lowercase letters or numbers.');
160+
161+
$handler = new DatabaseHandler($this->config);
162+
$handler->push('queue*', 'success', ['key' => 'value']);
163+
}
164+
165+
/**
166+
* @throws ReflectionException
167+
*/
168+
public function testPushWithTooLongQueueNameException()
169+
{
170+
$this->expectException(QueueException::class);
171+
$this->expectExceptionMessage('The queue name is too long. It should be no longer than 64 letters.');
172+
173+
$handler = new DatabaseHandler($this->config);
174+
$handler->push(str_repeat('a',65), 'success', ['key' => 'value']);
175+
}
176+
121177
/**
122178
* @throws ReflectionException
123179
*/
@@ -284,6 +340,14 @@ public function testForget()
284340
]);
285341
}
286342

343+
public function testForgetFalse()
344+
{
345+
$handler = new DatabaseHandler($this->config);
346+
$result = $handler->forget(1111);
347+
348+
$this->assertFalse($result);
349+
}
350+
287351
/**
288352
* @throws ReflectionException
289353
*/

tests/PredisHandlerTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,26 @@ public function testClear()
247247

248248
$predis = self::getPrivateProperty($handler, 'predis');
249249
$this->assertSame(0, $predis->zcard('queues:queue1:default'));
250+
251+
$result = $handler->clear('queue1');
252+
$this->assertTrue($result);
253+
}
254+
255+
/**
256+
* @throws ReflectionException
257+
*/
258+
public function testClearAll()
259+
{
260+
$handler = new PredisHandler($this->config);
261+
$result = $handler->clear();
262+
263+
$this->assertTrue($result);
264+
265+
$predis = self::getPrivateProperty($handler, 'predis');
266+
$this->assertCount(0, $predis->keys('queues:*'));
267+
268+
$result = $handler->clear();
269+
$this->assertTrue($result);
250270
}
251271

252272
/**

tests/RedisHandlerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,23 @@ public function testClear()
219219

220220
$redis = self::getPrivateProperty($handler, 'redis');
221221
$this->assertSame(0, $redis->zCard('queues:queue1:default'));
222+
223+
$result = $handler->clear('queue1');
224+
$this->assertTrue($result);
225+
}
226+
227+
public function testClearAll()
228+
{
229+
$handler = new RedisHandler($this->config);
230+
231+
$result = $handler->clear();
232+
$this->assertTrue($result);
233+
234+
$redis = self::getPrivateProperty($handler, 'redis');
235+
$this->assertCount(0, $redis->keys('queues:*'));
236+
237+
$result = $handler->clear();
238+
$this->assertTrue($result);
222239
}
223240

224241
public function testRetry()

0 commit comments

Comments
 (0)