@@ 7-104 (lines=98) @@ | ||
4 | ||
5 | use Spiral\Statistics\Extract; |
|
6 | ||
7 | class DailyTest extends AbstractInterval |
|
8 | { |
|
9 | const RANGE = Extract\Range::DAILY; |
|
10 | const RANGE_FIELD = 'day_mark'; |
|
11 | const RANGE_INTERVAL = 'P1D'; |
|
12 | const RANGE_FORMAT = 'M, d Y'; |
|
13 | ||
14 | // public function testDailyExtract() |
|
15 | // { |
|
16 | // $rangeValue = Extract\Range::DAILY; |
|
17 | // /** @var Extract $extract */ |
|
18 | // $extract = $this->container->get(Extract::class); |
|
19 | // /** @var Track $track */ |
|
20 | // $track = $this->container->get(Track::class); |
|
21 | // |
|
22 | // $datetime = new \DateTime('today noon'); |
|
23 | // $datetime2 = new \DateTime('today noon + 2 hours'); |
|
24 | // |
|
25 | // $this->assertCount(0, $this->orm->source(Occurrence::class)); |
|
26 | // $this->assertCount(0, $this->orm->source(Event::class)); |
|
27 | // |
|
28 | // $track->events([ |
|
29 | // 'event1' => 1, |
|
30 | // 'event2' => 2 |
|
31 | // ], $datetime); |
|
32 | // |
|
33 | // $track->events([ |
|
34 | // 'event1' => 3, |
|
35 | // 'event2' => 4 |
|
36 | // ], $datetime2); |
|
37 | // |
|
38 | // $this->assertCount(2, $this->orm->source(Occurrence::class)); |
|
39 | // $this->assertCount(4, $this->orm->source(Event::class)); |
|
40 | // |
|
41 | // //test start same date |
|
42 | // $start = new \DateTime('today'); |
|
43 | // $end = new \DateTime('today + 7 days'); |
|
44 | // $range = new Extract\Range($rangeValue); |
|
45 | // $results = $extract->events(clone $start, clone $end, $rangeValue, ['event1', 'event2']); |
|
46 | // |
|
47 | // $label = $start->format($range->getFormat()); |
|
48 | // $this->assertArrayHasKey($label, $results->results()); |
|
49 | // $this->assertArrayHasKey('event1', $results->results()[$label]); |
|
50 | // $this->assertArrayHasKey('event2', $results->results()[$label]); |
|
51 | // $this->assertEquals(4, $results->results()[$label]['event1']); |
|
52 | // $this->assertEquals(6, $results->results()[$label]['event2']); |
|
53 | // |
|
54 | // //test start end date |
|
55 | // $start = new \DateTime('today - 7 days'); |
|
56 | // $end = new \DateTime('today'); |
|
57 | // $range = new Extract\Range($rangeValue); |
|
58 | // $results = $extract->events(clone $start, clone $end, $rangeValue, ['event1', 'event2']); |
|
59 | // |
|
60 | // $label = $end->format($range->getFormat()); |
|
61 | // $this->assertArrayHasKey($label, $results->results()); |
|
62 | // $this->assertArrayHasKey('event1', $results->results()[$label]); |
|
63 | // $this->assertArrayHasKey('event2', $results->results()[$label]); |
|
64 | // $this->assertEquals(4, $results->results()[$label]['event1']); |
|
65 | // $this->assertEquals(6, $results->results()[$label]['event2']); |
|
66 | // |
|
67 | // //test same start and end date |
|
68 | // $start = $end = new \DateTime('today'); |
|
69 | // $range = new Extract\Range($rangeValue); |
|
70 | // $results = $extract->events(clone $start, clone $end, $rangeValue, ['event1', 'event2']); |
|
71 | // |
|
72 | // $label = $end->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 | ||
80 | protected function start(): \DateTime |
|
81 | { |
|
82 | return new \DateTime('today noon - 2 days'); |
|
83 | } |
|
84 | ||
85 | protected function end(): \DateTime |
|
86 | { |
|
87 | return new \DateTime('today noon + 2 days'); |
|
88 | } |
|
89 | ||
90 | protected function datetime1(): \DateTime |
|
91 | { |
|
92 | return new \DateTime('today noon'); |
|
93 | } |
|
94 | ||
95 | protected function datetime2(): \DateTime |
|
96 | { |
|
97 | return new \DateTime('today noon + 2 hours'); |
|
98 | } |
|
99 | ||
100 | protected function datetime3(): \DateTime |
|
101 | { |
|
102 | return new \DateTime('today noon + 26 hours'); |
|
103 | } |
|
104 | } |
@@ 7-104 (lines=98) @@ | ||
4 | ||
5 | use Spiral\Statistics\Extract; |
|
6 | ||
7 | class MonthlyTest extends AbstractInterval |
|
8 | { |
|
9 | const RANGE = Extract\Range::MONTHLY; |
|
10 | const RANGE_FIELD = 'month_mark'; |
|
11 | const RANGE_INTERVAL = 'P1M'; |
|
12 | const RANGE_FORMAT = 'M, Y'; |
|
13 | ||
14 | protected function start(): \DateTime |
|
15 | { |
|
16 | return new \DateTime('today noon - 35 days'); |
|
17 | } |
|
18 | ||
19 | protected function end(): \DateTime |
|
20 | { |
|
21 | return new \DateTime('today noon + 35 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 + 33 days + 2 hours'); |
|
37 | } |
|
38 | ||
39 | // public function testMonthly() |
|
40 | // { |
|
41 | // $rangeValue = Extract\Range::MONTHLY; |
|
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 noon'); |
|
48 | // $datetime2 = (new \DateTime('this Monday noon'))->add(new \DateInterval('PT1H')); |
|
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('P4M')); |
|
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('P4M')); |
|
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 | } |
@@ 7-105 (lines=99) @@ | ||
4 | ||
5 | use Spiral\Statistics\Extract; |
|
6 | ||
7 | class WeeklyTest extends AbstractInterval |
|
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 | } |
@@ 7-104 (lines=98) @@ | ||
4 | ||
5 | use Spiral\Statistics\Extract; |
|
6 | ||
7 | class YearlyTest extends AbstractInterval |
|
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 | } |