Completed
Pull Request — master (#30)
by Matthew
23:29 queued 08:10
created

DoctrineJobManagerTest::testArchiveAllJobs()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 56
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 9.7251
c 0
b 0
f 0
cc 3
eloc 39
nc 4
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Dtc\QueueBundle\Tests\Doctrine;
4
5
use Doctrine\ODM\MongoDB\DocumentManager;
6
use Doctrine\ORM\EntityManager;
7
use Dtc\QueueBundle\Doctrine\DoctrineJobManager;
8
use Dtc\QueueBundle\Doctrine\DtcQueueListener;
9
use Dtc\QueueBundle\Manager\StallableJobManager;
10
use Dtc\QueueBundle\Model\BaseJob;
11
use Dtc\QueueBundle\Model\Job;
12
use Dtc\QueueBundle\Model\RetryableJob;
13
use Dtc\QueueBundle\Tests\Manager\AutoRetryTrait;
14
use Dtc\QueueBundle\Tests\Manager\PriorityTestTrait;
15
use Dtc\QueueBundle\Model\StallableJob;
16
use Dtc\QueueBundle\Tests\FibonacciWorker;
17
use Dtc\QueueBundle\Tests\Manager\BaseJobManagerTest;
18
use Dtc\QueueBundle\ODM\JobManager;
19
use Dtc\QueueBundle\Tests\Manager\RetryableTrait;
20
use Dtc\QueueBundle\Tests\ORM\JobManagerTest;
21
use Dtc\QueueBundle\Util\Util;
22
use Symfony\Component\DependencyInjection\Container;
23
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
24
25
/**
26
 * @author David
27
 *
28
 * This test requires local mongodb running
29
 */
30
abstract class DoctrineJobManagerTest extends BaseJobManagerTest
31
{
32
    use PriorityTestTrait;
33
    use AutoRetryTrait;
34
    use RetryableTrait;
35
36
    protected static $dtcQueueListener;
37
38
    /** @var DocumentManager|EntityManager */
39
    protected static $objectManager;
40
    protected static $objectName;
41
    protected static $archiveObjectName;
42
    protected static $runClass;
43
    protected static $runArchiveClass;
44
    protected static $jobTimingClass;
45
    protected static $jobManagerClass;
46
    protected static $runManagerClass;
47
    protected static $jobTimingManagerClass;
48
    public static $runManager;
49
50
    public static function setUpBeforeClass()
51
    {
52
        self::$jobTimingManager = new self::$jobTimingManagerClass(self::$objectManager, self::$jobTimingClass, true);
53
        self::$runManager = new self::$runManagerClass(self::$objectManager, self::$runClass, self::$runArchiveClass);
54
        self::$jobManager = new self::$jobManagerClass(self::$runManager, self::$jobTimingManager, self::$objectManager, self::$objectName, self::$archiveObjectName);
55
        self::$jobManager->setMaxPriority(255);
56
57
        self::assertEquals(255, self::$jobManager->getMaxPriority());
58
        self::assertEquals(JobManager::PRIORITY_DESC, self::$jobManager->getPriorityDirection());
59
        self::$jobManager->setPriorityDirection(JobManager::PRIORITY_ASC);
60
        self::assertEquals(JobManager::PRIORITY_ASC, self::$jobManager->getPriorityDirection());
61
        self::$jobManager->setPriorityDirection(JobManager::PRIORITY_DESC);
62
63
        /** @var DoctrineJobManager $jobManager */
64
        $jobManager = self::$jobManager;
65
66
        $parameters = new ParameterBag();
67
68
        $container = new Container($parameters);
69
        $container->set('dtc_queue.job_manager', $jobManager);
70
        $container->set('dtc_queue.run_manager', self::$runManager);
71
72
        self::$dtcQueueListener = new DtcQueueListener(self::$jobManager->getJobArchiveClass(), self::$runManager->getRunArchiveClass());
73
        self::$objectManager->getEventManager()->addEventListener('preUpdate', self::$dtcQueueListener);
74
        self::$objectManager->getEventManager()->addEventListener('prePersist', self::$dtcQueueListener);
75
        self::$objectManager->getEventManager()->addEventListener('preRemove', self::$dtcQueueListener);
76
77
        self::$worker = new FibonacciWorker();
78
79
        parent::setUpBeforeClass();
80
    }
81
82
    public static function tearDownAfterClass()
83
    {
84
        self::$objectManager->getEventManager()->removeEventListener('preUpdate', self::$dtcQueueListener);
85
        self::$objectManager->getEventManager()->removeEventListener('prePersist', self::$dtcQueueListener);
86
        self::$objectManager->getEventManager()->removeEventListener('preRemove', self::$dtcQueueListener);
87
        parent::tearDownAfterClass();
88
    }
89
90
    public function testOrdering()
91
    {
92
        // priority when at
93
        /** @var DoctrineJobManager $jobManager */
94
        $jobManager = self::$jobManager;
95
96
        $time1 = time() - 2;
97
        $dateTime1 = new \DateTime("@$time1");
98
99
        $time2 = time();
100
        $dateTime2 = new \DateTime("@$time2");
101
102
        /** @var Job $job */
103
        $job = new static::$jobClass(static::$worker, false, null);
104
        $job->fibonacci(1);
0 ignored issues
show
Documentation Bug introduced by
The method fibonacci does not exist on object<Dtc\QueueBundle\Model\Job>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
105
        $job->setWhenAt($dateTime1);
106
        $job->setPriority(3);
107
        $id = $job->getId();
108
109
        $job2 = new static::$jobClass(static::$worker, false, null);
110
        $job2->setPriority(1);
111
        $job2->setWhenAt($dateTime2);
112
        $job2->fibonacci(1);
113
        $id2 = $job2->getId();
114
115
        $job3 = new static::$jobClass(static::$worker, false, null);
116
        $job3->setPriority(1);
117
        $job3->setWhenAt($dateTime1);
118
        $job3->fibonacci(1);
119
        $id3 = $job3->getId();
120
121
        $job4 = new static::$jobClass(static::$worker, false, null);
122
        $job4->setPriority(1);
123
        $job4->setWhenAt($dateTime2);
124
        $job4->fibonacci(1);
125
        $id4 = $job4->getId();
126
127
        $nextJob = $jobManager->getJob();
128
        static::assertEquals($id3, $nextJob->getId());
129
        $nextNextJob = $jobManager->getJob();
130
        $nextNextId = $nextNextJob->getId();
131
        static::assertTrue($id4 == $nextNextId || $id2 == $nextNextId, "$nextNextId not equals $id4 or $id2, could be $id or $id3");
132
133
        static::assertNotNull($jobManager->getJob());
134
        static::assertNotNull($jobManager->getJob());
135
136
        // non-priority when at
137
        $time1 = time() - 2;
138
        $dateTime1 = new \DateTime("@$time1");
139
140
        $time2 = time();
141
        $dateTime2 = new \DateTime("@$time2");
142
143
        /** @var Job $job */
144
        $job = new static::$jobClass(static::$worker, false, null);
145
        $job->fibonacci(1);
0 ignored issues
show
Documentation Bug introduced by
The method fibonacci does not exist on object<Dtc\QueueBundle\Model\Job>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
146
        $job->setWhenAt($dateTime1);
147
        $job->setPriority(3);
148
        $id = $job->getId();
149
150
        $job2 = new static::$jobClass(static::$worker, false, null);
151
        $job2->setPriority(1);
152
        $job2->setWhenAt($dateTime2);
153
        $job2->fibonacci(1);
154
155
        $job3 = new static::$jobClass(static::$worker, false, null);
156
        $job3->setPriority(1);
157
        $job3->setWhenAt($dateTime2);
158
        $job3->fibonacci(1);
159
160
        $job4 = new static::$jobClass(static::$worker, false, null);
161
        $job4->setPriority(1);
162
        $job4->setWhenAt($dateTime2);
163
        $job4->fibonacci(1);
164
165
        $nextJob = $jobManager->getJob(null, null, false);
166
        static::assertEquals($id, $nextJob->getId());
167
        static::assertNotNull($jobManager->getJob());
168
        static::assertNotNull($jobManager->getJob());
169
        static::assertNotNull($jobManager->getJob());
170
    }
171
172
    public function getJobBy()
173
    {
174
        /** @var DoctrineJobManager $jobManager */
175
        $jobManager = self::$jobManager;
176
177
        /** @var Job $job */
178
        $job = new static::$jobClass(static::$worker, false, null);
179
        $job->fibonacci(1);
0 ignored issues
show
Documentation Bug introduced by
The method fibonacci does not exist on object<Dtc\QueueBundle\Model\Job>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
180
        $id = $job->getId();
181
        $nextJob = $jobManager->getJob('fibonacci', null);
182
        static::assertNotNull($nextJob);
183
        static::assertEquals($id, $nextJob->getId());
184
185
        /** @var Job $job */
186
        $job = new static::$jobClass(static::$worker, false, null);
187
        $job->fibonacci(1);
0 ignored issues
show
Documentation Bug introduced by
The method fibonacci does not exist on object<Dtc\QueueBundle\Model\Job>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
188
        $id = $job->getId();
189
        $nextJob = $jobManager->getJob('fibonacci', 'fibonacci');
190
        static::assertNotNull($nextJob);
191
        static::assertEquals($id, $nextJob->getId());
192
193
        /** @var Job $job */
194
        $job = new static::$jobClass(static::$worker, false, null);
195
        $job->fibonacci(1);
0 ignored issues
show
Documentation Bug introduced by
The method fibonacci does not exist on object<Dtc\QueueBundle\Model\Job>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
196
        $id = $job->getId();
197
        $nextJob = $jobManager->getJob(null, 'fibonacci');
198
        static::assertNotNull($nextJob);
199
        static::assertEquals($id, $nextJob->getId());
200
201
        /** @var Job $job */
202
        $job = new static::$jobClass(static::$worker, false, null);
203
        $job->fibonacci(1);
0 ignored issues
show
Documentation Bug introduced by
The method fibonacci does not exist on object<Dtc\QueueBundle\Model\Job>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
204
        $id = $job->getId();
205
        $nextJob = $jobManager->getJob(null, 'fibonaccia');
206
        static::assertNull($nextJob);
207
        $nextJob = $jobManager->getJob('fibonacci', 'fibonaccia');
208
        static::assertNull($nextJob);
209
        $nextJob = $jobManager->getJob('fibonaccii', 'fibonacci');
210
        static::assertNull($nextJob);
211
        $nextJob = $jobManager->getJob();
212
        static::assertNotNull($nextJob);
213
        static::assertEquals($id, $nextJob->getId());
214
    }
215
216
    public function testDeleteJob()
217
    {
218
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
219
        $jobManager = self::$jobManager;
220
221
        /** @var Job $job */
222
        $job = $this->getJob();
223
        $id = $job->getId();
224
        $jobManager->deleteJob($job);
225
226
        $nextJob = $jobManager->getJob(null, null, true, 123);
227
        self::assertNull($nextJob, "Shouldn't be any jobs left in queue");
228
229
        $archiveObjectName = $jobManager->getJobArchiveClass();
230
231
        self::assertNotNull($id);
232
        $archiveRepository = $jobManager->getObjectManager()->getRepository($archiveObjectName);
233
        $result = $archiveRepository->find($id);
234
        self::assertNotNull($result);
235
        self::assertEquals($id, $result->getId());
236
    }
237
238
    public function testCountLiveJobs()
239
    {
240
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
241
        $jobManager = self::$jobManager;
242
243
        while ($job = $jobManager->getJob()) {
244
            $jobManager->deleteJob($job);
245
        }
246
247
        $this->getJob();
248
249
        $count = $jobManager->countLiveJobs();
250
        self::assertEquals(1, $count);
251
252
        $this->getJob();
253
254
        $count = $jobManager->countLiveJobs();
255
        self::assertEquals(2, $count);
256
257
        $this->getJob();
258
259
        $count = $jobManager->countLiveJobs();
260
        self::assertEquals(3, $count);
261
262
        $count = $jobManager->countLiveJobs('asdf');
263
        self::assertEquals(0, $count);
264
265
        $count = $jobManager->countLiveJobs('fibonacci');
266
        self::assertEquals(3, $count);
267
268
        $count = $jobManager->countLiveJobs('fibonacci', 'test');
269
        self::assertEquals(0, $count);
270
271
        $count = $jobManager->countLiveJobs('fibonacci', 'fibonacci');
272
        self::assertEquals(3, $count);
273
274
        while ($job = $jobManager->getJob()) {
275
            $jobManager->deleteJob($job);
276
        }
277
    }
278
279
    public function testArchiveAllJobs()
280
    {
281
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
282
        $jobManager = self::$jobManager;
283
284
        while ($job = $jobManager->getJob()) {
285
            $jobManager->deleteJob($job);
286
        }
287
288
        $this->getJob();
289
290
        $count = $jobManager->countLiveJobs();
291
        $archiveCount = $this->runCountQuery($jobManager->getJobArchiveClass());
292
        self::assertEquals(1, $count);
293
        $allCount = $this->runCountQuery($jobManager->getJobClass());
294
        $counter = 0;
295
        $countJobs = function($count) use (&$counter) {
296
            $counter += $count;
297
        };
298
        $jobManager->archiveAllJobs(null, null, $countJobs);
299
        self::assertEquals(0, $jobManager->countLiveJobs());
300
        self::assertEquals($allCount - 1, $this->runCountQuery($jobManager->getJobClass()));
301
        self::assertEquals($archiveCount + 1, $this->runCountQuery($jobManager->getJobArchiveClass()));
302
        self::assertEquals(1, $counter);
303
304
        $this->getJob();
305
        $this->getJob();
306
307
        $count = $jobManager->countLiveJobs();
308
        self::assertEquals(2, $count);
309
        $archiveCount = $this->runCountQuery($jobManager->getJobArchiveClass());
310
        $counter = 0;
311
        $jobManager->archiveAllJobs('fibonacci', null, $countJobs);
312
        self::assertEquals(0, $jobManager->countLiveJobs());
313
        self::assertEquals(2, $counter);
314
        self::assertEquals($archiveCount + 2, $this->runCountQuery($jobManager->getJobArchiveClass()));
315
316
        $this->getJob();
317
        $this->getJob();
318
319
        $count = $jobManager->countLiveJobs();
320
        self::assertEquals(2, $count);
321
322
        $jobManager->archiveAllJobs('fibonacc', null, $countJobs);
323
        self::assertEquals(2, $jobManager->countLiveJobs());
324
325
        $jobManager->archiveAllJobs('fibonacci', 'fibo', $countJobs);
326
        self::assertEquals(2, $jobManager->countLiveJobs());
327
328
        $jobManager->archiveAllJobs('fibonacci', 'fibonacci', $countJobs);
329
        self::assertEquals(0, $jobManager->countLiveJobs());
330
331
        while ($job = $jobManager->getJob()) {
332
            $jobManager->deleteJob($job);
333
        }
334
    }
335
336
    abstract protected function runCountQuery($class);
337
338
    public function testResetExceptionJobs()
339
    {
340
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
341
        $jobManager = self::$jobManager;
342
343
        $id = $this->createExceptionJob();
344
        $archiveObjectName = $jobManager->getJobArchiveClass();
345
        $objectManager = $jobManager->getObjectManager();
346
        $archiveRepository = $objectManager->getRepository($archiveObjectName);
347
        $result = $archiveRepository->find($id);
348
        self::assertNotNull($result);
349
        self::assertEquals(BaseJob::STATUS_EXCEPTION, $result->getStatus());
350
        if ($objectManager instanceof EntityManager) {
351
            JobManagerTest::createObjectManager();
352
            $jobManager = new self::$jobManagerClass(self::$runManager, self::$jobTimingManager, self::$objectManager, self::$objectName, self::$archiveObjectName);
353
            $jobManager->getObjectManager()->clear();
354
            $objectManager = $jobManager->getObjectManager();
355
        }
356
357
        $count = $jobManager->resetExceptionJobs();
358
359
        self::assertEquals(1, $count);
360
        $repository = $jobManager->getRepository();
361
        $job = $repository->find($id);
362
363
        self::assertNotNull($job);
364
        self::assertEquals(BaseJob::STATUS_NEW, $job->getStatus());
365
        self::assertNull($job->getStartedAt());
366
        self::assertNull($job->getFinishedAt());
367
        self::assertNull($job->getElapsed());
368
        self::assertNull($job->getMessage());
369
370
        $objectManager->remove($job);
371
        $objectManager->flush();
372
373
        $id = $this->createExceptionJob();
374
        $archiveObjectName = $jobManager->getJobArchiveClass();
375
        $objectManager = $jobManager->getObjectManager();
376
        $archiveRepository = $objectManager->getRepository($archiveObjectName);
377
        $result = $archiveRepository->find($id);
378
        $result->setMaxRetries(10);
379
        $result->setRetries(10);
380
        $objectManager->persist($result);
381
        $objectManager->flush();
382
        $count = $jobManager->resetExceptionJobs();
383
        self::assertEquals(0, $count);
384
        $job = $repository->find($id);
385
        self::assertNull($job);
386
        $job = $archiveRepository->find($id);
387
        self::assertNotNull($job);
388
        $objectManager->remove($job);
389
        $objectManager->flush();
390
    }
391
392
    protected function createExceptionJob()
393
    {
394
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
395
        $jobManager = self::$jobManager;
396
397
        /** @var Job $job */
398
        $job = $this->getJob();
399
        $id = $job->getId();
400
        $jobManager->deleteJob($job);
401
402
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
403
        $archiveObjectName = $jobManager->getJobArchiveClass();
404
405
        $objectManager = $jobManager->getObjectManager();
406
407
        $archiveRepository = $objectManager->getRepository($archiveObjectName);
408
        $result = $archiveRepository->find($id);
409
        self::assertNotNull($result);
410
        self::assertEquals($id, $result->getId());
411
412
        $result->setStatus(BaseJob::STATUS_EXCEPTION);
413
        $result->setStartedAt(Util::getMicrotimeDateTime());
414
        $result->setFinishedAt(new \DateTime());
415
        $result->setElapsed(12345);
416
        $result->setMessage('soomething');
417
        $objectManager->persist($result);
418
        $objectManager->flush();
419
420
        return $id;
421
    }
422
423
    /**
424
     * @param bool $endRun
425
     * @param bool $setId
426
     *
427
     * @return mixed
428
     */
429
    public function createStalledJob($endRun, $setId)
430
    {
431
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
432
        $jobManager = self::$jobManager;
433
434
        $job = new self::$jobClass(self::$worker, false, null);
435
        $job->fibonacci(1);
436
        self::assertNotNull($job->getId(), 'Job id should be generated');
437
        $job->setStatus(BaseJob::STATUS_RUNNING);
438
        $time = time();
439
        $date = new \DateTime("@$time");
440
        $job->setStartedAt($date);
441
        $id = $job->getId();
442
        $job = $jobManager->getRepository()->find($id);
443
444
        self::assertNotNull($job);
445
446
        $runClass = self::$runManager->getRunClass();
447
448
        $objectManager = $jobManager->getObjectManager();
449
        $run = new $runClass();
450
        $run->setLastHeartbeatAt(new \DateTime());
451
        if ($setId) {
452
            $run->setCurrentJobId($job->getId());
453
        }
454
        $objectManager->persist($run);
455
        $objectManager->flush();
456
        $runId = $run->getId();
457
        self::assertNotNull($runId);
458
        $job->setRunId($runId);
459
        $objectManager->persist($job);
460
        $objectManager->flush();
461
        if ($endRun) {
462
            $objectManager->remove($run);
463
            $objectManager->flush();
464
        }
465
        $id = $job->getId();
466
        $job = $jobManager->getRepository()->find($id);
467
468
        self::assertNotNull($job);
469
470
        if ($endRun) {
471
            $archivedRun = $objectManager->getRepository(self::$runManager->getRunArchiveClass())->find($runId);
472
473
            $minusTime = $time - (DoctrineJobManager::STALLED_SECONDS + 1);
474
            $archivedRun->setEndedAt(new \DateTime("@$minusTime"));
475
476
            $objectManager->persist($archivedRun);
477
            $objectManager->flush();
478
        }
479
        $id = $job->getId();
480
481
        return $id;
482
    }
483
484
    public function testResetStalledJobs()
485
    {
486
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
487
        $jobManager = self::$jobManager;
488
        $id = $this->createStalledJob(true, false);
489
490
        $objectManager = $jobManager->getObjectManager();
491
        $count = $jobManager->resetStalledJobs();
492
        self::assertEquals(1, $count);
493
494
        $job = $jobManager->getRepository()->find($id);
495
496
        self::assertNotNull($job);
497
        self::assertEquals(BaseJob::STATUS_NEW, $job->getStatus());
498
        self::assertNull($job->getStartedAt());
499
        self::assertNull($job->getFinishedAt());
500
        self::assertNull($job->getElapsed());
501
        self::assertNull($job->getMessage());
502
        self::assertEquals(1, $job->getStalls());
503
504
        $objectManager->remove($job);
505
        $objectManager->flush();
506
507
        $jobManager = self::$jobManager;
508
        $id = $this->createStalledJob(true, true);
509
510
        $objectManager = $jobManager->getObjectManager();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
511
        $count = $jobManager->resetStalledJobs();
512
        self::assertEquals(1, $count);
513
514
        $job = $jobManager->getRepository()->find($id);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getRepository() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
515
516
        self::assertNotNull($job);
517
        $objectManager->remove($job);
518
        $objectManager->flush();
519
520
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
521
        $id = $this->createStalledJob(false, false);
522
523
        $objectManager = $jobManager->getObjectManager();
524
        $count = $jobManager->resetStalledJobs();
525
        self::assertEquals(1, $count);
526
527
        $job = $jobManager->getRepository()->find($id);
528
529
        self::assertNotNull($job);
530
        self::assertEquals(BaseJob::STATUS_NEW, $job->getStatus());
531
        self::assertNull($job->getStartedAt());
532
        self::assertNull($job->getFinishedAt());
533
        self::assertNull($job->getElapsed());
534
        self::assertNull($job->getMessage());
535
        self::assertEquals(1, $job->getStalls());
536
537
        $objectManager->remove($job);
538
        $objectManager->flush();
539
540
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
541
        $jobManager = self::$jobManager;
542
        $id = $this->createStalledJob(false, true);
543
544
        $job = $jobManager->getRepository()->find($id);
545
        $objectManager = $jobManager->getObjectManager();
546
        $count = $jobManager->resetStalledJobs();
547
        self::assertEquals(0, $count);
548
549
        $objectManager->remove($job);
550
        $objectManager->flush();
551
552
        $id = $this->createStalledJob(true, false);
553
        $job = $jobManager->getRepository()->find($id);
554
        $job->setMaxRetries(10);
555
        $job->setRetries(10);
556
        $objectManager->persist($job);
557
        $objectManager->flush();
558
559
        $count = $jobManager->resetStalledJobs();
560
        self::assertEquals(0, $count);
561
        $job = $jobManager->getRepository()->find($id);
562
        self::assertNull($job);
563
        $job = $objectManager->getRepository($jobManager->getJobArchiveClass())->find($id);
564
        self::assertNotNull($job);
565
        $objectManager->remove($job);
566
        $objectManager->flush();
567
568
        $id = $this->createStalledJob(true, false);
569
        $job = $jobManager->getRepository()->find($id);
570
        $job->setMaxStalls(10);
571
        $job->setStalls(10);
572
        $objectManager->persist($job);
573
        $objectManager->flush();
574
575
        $count = $jobManager->resetStalledJobs();
576
        self::assertEquals(0, $count);
577
        $job = $jobManager->getRepository()->find($id);
578
        self::assertNull($job);
579
        $job = $objectManager->getRepository($jobManager->getJobArchiveClass())->find($id);
580
        self::assertNotNull($job);
581
        $objectManager->remove($job);
582
        $objectManager->flush();
583
    }
584
585
    public function testpruneExceptionJobs()
586
    {
587
        $job = $this->getJob();
588
        $id = $job->getId();
589
590
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
591
        $jobManager = self::$jobManager;
592
        $jobManager->deleteJob($job);
593
        $archiveObjectName = $jobManager->getJobArchiveClass();
594
595
        $objectManager = $jobManager->getObjectManager();
596
597
        $archiveRepository = $objectManager->getRepository($archiveObjectName);
598
        $result = $archiveRepository->find($id);
599
        self::assertNotNull($result);
600
        self::assertEquals($id, $result->getId());
601
602
        $result->setStatus(BaseJob::STATUS_EXCEPTION);
603
        $result->setStartedAt(new \DateTime());
604
        $result->setFinishedAt(new \DateTime());
605
        $result->setElapsed(12345);
606
        $result->setMessage('soomething');
607
        $objectManager->persist($result);
608
        $objectManager->flush();
609
610
        $count = $jobManager->pruneExceptionJobs('asdf');
611
        self::assertEquals(0, $count);
612
        $count = $jobManager->pruneExceptionJobs(null, 'asdf');
613
        self::assertEquals(0, $count);
614
        $count = $jobManager->pruneExceptionJobs('fibonacci', 'asdf');
615
        self::assertEquals(0, $count);
616
        $count = $jobManager->pruneExceptionJobs('fibonacci', 'asdf');
617
        self::assertEquals(0, $count);
618
        $count = $jobManager->pruneExceptionJobs('fibonacci', 'fibonacci');
619
        self::assertEquals(1, $count);
620
        $repository = $jobManager->getRepository();
621
        $job = $repository->find($id);
622
        $objectManager->clear();
623
        self::assertNull($job);
624
        $archiveJob = $archiveRepository->find($id);
625
        self::assertNull($archiveJob);
626
627
        $job = $this->getJob();
628
        $id = $job->getId();
629
        $objectManager->remove($job);
630
        $objectManager->flush();
631
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
632
        $jobManager = self::$jobManager;
633
        $archiveObjectName = $jobManager->getJobArchiveClass();
634
635
        $objectManager = $jobManager->getObjectManager();
636
637
        $archiveRepository = $objectManager->getRepository($archiveObjectName);
638
        $result = $archiveRepository->find($id);
639
        self::assertNotNull($result);
640
        self::assertEquals($id, $result->getId());
641
642
        $result->setStatus(BaseJob::STATUS_EXCEPTION);
643
        $result->setStartedAt(new \DateTime());
644
        $result->setFinishedAt(new \DateTime());
645
        $result->setElapsed(12345);
646
        $result->setMessage('soomething');
647
        $objectManager->persist($result);
648
        $objectManager->flush();
649
650
        $job = $this->getJob();
651
        $id = $job->getId();
652
        $objectManager->remove($job);
653
        $objectManager->flush();
654
655
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
656
        $jobManager = self::$jobManager;
657
        $archiveObjectName = $jobManager->getJobArchiveClass();
658
        $objectManager = $jobManager->getObjectManager();
659
660
        $archiveRepository = $objectManager->getRepository($archiveObjectName);
661
        $result = $archiveRepository->find($id);
662
        self::assertNotNull($result);
663
        self::assertEquals($id, $result->getId());
664
665
        $result->setStatus(BaseJob::STATUS_EXCEPTION);
666
        $result->setStartedAt(new \DateTime());
667
        $result->setFinishedAt(new \DateTime());
668
        $result->setElapsed(12345);
669
        $result->setMessage('soomething');
670
        $objectManager->persist($result);
671
        $objectManager->flush();
672
        $count = $jobManager->pruneExceptionJobs();
673
        self::assertEquals(2, $count);
674
    }
675
676
    public function testPruneStalledJobs()
677
    {
678
        static::setUpBeforeClass();
679
680
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
681
        $jobManager = self::$jobManager;
682
683
        $job = new self::$jobClass(self::$worker, false, null);
684
        $job->fibonacci(1);
685
        self::assertNotNull($job->getId(), 'Job id should be generated');
686
        $job->setStatus(BaseJob::STATUS_RUNNING);
687
        $time = time();
688
        $date = new \DateTime("@$time");
689
        $job->setStartedAt($date);
690
        $id = $job->getId();
691
        $job = $jobManager->getRepository()->find($id);
692
693
        self::assertNotNull($job);
694
695
        $runClass = self::$runManager->getRunClass();
696
697
        $objectManager = $jobManager->getObjectManager();
698
        $run = new $runClass();
699
        $run->setLastHeartbeatAt(new \DateTime());
700
        $objectManager->persist($run);
701
        $objectManager->flush();
702
        $runId = $run->getId();
703
        self::assertNotNull($runId);
704
        $job->setRunId($runId);
705
        $objectManager->persist($job);
706
        $objectManager->flush();
707
        $objectManager->remove($run);
708
        $objectManager->flush();
709
        $id = $job->getId();
710
        $job = $jobManager->getRepository()->find($id);
711
712
        self::assertNotNull($job);
713
714
        $archivedRun = $objectManager->getRepository(self::$runManager->getRunArchiveClass())->find($runId);
715
716
        $minusTime = $time - (DoctrineJobManager::STALLED_SECONDS + 1);
717
        $archivedRun->setEndedAt(new \DateTime("@$minusTime"));
718
719
        $objectManager->persist($archivedRun);
720
        $objectManager->flush();
721
722
        $count = $jobManager->pruneStalledJobs('asdf');
723
        self::assertEquals(0, $count);
724
        $count = $jobManager->pruneStalledJobs(null, 'asdf');
725
        self::assertEquals(0, $count);
726
        $count = $jobManager->pruneStalledJobs('fibonacci', 'asdf');
727
        self::assertEquals(0, $count);
728
        $count = $jobManager->pruneStalledJobs('fibonacci', 'fibonacci');
729
        self::assertEquals(1, $count);
730
731
        $job = $jobManager->getRepository()->find($id);
732
733
        self::assertNull($job);
734
735
        $archivedJob = $jobManager->getObjectManager()->getRepository($jobManager->getJobArchiveClass())->find($id);
736
737
        self::assertNotNull($archivedJob);
738
        self::assertEquals(StallableJob::STATUS_STALLED, $archivedJob->getStatus());
739
        self::assertEquals(1, $archivedJob->getStalls());
740
        $objectManager->remove($archivedJob);
741
        $objectManager->flush();
742
743
        // multiple
744
745
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
746
        $jobManager = self::$jobManager;
747
748
        $job = new self::$jobClass(self::$worker, false, null);
749
        $job->fibonacci(1);
750
        self::assertNotNull($job->getId(), 'Job id should be generated');
751
        $job->setStatus(BaseJob::STATUS_RUNNING);
752
        $time = time();
753
        $date = new \DateTime("@$time");
754
        $job->setStartedAt($date);
755
        $id = $job->getId();
756
        $job = $jobManager->getRepository()->find($id);
757
758
        self::assertNotNull($job);
759
760
        $runClass = self::$runManager->getRunClass();
761
762
        $objectManager = $jobManager->getObjectManager();
763
        $run = new $runClass();
764
        $run->setLastHeartbeatAt(new \DateTime());
765
        $objectManager->persist($run);
766
        $objectManager->flush();
767
        $runId = $run->getId();
768
        self::assertNotNull($runId);
769
        $job->setRunId($runId);
770
        $objectManager->persist($job);
771
        $objectManager->flush();
772
        $objectManager->remove($run);
773
        $objectManager->flush();
774
        $id = $job->getId();
775
        $job = $jobManager->getRepository()->find($id);
776
777
        self::assertNotNull($job);
778
779
        $archivedRun = $objectManager->getRepository(self::$runManager->getRunArchiveClass())->find($runId);
780
781
        $minusTime = $time - (DoctrineJobManager::STALLED_SECONDS + 1);
782
        $archivedRun->setEndedAt(new \DateTime("@$minusTime"));
783
784
        $objectManager->persist($archivedRun);
785
        $objectManager->flush();
786
787
        $job = new self::$jobClass(self::$worker, false, null);
788
        $job->fibonacci(1);
789
        self::assertNotNull($job->getId(), 'Job id should be generated');
790
        $job->setStatus(BaseJob::STATUS_RUNNING);
791
        $time = time();
792
        $date = new \DateTime("@$time");
793
        $job->setStartedAt($date);
794
        $id = $job->getId();
795
        $job = $jobManager->getRepository()->find($id);
796
797
        self::assertNotNull($job);
798
799
        $runClass = self::$runManager->getRunClass();
800
801
        $objectManager = $jobManager->getObjectManager();
802
        $run = new $runClass();
803
        $run->setLastHeartbeatAt(new \DateTime());
804
        $objectManager->persist($run);
805
        $objectManager->flush();
806
        $runId = $run->getId();
807
        self::assertNotNull($runId);
808
        $job->setRunId($runId);
809
        $objectManager->persist($job);
810
        $objectManager->flush();
811
        $objectManager->remove($run);
812
        $objectManager->flush();
813
        $id = $job->getId();
814
        $job = $jobManager->getRepository()->find($id);
815
816
        self::assertNotNull($job);
817
818
        $archivedRun = $objectManager->getRepository(self::$runManager->getRunArchiveClass())->find($runId);
819
820
        $minusTime = $time - (DoctrineJobManager::STALLED_SECONDS + 1);
821
        $archivedRun->setEndedAt(new \DateTime("@$minusTime"));
822
823
        $objectManager->persist($archivedRun);
824
        $objectManager->flush();
825
        $count = $jobManager->pruneStalledJobs();
826
        self::assertEquals(2, $count);
827
    }
828
829
    public function testBatchJobs()
830
    {
831
        $jobs = self::$jobManager->getRepository()->findAll();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getRepository() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
832
        foreach ($jobs as $job) {
833
            self::$jobManager->getObjectManager()->remove($job);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
834
        }
835
        self::$jobManager->getObjectManager()->flush();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
836
        self::$jobManager->getObjectManager()->clear();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
837
838
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
839
        $worker = self::$worker;
840
        $job1 = $worker->later()->fibonacci(1);
841
        $job2 = $worker->batchLater()->fibonacci(1);
842
        self::assertEquals($job1, $job2);
843
844
        $jobs = self::$jobManager->getRepository()->findAll();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getRepository() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
845
        self::assertCount(1, $jobs);
846
        self::assertEquals($job1, $jobs[0]);
847
        self::assertNull($jobs[0]->getPriority());
848
        self::$jobManager->getObjectManager()->remove($jobs[0]);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
849
        self::$jobManager->getObjectManager()->flush();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
850
        self::$jobManager->getObjectManager()->clear();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
851
852
        $job1 = $worker->later()->fibonacci(1);
853
        self::assertNull($job1->getPriority());
854
        $job2 = $worker->batchLater()->setPriority(3)->fibonacci(1);
855
        self::assertEquals($job1, $job2);
856
        self::assertNotNull($job2->getPriority());
857
858
        $jobs = self::$jobManager->getRepository()->findAll();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getRepository() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
859
        self::assertCount(1, $jobs);
860
        self::assertEquals($job1, $jobs[0]);
861
        self::assertNotNull($jobs[0]->getPriority());
862
863
        // Not
864
        $jobs = self::$jobManager->getRepository()->findAll();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getRepository() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
865
        foreach ($jobs as $job) {
866
            self::$jobManager->getObjectManager()->remove($job);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
867
        }
868
        self::$jobManager->getObjectManager()->remove($jobs[0]);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
869
        self::$jobManager->getObjectManager()->flush();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
870
        self::$jobManager->getObjectManager()->clear();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
871
872
        $job1 = $worker->later(100)->fibonacci(1);
873
874
        $time1 = new \DateTime();
875
        $job2 = $worker->batchLater(0)->fibonacci(1);
876
        $time2 = Util::getDateTimeFromDecimalFormat(Util::getMicrotimeDecimal());
877
878
        self::assertEquals($job1, $job2);
879
        self::assertGreaterThanOrEqual($time1, $job2->getWhenAt());
880
        self::assertLessThanOrEqual($time2, $job2->getWhenAt());
881
882
        $jobs = self::$jobManager->getRepository()->findAll();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getRepository() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
883
        self::assertCount(1, $jobs);
884
        self::assertEquals($job1, $jobs[0]);
885
        self::assertGreaterThanOrEqual($time1, $jobs[0]->getWhenAt());
886
        self::assertLessThanOrEqual($time2, $jobs[0]->getWhenAt());
887
        self::$jobManager->getObjectManager()->remove($jobs[0]);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
888
        self::$jobManager->getObjectManager()->flush();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
889
        self::$jobManager->getObjectManager()->clear();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
890
891
        $job1 = $worker->later(100)->setPriority(3)->fibonacci(1);
892
        $priority1 = $job1->getPriority();
893
        $time1 = Util::getDateTimeFromDecimalFormat(Util::getMicrotimeDecimal());
894
        $job2 = $worker->batchLater(0)->setPriority(1)->fibonacci(1);
895
        $time2 = Util::getDateTimeFromDecimalFormat(Util::getMicrotimeDecimal());
896
        self::assertEquals($job1, $job2);
897
        self::assertNotEquals($priority1, $job2->getPriority());
898
899
        self::assertEquals($job1, $job2);
900
        self::assertGreaterThanOrEqual($time1, $job2->getWhenAt());
901
        self::assertLessThanOrEqual($time2, $job2->getWhenAt());
902
    }
903
904
    public function testPruneExpiredJobs()
905
    {
906
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
907
        $jobManager = self::$jobManager;
908
        $objectManager = $jobManager->getObjectManager();
909
910
        $job = new self::$jobClass(self::$worker, false, null);
911
        $job->fibonacci(1);
912
        self::assertNotNull($job->getId(), 'Job id should be generated');
913
        $time = time() - 1;
914
        $date = new \DateTime("@$time");
915
        $job->setExpiresAt($date);
916
        $objectManager->persist($job);
917
        $objectManager->flush();
918
919
        $count = $jobManager->pruneExpiredJobs('asdf');
920
        self::assertEquals(0, $count);
921
        $count = $jobManager->pruneExpiredJobs(null, 'asdf');
922
        self::assertEquals(0, $count);
923
        $count = $jobManager->pruneExpiredJobs(null, 'fibonacci');
924
        self::assertEquals(1, $count);
925
926
        $job = new self::$jobClass(self::$worker, false, null);
927
        $job->fibonacci(1);
928
        self::assertNotNull($job->getId(), 'Job id should be generated');
929
        $time = time() - 1;
930
        $date = new \DateTime("@$time");
931
        $job->setExpiresAt($date);
932
        $objectManager->persist($job);
933
        $objectManager->flush();
934
935
        $job = new self::$jobClass(self::$worker, false, null);
936
        $job->fibonacci(1);
937
        self::assertNotNull($job->getId(), 'Job id should be generated');
938
        $time = time() - 1;
939
        $date = new \DateTime("@$time");
940
        $job->setExpiresAt($date);
941
        $objectManager->persist($job);
942
        $objectManager->flush();
943
944
        $count = $jobManager->pruneExpiredJobs(null, 'fibonacci');
945
        self::assertEquals(2, $count);
946
947
        $job = new self::$jobClass(self::$worker, false, null);
948
        $job->fibonacci(1);
949
        self::assertNotNull($job->getId(), 'Job id should be generated');
950
        $time = time() - 1;
951
        $date = new \DateTime("@$time");
952
        $job->setExpiresAt($date);
953
        $objectManager->persist($job);
954
        $objectManager->flush();
955
956
        $job = new self::$jobClass(self::$worker, false, null);
957
        $job->fibonacci(1);
958
        self::assertNotNull($job->getId(), 'Job id should be generated');
959
        $time = time() - 1;
960
        $date = new \DateTime("@$time");
961
        $job->setExpiresAt($date);
962
        $objectManager->persist($job);
963
        $objectManager->flush();
964
965
        $count = $jobManager->pruneExpiredJobs('fibonacci', 'fibonacci');
966
        self::assertEquals(2, $count);
967
968
        $job = new self::$jobClass(self::$worker, false, null);
969
        $job->fibonacci(1);
970
        self::assertNotNull($job->getId(), 'Job id should be generated');
971
        $time = time() - 1;
972
        $date = new \DateTime("@$time");
973
        $job->setExpiresAt($date);
974
        $objectManager->persist($job);
975
        $objectManager->flush();
976
977
        $job = new self::$jobClass(self::$worker, false, null);
978
        $job->fibonacci(1);
979
        self::assertNotNull($job->getId(), 'Job id should be generated');
980
        $time = time() - 1;
981
        $date = new \DateTime("@$time");
982
        $job->setExpiresAt($date);
983
        $objectManager->persist($job);
984
        $objectManager->flush();
985
986
        $count = $jobManager->pruneExpiredJobs('fibonacci');
987
        self::assertEquals(2, $count);
988
989
        $job = new self::$jobClass(self::$worker, false, null);
990
        $job->fibonacci(1);
991
        self::assertNotNull($job->getId(), 'Job id should be generated');
992
        $time = time() - 1;
993
        $date = new \DateTime("@$time");
994
        $job->setExpiresAt($date);
995
        $objectManager->persist($job);
996
        $objectManager->flush();
997
998
        $jobId1 = $job->getId();
999
1000
        $job = new self::$jobClass(self::$worker, false, null);
1001
        $job->fibonacci(1);
1002
        self::assertNotNull($job->getId(), 'Job id should be generated');
1003
        $time = time() - 1;
1004
        $date = new \DateTime("@$time");
1005
        $job->setExpiresAt($date);
1006
        $objectManager->persist($job);
1007
        $objectManager->flush();
1008
1009
        $jobId2 = $job->getId();
1010
1011
        $count = $jobManager->pruneExpiredJobs();
1012
        self::assertEquals(2, $count);
1013
1014
        $archiveRepository = $jobManager->getObjectManager()->getRepository($jobManager->getJobArchiveClass());
1015
1016
        $job = $archiveRepository->find($jobId1);
1017
        self::assertNotNull($job);
1018
        self::assertEquals(Job::STATUS_EXPIRED, $job->getStatus());
1019
1020
        $job = $archiveRepository->find($jobId2);
1021
        self::assertNotNull($job);
1022
        self::assertEquals(Job::STATUS_EXPIRED, $job->getStatus());
1023
    }
1024
1025
    public function testPruneArchivedJobs()
1026
    {
1027
        /** @var JobManager|\Dtc\QueueBundle\ORM\JobManager $jobManager */
1028
        $jobManager = self::$jobManager;
1029
        $objectManager = $jobManager->getObjectManager();
1030
        $jobArchiveClass = $jobManager->getJobArchiveClass();
1031
        $jobArchiveRepository = $objectManager->getRepository($jobArchiveClass);
1032
1033
        self::$objectManager->getEventManager()->removeEventListener('preUpdate', self::$dtcQueueListener);
1034
1035
        $job = new self::$jobClass(self::$worker, false, null);
1036
        $job->fibonacci(1);
1037
        $id = $job->getId();
1038
        $objectManager->remove($job);
1039
        $objectManager->flush();
1040
1041
        $jobArchive = $jobArchiveRepository->find($id);
1042
        self::assertNotNull($jobArchive);
1043
        $time = time() - 86401;
1044
        $jobArchive->setUpdatedAt(new \DateTime("@$time"));
1045
        $objectManager->persist($jobArchive);
1046
        $objectManager->flush();
1047
1048
        $older = $time + 1;
1049
        $count = $jobManager->pruneArchivedJobs(new \DateTime("@$time"));
1050
        self::assertEquals(0, $count);
1051
        $count = $jobManager->pruneArchivedJobs(new \DateTime("@$older"));
1052
        self::assertEquals(1, $count);
1053
1054
        $job = new self::$jobClass(self::$worker, false, null);
1055
        $job->fibonacci(1);
1056
        $id = $job->getId();
1057
        $objectManager->remove($job);
1058
        $objectManager->flush();
1059
1060
        $jobArchive = $jobArchiveRepository->find($id);
1061
        self::assertNotNull($jobArchive);
1062
        $time = time() - 86401;
1063
        $jobArchive->setUpdatedAt(new \DateTime("@$time"));
1064
        $objectManager->persist($jobArchive);
1065
        $objectManager->flush();
1066
1067
        $job = new self::$jobClass(self::$worker, false, null);
1068
        $job->fibonacci(1);
1069
        $id = $job->getId();
1070
        $objectManager->remove($job);
1071
        $objectManager->flush();
1072
1073
        $jobArchive = $jobArchiveRepository->find($id);
1074
        self::assertNotNull($jobArchive);
1075
        $jobArchive->setUpdatedAt(new \DateTime("@$time"));
1076
        $objectManager->persist($jobArchive);
1077
        $objectManager->flush();
1078
        $older = $time + 1;
1079
        $count = $jobManager->pruneArchivedJobs(new \DateTime("@$time"));
1080
        self::assertEquals(0, $count);
1081
        $count = $jobManager->pruneArchivedJobs(new \DateTime("@$older"));
1082
        self::assertEquals(2, $count);
1083
1084
        self::$objectManager->getEventManager()->addEventListener('preUpdate', self::$dtcQueueListener);
1085
    }
1086
1087
    public function testPerformance()
1088
    {
1089
        $jobs = self::$jobManager->getRepository()->findAll();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getRepository() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
1090
        foreach ($jobs as $job) {
1091
            self::$jobManager->getObjectManager()->remove($job);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
1092
        }
1093
        self::$jobManager->getObjectManager()->flush();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
1094
1095
        self::$jobManager->getObjectManager()->clear();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
1096
        parent::testPerformance();
1097
    }
1098
1099
    protected function getBaseStatus()
1100
    {
1101
        /** @var DoctrineJobManager $jobManager */
1102
        $jobManager = self::$jobManager;
1103
        $job = new self::$jobClass(self::$worker, false, null);
1104
        $job->fibonacci(1);
1105
        $status = $jobManager->getStatus();
1106
        self::assertArrayHasKey('fibonacci->fibonacci()', $status);
1107
        $fibonacciStatus = $status['fibonacci->fibonacci()'];
1108
1109
        self::assertArrayHasKey(BaseJob::STATUS_NEW, $fibonacciStatus);
1110
        self::assertArrayHasKey(BaseJob::STATUS_EXCEPTION, $fibonacciStatus);
1111
        self::assertArrayHasKey(BaseJob::STATUS_RUNNING, $fibonacciStatus);
1112
        self::assertArrayHasKey(BaseJob::STATUS_SUCCESS, $fibonacciStatus);
1113
        self::assertArrayHasKey(Job::STATUS_EXPIRED, $fibonacciStatus);
1114
        self::assertArrayHasKey(StallableJob::STATUS_MAX_STALLS, $fibonacciStatus);
1115
        self::assertArrayHasKey(RetryableJob::STATUS_MAX_EXCEPTIONS, $fibonacciStatus);
1116
        self::assertArrayHasKey(RetryableJob::STATUS_MAX_FAILURES, $fibonacciStatus);
1117
        self::assertArrayHasKey(RetryableJob::STATUS_MAX_RETRIES, $fibonacciStatus);
1118
1119
        return [$job, $status];
1120
    }
1121
1122
    public function testGetStatus()
1123
    {
1124
        list($job1, $status1) = $this->getBaseStatus();
1125
        list($job2, $status2) = $this->getBaseStatus();
1126
        $fibonacciStatus1 = $status1['fibonacci->fibonacci()'];
1127
        $fibonacciStatus2 = $status2['fibonacci->fibonacci()'];
1128
1129
        self::assertEquals($fibonacciStatus1[BaseJob::STATUS_NEW] + 1, $fibonacciStatus2[BaseJob::STATUS_NEW]);
1130
        $jobManager = self::$jobManager;
1131
        $objectManager = $jobManager->getObjectManager();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Dtc\QueueBundle\Manager\JobManagerInterface as the method getObjectManager() does only exist in the following implementations of said interface: Dtc\QueueBundle\Doctrine\BaseDoctrineJobManager, Dtc\QueueBundle\Doctrine\DoctrineJobManager, Dtc\QueueBundle\ODM\JobManager, Dtc\QueueBundle\ORM\JobManager.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
1132
        $objectManager->remove($job1);
1133
        $objectManager->remove($job2);
1134
    }
1135
1136
    public function testStallableJobManager()
1137
    {
1138
        /** @var StallableJobManager $jobManager */
1139
        $jobManager = self::$jobManager;
1140
1141
        $defaultMaxStalls = $jobManager->getDefaultMaxStalls();
1142
        $jobManager->setDefaultMaxStalls(123);
1143
        self::assertEquals(123, $jobManager->getDefaultMaxStalls());
1144
        $jobManager->setDefaultMaxStalls($defaultMaxStalls);
1145
        self::assertEquals($defaultMaxStalls, $jobManager->getDefaultMaxStalls());
1146
    }
1147
}
1148