Passed
Branch feature/v2 (61dd95)
by Valentin
05:53
created

ExtractTest::testEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Spiral\Tests\Statistics;
4
5
use Spiral\Statistics\Database\Statistics;
6
use Spiral\Statistics\Extract;
7
use Spiral\Tests\BaseTest;
8
use Spiral\Tests\Statistics\Entities\UnknownRange;
9
10
/**
11
 * For \Spiral\Statistics\Extract::events tests see below:
12
 *
13
 * @see Spiral\Tests\Statistics\Extract\Intervals\AbstractInterval::testSamePeriodExtractEvents
14
 * @see Spiral\Tests\Statistics\Extract\Intervals\AbstractInterval::testAnotherPeriodExtractEvents
15
 */
16
class ExtractTest extends BaseTest
17
{
18
    /**
19
     * @expectedException \Spiral\Statistics\Exceptions\InvalidExtractException
20
     */
21
    public function testEmptyEvents()
22
    {
23
        $extract = $this->getExtract();
24
        $extract->events(new \DateTime(), new \DateTime(), new UnknownRange(), []);
25
    }
26
27
    public function testEvents()
28
    {
29
        $extract = $this->getExtract();
30
        $events = $extract->events(
31
            new \DateTime(),
32
            new \DateTime(),
33
            new Extract\Range\DailyRange(), ['event']
34
        );
35
36
        $this->assertInstanceOf(Extract\Events::class, $events);
37
    }
38
39 View Code Duplication
    public function testDateSwap()
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...
40
    {
41
        $extract = $this->getExtract();
42
        $track = $this->getTrack();
43
44
        $this->assertCount(0, $this->orm->source(Statistics::class));
45
46
        $datetime1 = new \DateTime('now');
47
        $datetime2 = new \DateTime('tomorrow');
48
49
        $track->event('event1', 1, $datetime1);
50
        $track->event('event2', 1, $datetime1);
51
        $track->event('event2', 2, $datetime2);
52
53
        $this->assertCount(3, $this->orm->source(Statistics::class));
54
55
        $start = new \DateTime('-2 days');
56
        $end = new \DateTime('+2 days');
57
58
        $range = new Extract\Range\DailyRange();
59
60
        $this->assertEquals(
61
            $extract->events($start, $end, $range, ['event1']),
62
            $extract->events($end, $start, $range, ['event1'])
63
        );
64
    }
65
66 View Code Duplication
    public function testFillGaps()
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...
67
    {
68
        $extract = $this->getExtract();
69
        $track = $this->getTrack();
70
71
        $this->assertCount(0, $this->orm->source(Statistics::class));
72
73
        $datetime1 = new \DateTime('now');
74
        $datetime2 = new \DateTime('tomorrow');
75
76
        $track->event('event1', 1, $datetime1);
77
        $track->event('event2', 1, $datetime1);
78
        $track->event('event2', 2, $datetime2);
79
80
        $this->assertCount(3, $this->orm->source(Statistics::class));
81
82
        $start = new \DateTime('-2 days');
83
        $end = new \DateTime('+2 days');
84
85
        $range = new Extract\Range\DailyRange();
86
        $events = $extract->events($start, $end, $range, ['event1']);
87
88
        $this->assertCount(5, $events->getRows());
89
    }
90
}