1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spiral\Tests\Statistics\Extract\Intervals; |
4
|
|
|
|
5
|
|
|
use Spiral\Statistics\Extract; |
6
|
|
|
|
7
|
|
View Code Duplication |
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
|
|
|
} |
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.