| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Spiral\Tests\Statistics; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Spiral\Statistics\Database\Statistics; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Spiral\Tests\BaseTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class TrackTest extends BaseTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 10 |  | View Code Duplication |     public function testEvent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |         $track = $this->getTrack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         $this->assertCount(0, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         $track->event('some-event', 1.23); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $this->assertCount(1, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     public function testEventInc() | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         $track = $this->getTrack(); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         $this->assertCount(0, $this->orm->source(Statistics::class)); | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         $datetime = new \DateTime('now'); | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $track->event('some-event', 1.23, $datetime); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         $track->event('some-event', 2.34, $datetime); | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         $this->assertCount(1, $this->orm->source(Statistics::class)); | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         /** @var Statistics $event */ | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $event = $this->orm->source(Statistics::class)->findOne(); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         $this->assertNotEmpty($event); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         $this->assertSame(3.57, $event->value); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 40 |  | View Code Duplication |     public function testSignEventInc() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $track = $this->getTrack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->assertCount(0, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $datetime = new \DateTime('now'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $track->event('some-event', 1.23, $datetime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $track->event('some-event', -2.34, $datetime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->assertCount(1, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         /** @var Statistics $event */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $event = $this->orm->source(Statistics::class)->findOne(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->assertNotEmpty($event); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $this->assertSame(-1.11, $event->value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     public function testZeroEventInc() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $track = $this->getTrack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $this->assertCount(0, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $datetime = new \DateTime('now'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $track->event('some-event', 1.23, $datetime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $track->event('some-event', 0, $datetime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->assertCount(1, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         /** @var Statistics $event */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $event = $this->orm->source(Statistics::class)->findOne(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->assertNotEmpty($event); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $this->assertSame(1.23, $event->value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 78 |  | View Code Duplication |     public function testEvents() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $track = $this->getTrack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $this->assertCount(0, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $track->events([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             'some-event'  => 1.23, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             'some-event2' => 2.34 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $this->assertCount(2, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 92 |  | View Code Duplication |     public function testEmptyEvents() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $track = $this->getTrack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $this->assertCount(0, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $track->events([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $this->assertCount(0, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 103 |  | View Code Duplication |     public function testEventsInc() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $track = $this->getTrack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $this->assertCount(0, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $datetime = new \DateTime('now'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $track->events([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             'some-event' => 1.23, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         ], $datetime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $track->events([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             'some-event' => 2.34, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         ], $datetime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $this->assertCount(1, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         /** @var Statistics $event */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         $event = $this->orm->source(Statistics::class)->findOne(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $this->assertNotEmpty($event); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         $this->assertSame(3.57, $event->value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 126 |  | View Code Duplication |     public function testSignEventsInc() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $track = $this->getTrack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $this->assertCount(0, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         $datetime = new \DateTime('now'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         $track->events([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |             'some-event' => 1.23, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         ], $datetime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         $track->events([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |             'some-event' => -2.34, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         ], $datetime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $this->assertCount(1, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         /** @var Statistics $event */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         $event = $this->orm->source(Statistics::class)->findOne(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         $this->assertNotEmpty($event); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         $this->assertSame(-1.11, $event->value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 149 |  | View Code Duplication |     public function testZeroEventsInc() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         $track = $this->getTrack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         $this->assertCount(0, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         $datetime = new \DateTime('now'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         $track->events([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |             'some-event' => 1.23, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         ], $datetime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         $track->events([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             'some-event' => 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         ], $datetime); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         $this->assertCount(1, $this->orm->source(Statistics::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         /** @var Statistics $event */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         $event = $this->orm->source(Statistics::class)->findOne(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         $this->assertNotEmpty($event); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         $this->assertSame(1.23, $event->value); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 170 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 171 |  |  | } |