MineServiceTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 105
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testSimpleR1UpdateWithoutEvent() 0 17 1
A testSimpleR2UpdateWithoutEvent() 0 17 1
A testSimpleR3UpdateWithoutEvent() 0 17 1
A testUpdateWithEvent() 0 21 1
A testUpdateWithCancelledEvent() 0 17 1
1
<?php
2
3
namespace AppBundle\Tests\Service;
4
5
use AppBundle\Entity\Mine;
6
use AppBundle\Entity\User;
7
use AppBundle\Tests\KernelDbTestCase;
8
use DateTime;
9
10
class MineServiceTest extends KernelDbTestCase
11
{
12
    private $mineService;
13
14
    protected function setUp()
15
    {
16
        parent::setUp();
17
18
        $this->mineService = $this->container->get('app.mine');
0 ignored issues
show
Bug introduced by
The property container does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
    }
20
21
    public function testSimpleR1UpdateWithoutEvent()
22
    {
23
        $mine = $this->entityManager->getRepository(Mine::class)->find(1);
24
        $this->assertEquals(new DateTime('2016-08-01 00:00:01'), $mine->getLastUpdate());
25
        $user = $this->entityManager->getRepository(User::class)->find(1);
26
27
        $prodRxOnPeriod = 24 * $mine->getProdLevelIndex() * 1;
28
        $prodUpdated = $mine->getR1() + $prodRxOnPeriod;
29
        $newDate = new DateTime('2016-08-02 00:00:01');
30
31
        $this->mineService->update($user, $newDate);
32
33
        $this->assertEquals($prodUpdated, $mine->getR1());
34
        $this->assertEquals(0, $mine->getR2());
35
        $this->assertEquals(0, $mine->getR3());
36
        $this->assertEquals($newDate, $mine->getLastUpdate());
37
    }
38
39
    public function testSimpleR2UpdateWithoutEvent()
40
    {
41
        $mine = $this->entityManager->getRepository(Mine::class)->find(2);
42
        $this->assertEquals(new DateTime('2016-08-01 00:00:01'), $mine->getLastUpdate());
43
        $user = $this->entityManager->getRepository(User::class)->find(2);
44
45
        $prodRxOnPeriod = 24 * $mine->getProdLevelIndex() * 1;
46
        $prodUpdated = $mine->getR2() + $prodRxOnPeriod;
47
        $newDate = new DateTime('2016-08-02 00:00:01');
48
49
        $this->mineService->update($user, $newDate);
50
51
        $this->assertEquals(0, $mine->getR1());
52
        $this->assertEquals($prodUpdated, $mine->getR2());
53
        $this->assertEquals(0, $mine->getR3());
54
        $this->assertEquals($newDate, $mine->getLastUpdate());
55
    }
56
57
    public function testSimpleR3UpdateWithoutEvent()
58
    {
59
        $mine = $this->entityManager->getRepository(Mine::class)->find(3);
60
        $this->assertEquals(new DateTime('2016-08-01 00:00:01'), $mine->getLastUpdate());
61
        $user = $this->entityManager->getRepository(User::class)->find(3);
62
63
        $prodRxOnPeriod = 24 * $mine->getProdLevelIndex() * 1;
64
        $prodUpdated = $mine->getR3() + $prodRxOnPeriod;
65
        $newDate = new DateTime('2016-08-02 00:00:01');
66
67
        $this->mineService->update($user, $newDate);
68
69
        $this->assertEquals(0, $mine->getR1());
70
        $this->assertEquals(0, $mine->getR2());
71
        $this->assertEquals($prodUpdated, $mine->getR3());
72
        $this->assertEquals($newDate, $mine->getLastUpdate());
73
    }
74
75
    public function testUpdateWithEvent()
76
    {
77
        $mine = $this->entityManager->getRepository(Mine::class)->find(6);
78
        $this->assertEquals(new DateTime('2016-08-01 00:00:01'), $mine->getLastUpdate());
79
        $user = $this->entityManager->getRepository(User::class)->find(6);
80
81
        $prodRxOnPeriod1 = 24 * $mine->getProdLevelIndex() * $mine->getR1Factor() / 100;
82
        $mine->setLevel(2);
83
        $prodRxOnPeriod2 = 24 * $mine->getProdLevelIndex() * $mine->getR1Factor() / 100;
84
        $prodUpdated = $mine->getR1() + $prodRxOnPeriod1 + $prodRxOnPeriod2;
85
        $mine->setLevel(1);
86
        $newDate = new DateTime('2016-08-03 00:00:01');
87
88
        $this->mineService->update($user, $newDate);
89
90
        $this->assertEquals($prodUpdated, $mine->getR1());
91
        $this->assertEquals($prodUpdated, $mine->getR2());
92
        $this->assertEquals($prodUpdated, $mine->getR3());
93
        $this->assertEquals(2, $mine->getLevel());
94
        $this->assertEquals($newDate, $mine->getLastUpdate());
95
    }
96
97
    public function testUpdateWithCancelledEvent()
98
    {
99
        $mine = $this->entityManager->getRepository(Mine::class)->find(7);
100
        $this->assertEquals(new DateTime('2016-08-01 00:00:01'), $mine->getLastUpdate());
101
        $user = $this->entityManager->getRepository(User::class)->find(7);
102
103
        $prodUpdated = 48 * $mine->getProdLevelIndex() * $mine->getR1Factor() / 100;
104
        $newDate = new DateTime('2016-08-03 00:00:01');
105
106
        $this->mineService->update($user, $newDate);
107
108
        $this->assertEquals($prodUpdated, $mine->getR1());
109
        $this->assertEquals($prodUpdated, $mine->getR2());
110
        $this->assertEquals($prodUpdated, $mine->getR3());
111
        $this->assertEquals(1, $mine->getLevel());
112
        $this->assertEquals($newDate, $mine->getLastUpdate());
113
    }
114
}
115