Code Duplication    Length = 72-74 lines in 2 locations

Tests/RabbitMQ/JobManagerTest.php 1 location

@@ 182-253 (lines=72) @@
179
        );
180
    }
181
182
    public function testSaveJob()
183
    {
184
        // Make sure a job proper type
185
        $failed = false;
186
        try {
187
            $job = new Job();
188
            self::$jobManager->save($job);
189
            $failed = true;
190
        } catch (\Exception $exception) {
191
            self::assertTrue(true);
192
        }
193
        self::assertFalse($failed);
194
195
        $job = new self::$jobClass(self::$worker, false, null);
196
        try {
197
            $job->setPriority(256)->fibonacci(1);
198
            $failed = true;
199
        } catch (\Exception $exception) {
200
            self::assertTrue(true);
201
        }
202
        self::assertFalse($failed);
203
204
        $job = new self::$jobClass(self::$worker, false, null);
205
        $job->setPriority(100)->fibonacci(1);
206
        self::assertNotNull($job->getId(), 'Job id should be generated');
207
208
        $jobInQueue = self::$jobManager->getJob();
209
        self::assertNotNull($jobInQueue, 'There should be a job.');
210
        self::$jobManager->saveHistory($jobInQueue);
211
212
        $job = new self::$jobClass(self::$worker, false, null);
213
        $job->fibonacci(1);
214
        self::assertNotNull($job->getId(), 'Job id should be generated');
215
216
        $failed = false;
217
        try {
218
            self::$jobManager->getJob('fibonacci');
219
            $failed = true;
220
        } catch (\Exception $exception) {
221
            self::assertTrue(true);
222
        }
223
        self::assertFalse($failed);
224
225
        $failed = false;
226
        try {
227
            self::$jobManager->getJob(null, 'fibonacci');
228
            $failed = true;
229
        } catch (\Exception $exception) {
230
            self::assertTrue(true);
231
        }
232
        self::assertFalse($failed);
233
234
        $jobInQueue = self::$jobManager->getJob();
235
        self::assertNotNull($jobInQueue, 'There should be a job.');
236
        self::assertEquals(
237
            $job->getId(),
238
            $jobInQueue->getId(),
239
            'Job id returned by manager should be the same'
240
        );
241
242
        $job->setStatus(BaseJob::STATUS_SUCCESS);
243
        $badJob = new Job();
244
        $failed = false;
245
        try {
246
            self::$jobManager->saveHistory($badJob);
247
            $failed = true;
248
        } catch (\Exception $exception) {
249
            self::assertTrue(true);
250
        }
251
        self::assertFalse($failed);
252
        self::$jobManager->saveHistory($jobInQueue);
253
    }
254
255
    protected static function drainQueue($channel)
256
    {

Tests/Redis/JobManagerTest.php 1 location

@@ 198-271 (lines=74) @@
195
        $this->drain();
196
    }
197
198
    public function testSaveJob()
199
    {
200
        // Make sure a job proper type
201
        $failed = false;
202
        try {
203
            $job = new Job();
204
            self::$jobManager->save($job);
205
            $failed = true;
206
        } catch (\Exception $exception) {
207
            self::assertTrue(true);
208
        }
209
        self::assertFalse($failed);
210
211
        if (null !== self::$jobManager->getMaxPriority()) {
212
            $job = new self::$jobClass(self::$worker, false, null);
213
            try {
214
                $job->setPriority(256)->fibonacci(1);
215
                $failed = true;
216
            } catch (\Exception $exception) {
217
                self::assertTrue(true);
218
            }
219
            self::assertFalse($failed);
220
221
            $job = new self::$jobClass(self::$worker, false, null);
222
            $job->setPriority(100)->fibonacci(1);
223
            self::assertNotNull($job->getId(), 'Job id should be generated');
224
225
            $jobInQueue = self::$jobManager->getJob();
226
            self::assertNotNull($jobInQueue, 'There should be a job.');
227
            self::$jobManager->saveHistory($jobInQueue);
228
        }
229
230
        $job = new self::$jobClass(self::$worker, false, null);
231
        $job->fibonacci(1);
232
        self::assertNotNull($job->getId(), 'Job id should be generated');
233
234
        $failed = false;
235
        try {
236
            self::$jobManager->getJob('fibonacci');
237
            $failed = true;
238
        } catch (\Exception $exception) {
239
            self::assertTrue(true);
240
        }
241
        self::assertFalse($failed);
242
243
        $failed = false;
244
        try {
245
            self::$jobManager->getJob(null, 'fibonacci');
246
            $failed = true;
247
        } catch (\Exception $exception) {
248
            self::assertTrue(true);
249
        }
250
        self::assertFalse($failed);
251
252
        $jobInQueue = self::$jobManager->getJob();
253
        self::assertNotNull($jobInQueue, 'There should be a job.');
254
        self::assertEquals(
255
            $job->getId(),
256
            $jobInQueue->getId(),
257
            'Job id returned by manager should be the same'
258
        );
259
260
        $job->setStatus(BaseJob::STATUS_SUCCESS);
261
        $badJob = new Job();
262
        $failed = false;
263
        try {
264
            self::$jobManager->saveHistory($badJob);
265
            $failed = true;
266
        } catch (\Exception $exception) {
267
            self::assertTrue(true);
268
        }
269
        self::assertFalse($failed);
270
        self::$jobManager->saveHistory($jobInQueue);
271
    }
272
273
    public function testGetStatus()
274
    {