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

WeeklyTest::datetime3()   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 WeeklyTest 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::WEEKLY;
10
    const RANGE_FIELD    = 'week_mark';
11
    const RANGE_INTERVAL = 'P7D';
12
    const RANGE_FORMAT   = 'W, Y';
13
14
    protected function start(): \DateTime
15
    {
16
        return new \DateTime('today noon - 22 days');
17
    }
18
19
    protected function end(): \DateTime
20
    {
21
        return new \DateTime('today noon + 22 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 + 8 days + 2 hours');
37
    }
38
39
40
//    public function testWeekly()
41
//    {
42
//        $rangeValue = Extract\Range::WEEKLY;
43
//        /** @var Extract $extract */
44
//        $extract = $this->container->get(Extract::class);
45
//        /** @var Track $track */
46
//        $track = $this->container->get(Track::class);
47
//
48
//        $datetime = new \DateTime('this Monday noon');
49
//        $datetime2 = (new \DateTime('this Monday noon'))->add(new \DateInterval('P1D'));
50
//
51
//        $this->assertCount(0, $this->orm->source(Occurrence::class));
52
//        $this->assertCount(0, $this->orm->source(Event::class));
53
//
54
//        $track->events([
55
//            'event1' => 1,
56
//            'event2' => 2
57
//        ], $datetime);
58
//
59
//        $track->events([
60
//            'event1' => 3,
61
//            'event2' => 4
62
//        ], $datetime2);
63
//
64
//        $this->assertCount(2, $this->orm->source(Occurrence::class));
65
//        $this->assertCount(4, $this->orm->source(Event::class));
66
//
67
//        //test start same date
68
//        $start = new \DateTime('this Monday noon');
69
//        $end = (new \DateTime('this Monday noon'))->add(new \DateInterval('P21D'));
70
//        $range = new Extract\Range($rangeValue);
71
//        $results = $extract->events(clone $start, clone $end, $rangeValue, ['event1', 'event2']);
72
//
73
//        $label = $start->format($range->getFormat());
74
//        $this->assertArrayHasKey($label, $results->results());
75
//        $this->assertArrayHasKey('event1', $results->results()[$label]);
76
//        $this->assertArrayHasKey('event2', $results->results()[$label]);
77
//        $this->assertEquals(4, $results->results()[$label]['event1']);
78
//        $this->assertEquals(6, $results->results()[$label]['event2']);
79
//
80
//        //test start end date
81
//        $start = (new \DateTime('this Monday noon'))->sub(new \DateInterval('P21D'));
82
//        $end = new \DateTime('this Monday noon');
83
//        $range = new Extract\Range($rangeValue);
84
//        $results = $extract->events(clone $start, clone $end, $rangeValue, ['event1', 'event2']);
85
//
86
//        $label = $end->format($range->getFormat());
87
//        $this->assertArrayHasKey($label, $results->results());
88
//        $this->assertArrayHasKey('event1', $results->results()[$label]);
89
//        $this->assertArrayHasKey('event2', $results->results()[$label]);
90
//        $this->assertEquals(4, $results->results()[$label]['event1']);
91
//        $this->assertEquals(6, $results->results()[$label]['event2']);
92
//
93
//        //test same start and end date
94
//        $start = $end = new \DateTime('this Monday noon');
95
//        $range = new Extract\Range($rangeValue);
96
//        $results = $extract->events(clone $start, clone $end, $rangeValue, ['event1', 'event2']);
97
//
98
//        $label = $end->format($range->getFormat());
99
//        $this->assertArrayHasKey($label, $results->results());
100
//        $this->assertArrayHasKey('event1', $results->results()[$label]);
101
//        $this->assertArrayHasKey('event2', $results->results()[$label]);
102
//        $this->assertEquals(4, $results->results()[$label]['event1']);
103
//        $this->assertEquals(6, $results->results()[$label]['event2']);
104
//    }
105
}