Completed
Push — master ( 5fe2ea...bba9f0 )
by Matthew
13:23
created

testLiveJobsGridSource()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 53
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 9.5797
c 0
b 0
f 0
cc 2
eloc 40
nc 2
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 PHPUnit\Framework\TestCase;
6
7
/**
8
 * This test requires local mongodb running.
9
 */
10
abstract class BaseLiveJobGridSourceTest extends TestCase
11
{
12
    abstract protected function getLiveGridSource();
13
14
    public function testLiveJobsGridSource()
15
    {
16
        $liveJobsGridSource = $this->getLiveGridSource();
17
        self::assertNull($liveJobsGridSource->getDefaultSort());
18
        self::assertFalse($liveJobsGridSource->isRunning());
19
        $count = $liveJobsGridSource->getCount();
20
        $records = $liveJobsGridSource->getRecords();
21
        self::assertEquals(0, $count);
22
        self::assertEmpty($records);
23
24
        $job = new BaseJobManagerTest::$jobClass(BaseJobManagerTest::$worker, false, null);
25
        $job->fibonacci(1);
26
27
        $count = $liveJobsGridSource->getCount();
28
        $records = $liveJobsGridSource->getRecords();
29
        self::assertEquals(1, $count);
30
        self::assertNotEmpty($records);
31
32
        $job = new BaseJobManagerTest::$jobClass(BaseJobManagerTest::$worker, false, null);
33
        $job->fibonacci(1);
34
35
        $count = $liveJobsGridSource->getCount();
36
        $records = $liveJobsGridSource->getRecords();
37
        self::assertEquals(2, $count);
38
        self::assertNotEmpty($records);
39
40
        $columns = $liveJobsGridSource->getColumns();
41
        self::assertNotEmpty($columns);
42
        foreach ($columns as $column) {
43
            self::assertFalse($column->getOption('sortable'));
44
        }
45
46
        $liveJobsGridSource->setRunning(true);
47
        self::assertTrue($liveJobsGridSource->isRunning());
48
        $count = $liveJobsGridSource->getCount();
49
        $records = $liveJobsGridSource->getRecords();
50
        self::assertEquals(0, $count);
51
        self::assertEmpty($records);
52
53
        BaseJobManagerTest::$jobManager->getJob();
54
55
        $count = $liveJobsGridSource->getCount();
56
        $records = $liveJobsGridSource->getRecords();
57
        self::assertEquals(1, $count);
58
        self::assertNotEmpty($records);
59
60
        BaseJobManagerTest::$jobManager->getJob();
61
62
        $count = $liveJobsGridSource->getCount();
63
        $records = $liveJobsGridSource->getRecords();
64
        self::assertEquals(2, $count);
65
        self::assertNotEmpty($records);
66
    }
67
}
68