Passed
Branch feature/chart.js (1dc9af)
by Valentin
02:38
created

YearlyTest::datetime2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spiral\Tests\Statistics\Extract\Intervals;
4
5
use Spiral\Statistics\Extract;
6
7 View Code Duplication
class YearlyTest extends AbstractInterval
1 ignored issue
show
Duplication introduced by
This class 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...
8
{
9
    const RANGE          = Extract\Range::YEARLY;
10
    const RANGE_FIELD    = 'year_mark';
11
    const RANGE_INTERVAL = 'P1Y';
12
    const RANGE_FORMAT   = 'Y';
13
14
    protected function start(): \DateTime
15
    {
16
        return new \DateTime('today noon - 370 days');
17
    }
18
19
    protected function end(): \DateTime
20
    {
21
        return new \DateTime('today noon + 370 days');
22
    }
23
24
    protected function datetime1(): \DateTime
25
    {
26
        return new \DateTime('today noon');
27
    }
28
29
    protected function datetime2(): \DateTime
30
    {
31
        return new \DateTime('today noon + 2 hours');
32
    }
33
34
    protected function datetime3(): \DateTime
35
    {
36
        return new \DateTime('today noon + 367 days + 2 hours');
37
    }
38
39
//    public function testYearly()
40
//    {
41
//        $rangeValue = Extract\Range::YEARLY;
42
//        /** @var Extract $extract */
43
//        $extract = $this->container->get(Extract::class);
44
//        /** @var Track $track */
45
//        $track = $this->container->get(Track::class);
46
//
47
//        $datetime = new \DateTime('this Monday of January');
48
//        $datetime2 = (new \DateTime('this Monday of January'))->add(new \DateInterval('P3M'));
49
//
50
//        $this->assertCount(0, $this->orm->source(Occurrence::class));
51
//        $this->assertCount(0, $this->orm->source(Event::class));
52
//
53
//        $track->events([
54
//            'event1' => 1,
55
//            'event2' => 2
56
//        ], $datetime);
57
//
58
//        $track->events([
59
//            'event1' => 3,
60
//            'event2' => 4
61
//        ], $datetime2);
62
//
63
//        $this->assertCount(2, $this->orm->source(Occurrence::class));
64
//        $this->assertCount(4, $this->orm->source(Event::class));
65
//
66
//        //test start same date
67
//        $start = new \DateTime('this Monday noon');
68
//        $end = (new \DateTime('this Monday noon'))->add(new \DateInterval('P2Y'));
69
//        $range = new Extract\Range($rangeValue);
70
//        $results = $extract->events(clone $start, clone $end, $rangeValue, ['event1', 'event2']);
71
//
72
//        $label = $start->format($range->getFormat());
73
//        $this->assertArrayHasKey($label, $results->results());
74
//        $this->assertArrayHasKey('event1', $results->results()[$label]);
75
//        $this->assertArrayHasKey('event2', $results->results()[$label]);
76
//        $this->assertEquals(4, $results->results()[$label]['event1']);
77
//        $this->assertEquals(6, $results->results()[$label]['event2']);
78
//
79
//        //test start end date
80
//        $start = (new \DateTime('this Monday noon'))->sub(new \DateInterval('P2Y'));
81
//        $end = new \DateTime('this Monday noon');
82
//        $range = new Extract\Range($rangeValue);
83
//        $results = $extract->events(clone $start, clone $end, $rangeValue, ['event1', 'event2']);
84
//
85
//        $label = $end->format($range->getFormat());
86
//        $this->assertArrayHasKey($label, $results->results());
87
//        $this->assertArrayHasKey('event1', $results->results()[$label]);
88
//        $this->assertArrayHasKey('event2', $results->results()[$label]);
89
//        $this->assertEquals(4, $results->results()[$label]['event1']);
90
//        $this->assertEquals(6, $results->results()[$label]['event2']);
91
//
92
//        //test same start and end date
93
//        $start = $end = new \DateTime('this Monday noon');
94
//        $range = new Extract\Range($rangeValue);
95
//        $results = $extract->events(clone $start, clone $end, $rangeValue, ['event1', 'event2']);
96
//
97
//        $label = $end->format($range->getFormat());
98
//        $this->assertArrayHasKey($label, $results->results());
99
//        $this->assertArrayHasKey('event1', $results->results()[$label]);
100
//        $this->assertArrayHasKey('event2', $results->results()[$label]);
101
//        $this->assertEquals(4, $results->results()[$label]['event1']);
102
//        $this->assertEquals(6, $results->results()[$label]['event2']);
103
//    }
104
}