Passed
Push — master ( 62401f...daf94f )
by Alec
07:24
created

EventCounterTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 5
1
<?php
2
/**
3
 * User: alec
4
 * Date: 03.11.18
5
 * Time: 22:32
6
 */
7
8
namespace Unit\EventCounter;
9
10
use AlecRabbit\EventCounter;
11
use PHPUnit\Framework\TestCase;
12
use Unit\DataProviders\EventsBasicDataProviderOne;
13
use Unit\DataProviders\EventsBasicDataProviderTwo;
14
15
class EventCounterTest extends TestCase
16
{
17
    /** @test */
18
    public function creationEventCounter(): void
19
    {
20
        $ec = new EventCounter(3600, 60);
21
        $ec->setName('new');
22
        $this->assertEquals('new', $ec->getName());
23
        $this->assertEquals([], $ec->getEvents());
24
        $ec->addEvent();
25
        $this->assertEquals(1, $ec->getCalculatedEvents());
26
        $ec->addEvent();
27
        $this->assertEquals(2, $ec->getCalculatedEvents());
28
    }
29
30
    /** @test */
31
    public function fillEventCounter(): void
32
    {
33
        $ec = new EventCounter(86400, 60);
34
        $ec->setRelativeMode();
35
        foreach (EventsBasicDataProviderOne::data() as $timestamp) {
36
            $ec->addEvent($timestamp);
37
        }
38
        $this->assertEquals(5760, $ec->getCalculatedEvents());
39
        $this->assertCount(1440, $ec->getEvents());
40
        $this->assertEquals(5760, $ec->getCalculatedEvents(true));
41
        $this->assertCount(0, $ec->getEvents());
42
    }
43
44
    /** @test */
45
    public function fillEventCounter2(): void
46
    {
47
        $ec = new EventCounter( 60);
48
        $ec->setRelativeMode();
49
        foreach (EventsBasicDataProviderTwo::data() as $timestamp) {
50
            $ec->addEvent($timestamp);
51
        }
52
        $this->assertEquals(120, $ec->getCalculatedEvents());
53
        $this->assertCount(60, $ec->getEvents());
54
        $this->assertEquals(120, $ec->getCalculatedEvents(true));
55
        $this->assertCount(0, $ec->getEvents());
56
    }
57
}
58