Completed
Push — master ( d4f4f0...01653d )
by Matthew
04:03
created

RunManagerTest::testPruneStaleRuns()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 26

Duplication

Lines 31
Ratio 100 %

Importance

Changes 0
Metric Value
dl 31
loc 31
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 26
nc 1
nop 0
1
<?php
2
3
namespace Dtc\QueueBundle\Tests\ORM;
4
5
use PHPUnit\Framework\TestCase;
6
7
class RunManagerTest extends TestCase
8
{
9 View Code Duplication
    public function testPruneStaleRuns()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
    {
11
        JobManagerTest::setUpBeforeClass();
12
        $jobManager = JobManagerTest::$jobManager;
13
        $runClass = \Dtc\QueueBundle\Entity\Run::class;
14
        $runArchiveClass = \Dtc\QueueBundle\Entity\RunArchive::class;
15
        $runManager = new \Dtc\QueueBundle\ORM\RunManager($runClass, \Dtc\QueueBundle\Entity\JobTiming::class, true);
16
        $runManager->setRunArchiveClass($runArchiveClass);
17
        $runManager->setObjectManager($jobManager->getObjectManager());
18
        $objectManager = $runManager->getObjectManager();
19
        $runRepository = $objectManager->getRepository($runClass);
20
        self::assertEmpty($runRepository->findAll());
21
        $runArchiveRepository = $objectManager->getRepository($runArchiveClass);
22
        self::assertEmpty($runArchiveRepository->findAll());
23
24
        $run = new $runClass();
25
        $time = time() - 96400;
26
        $date = new \DateTime("@$time");
27
28
        $run->setStartedAt($date);
29
        $run->setLastHeartbeatAt($date);
30
        $objectManager->persist($run);
31
        $objectManager->flush($run);
32
        self::assertCount(1, $runRepository->findAll());
33
34
        $count = $runManager->pruneStalledRuns();
35
        self::assertEquals(1, $count);
36
        self::assertEmpty($runRepository->findAll());
37
        $count = $runManager->pruneStalledRuns();
38
        self::assertEquals(0, $count);
39
    }
40
}
41