1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spiral\Tests\Statistics; |
4
|
|
|
|
5
|
|
|
use Spiral\Statistics\Database\Event; |
6
|
|
|
use Spiral\Statistics\Database\Occurrence; |
7
|
|
|
use Spiral\Statistics\Extract; |
8
|
|
|
use Spiral\Statistics\Track; |
9
|
|
|
use Spiral\Tests\BaseTest; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* For \Spiral\Statistics\Extract::events tests see below: |
13
|
|
|
* |
14
|
|
|
* @see Spiral\Tests\Statistics\Extract\Intervals\AbstractInterval::testExtractEvents |
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(), 'range', []); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testDateSwap() |
28
|
|
|
{ |
29
|
|
|
$extract = $this->getExtract(); |
30
|
|
|
$track = $this->getTrack(); |
31
|
|
|
|
32
|
|
|
$this->assertCount(0, $this->orm->source(Occurrence::class)); |
33
|
|
|
$this->assertCount(0, $this->orm->source(Event::class)); |
34
|
|
|
|
35
|
|
|
$datetime1 = new \DateTime('now'); |
36
|
|
|
$datetime2 = new \DateTime('tomorrow'); |
37
|
|
|
|
38
|
|
|
$track->event('event1', 1, $datetime1); |
39
|
|
|
$track->event('event2', 1, $datetime1); |
40
|
|
|
$track->event('event2', 2, $datetime2); |
41
|
|
|
|
42
|
|
|
$this->assertCount(2, $this->orm->source(Occurrence::class)); |
43
|
|
|
$this->assertCount(3, $this->orm->source(Event::class)); |
44
|
|
|
|
45
|
|
|
$start = new \DateTime('-2 days'); |
46
|
|
|
$end = new \DateTime('+2 days'); |
47
|
|
|
|
48
|
|
|
$this->assertEquals( |
49
|
|
|
$extract->events($start, $end, Extract\Range::DAILY, ['event1']), |
50
|
|
|
$extract->events($end, $start, Extract\Range::DAILY, ['event1']) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
} |