/**
  * @param Activity $activity
  */
 public function add(Activity $activity)
 {
     $day = $activity->dateTime()->format('Y-m-d');
     if (empty($this->list[$day]) || !$this->list[$day] instanceof Activity) {
         $this->list[$day] = $activity;
         return;
     }
     $this->list[$day]->increaseActivity($activity->activity());
 }
 /**
  * @test
  */
 public function shouldIterateThroughStorages()
 {
     $this->activityCollection->add(Activity::withUserDateActivityCount(User::named('test'), new \DateTime("2015-12-30 23:50:01"), 1));
     $this->activityCollection->add(Activity::withUserDateActivityCount(User::named('test'), new \DateTime("2015-12-31 23:50:01"), 1));
     $this->activityCollection->add(Activity::withUserDateActivityCount(User::named('test'), new \DateTime("2015-12-31 23:50:01"), 1));
     $dates = ['2015-12-30', '2015-12-31'];
     $i = 0;
     foreach ($this->activityCollection as $day => $activity) {
         $this->assertSame($dates[$i], $day);
         $this->assertInstanceOf(Activity::class, $activity);
         $i++;
     }
     $this->assertSame(2, $i);
 }
 /**
  * @param array $row
  * @return Activity
  */
 private function mapActivityRowToActivity($row)
 {
     $dateTime = new \DateTime();
     return Activity::withUserDateActivityCount(User::named($row['user']), $dateTime->setTimestamp((int) $row['timestamp']), (int) $row['activities']);
 }
Exemplo n.º 4
0
 /**
  * @test
  * @dataProvider getInvalidActivities
  * @param $activityCount
  */
 public function shouldNotAllowCreationWithoutValidActivityCount($activityCount)
 {
     $this->setExpectedException(InvalidArgumentException::class);
     Activity::withUserDateActivityCount(User::named('test'), new \DateTime("2015-12-31 23:50:01"), $activityCount);
 }