Skip to content

Commit 1bafc41

Browse files
committed
fix phpcpd
1 parent 5a8b00a commit 1bafc41

File tree

4 files changed

+103
-109
lines changed

4 files changed

+103
-109
lines changed

tests/DatabaseHandlerTest.php

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -169,49 +169,6 @@ public function testPushWithDelay(): void
169169
]);
170170
}
171171

172-
/**
173-
* @throws ReflectionException
174-
*/
175-
public function testPushAndPopWithDelay(): void
176-
{
177-
Time::setTestNow('2023-12-29 14:15:16');
178-
179-
$handler = new DatabaseHandler($this->config);
180-
$result = $handler->setDelay(MINUTE)->push('queue-delay', 'success', ['key1' => 'value1']);
181-
182-
$this->assertTrue($result);
183-
$this->seeInDatabase('queue_jobs', [
184-
'queue' => 'queue-delay',
185-
'payload' => json_encode(['job' => 'success', 'data' => ['key1' => 'value1']]),
186-
'available_at' => 1703859376,
187-
]);
188-
189-
$result = $handler->push('queue-delay', 'success', ['key2' => 'value2']);
190-
191-
$this->assertTrue($result);
192-
$this->seeInDatabase('queue_jobs', [
193-
'queue' => 'queue-delay',
194-
'payload' => json_encode(['job' => 'success', 'data' => ['key2' => 'value2']]),
195-
'available_at' => 1703859316,
196-
]);
197-
198-
$result = $handler->pop('queue-delay', ['default']);
199-
$this->assertInstanceOf(QueueJob::class, $result);
200-
$payload = ['job' => 'success', 'data' => ['key2' => 'value2']];
201-
$this->assertSame($payload, $result->payload);
202-
203-
$result = $handler->pop('queue-delay', ['default']);
204-
$this->assertNull($result);
205-
206-
// add 1 minute
207-
Time::setTestNow('2023-12-29 14:16:16');
208-
209-
$result = $handler->pop('queue-delay', ['default']);
210-
$this->assertInstanceOf(QueueJob::class, $result);
211-
$payload = ['job' => 'success', 'data' => ['key1' => 'value1']];
212-
$this->assertSame($payload, $result->payload);
213-
}
214-
215172
public function testPushWithDelayException(): void
216173
{
217174
$this->expectException(QueueException::class);

tests/PredisHandlerTest.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -123,39 +123,6 @@ public function testPushWithDelay(): void
123123
$this->assertSame(['key' => 'value'], $queueJob->payload['data']);
124124
}
125125

126-
/**
127-
* @throws ReflectionException
128-
*/
129-
public function testPushAndPopWithDelay(): void
130-
{
131-
Time::setTestNow('2023-12-29 14:15:16');
132-
133-
$handler = new PredisHandler($this->config);
134-
$result = $handler->setDelay(MINUTE)->push('queue-delay', 'success', ['key1' => 'value1']);
135-
136-
$this->assertTrue($result);
137-
138-
$result = $handler->push('queue-delay', 'success', ['key2' => 'value2']);
139-
140-
$this->assertTrue($result);
141-
142-
$result = $handler->pop('queue-delay', ['default']);
143-
$this->assertInstanceOf(QueueJob::class, $result);
144-
$payload = ['job' => 'success', 'data' => ['key2' => 'value2']];
145-
$this->assertSame($payload, $result->payload);
146-
147-
$result = $handler->pop('queue-delay', ['default']);
148-
$this->assertNull($result);
149-
150-
// add 1 minute
151-
Time::setTestNow('2023-12-29 14:16:16');
152-
153-
$result = $handler->pop('queue-delay', ['default']);
154-
$this->assertInstanceOf(QueueJob::class, $result);
155-
$payload = ['job' => 'success', 'data' => ['key1' => 'value1']];
156-
$this->assertSame($payload, $result->payload);
157-
}
158-
159126
public function testPushException(): void
160127
{
161128
$this->expectException(QueueException::class);

tests/PushAndPopWithDelayTest.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of CodeIgniter Queue.
7+
*
8+
* (c) CodeIgniter Foundation <[email protected]>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace Tests;
15+
16+
use CodeIgniter\I18n\Time;
17+
use CodeIgniter\Queue\Entities\QueueJob;
18+
use CodeIgniter\Test\ReflectionHelper;
19+
use PHPUnit\Framework\Attributes\DataProvider;
20+
use Tests\Support\Config\Queue as QueueConfig;
21+
use Tests\Support\Database\Seeds\TestDatabaseQueueSeeder;
22+
use Tests\Support\TestCase;
23+
24+
/**
25+
* @internal
26+
*/
27+
final class PushAndPopWithDelayTest extends TestCase
28+
{
29+
use ReflectionHelper;
30+
31+
protected $seed = TestDatabaseQueueSeeder::class;
32+
private QueueConfig $config;
33+
34+
protected function setUp(): void
35+
{
36+
parent::setUp();
37+
38+
$this->config = config(QueueConfig::class);
39+
}
40+
41+
public static function handlerProvider(): iterable
42+
{
43+
return [
44+
[
45+
'database', // name
46+
'CodeIgniter\Queue\Handlers\DatabaseHandler', // class
47+
],
48+
[
49+
'redis',
50+
'CodeIgniter\Queue\Handlers\RedisHandler',
51+
],
52+
[
53+
'predis',
54+
'CodeIgniter\Queue\Handlers\PredisHandler',
55+
],
56+
];
57+
}
58+
59+
#[DataProvider('handlerProvider')]
60+
public function testPushAndPopWithDelay(string $name, string $class): void
61+
{
62+
Time::setTestNow('2023-12-29 14:15:16');
63+
64+
$handler = new $class($this->config);
65+
$result = $handler->setDelay(MINUTE)->push('queue-delay', 'success', ['key1' => 'value1']);
66+
67+
$this->assertTrue($result);
68+
69+
$result = $handler->push('queue-delay', 'success', ['key2' => 'value2']);
70+
71+
$this->assertTrue($result);
72+
73+
if ($name === 'database') {
74+
$this->seeInDatabase('queue_jobs', [
75+
'queue' => 'queue-delay',
76+
'payload' => json_encode(['job' => 'success', 'data' => ['key1' => 'value1']]),
77+
'available_at' => 1703859376,
78+
]);
79+
80+
$this->seeInDatabase('queue_jobs', [
81+
'queue' => 'queue-delay',
82+
'payload' => json_encode(['job' => 'success', 'data' => ['key2' => 'value2']]),
83+
'available_at' => 1703859316,
84+
]);
85+
}
86+
87+
$result = $handler->pop('queue-delay', ['default']);
88+
$this->assertInstanceOf(QueueJob::class, $result);
89+
$payload = ['job' => 'success', 'data' => ['key2' => 'value2']];
90+
$this->assertSame($payload, $result->payload);
91+
92+
$result = $handler->pop('queue-delay', ['default']);
93+
$this->assertNull($result);
94+
95+
// add 1 minute
96+
Time::setTestNow('2023-12-29 14:16:16');
97+
98+
$result = $handler->pop('queue-delay', ['default']);
99+
$this->assertInstanceOf(QueueJob::class, $result);
100+
$payload = ['job' => 'success', 'data' => ['key1' => 'value1']];
101+
$this->assertSame($payload, $result->payload);
102+
}
103+
}

tests/RedisHandlerTest.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -117,39 +117,6 @@ public function testPushWithDelay(): void
117117
$this->assertSame(['key' => 'value'], $queueJob->payload['data']);
118118
}
119119

120-
/**
121-
* @throws ReflectionException
122-
*/
123-
public function testPushAndPopWithDelay(): void
124-
{
125-
Time::setTestNow('2023-12-29 14:15:16');
126-
127-
$handler = new RedisHandler($this->config);
128-
$result = $handler->setDelay(MINUTE)->push('queue-delay', 'success', ['key1' => 'value1']);
129-
130-
$this->assertTrue($result);
131-
132-
$result = $handler->push('queue-delay', 'success', ['key2' => 'value2']);
133-
134-
$this->assertTrue($result);
135-
136-
$result = $handler->pop('queue-delay', ['default']);
137-
$this->assertInstanceOf(QueueJob::class, $result);
138-
$payload = ['job' => 'success', 'data' => ['key2' => 'value2']];
139-
$this->assertSame($payload, $result->payload);
140-
141-
$result = $handler->pop('queue-delay', ['default']);
142-
$this->assertNull($result);
143-
144-
// add 1 minute
145-
Time::setTestNow('2023-12-29 14:16:16');
146-
147-
$result = $handler->pop('queue-delay', ['default']);
148-
$this->assertInstanceOf(QueueJob::class, $result);
149-
$payload = ['job' => 'success', 'data' => ['key1' => 'value1']];
150-
$this->assertSame($payload, $result->payload);
151-
}
152-
153120
public function testPushException(): void
154121
{
155122
$this->expectException(QueueException::class);

0 commit comments

Comments
 (0)