Esempio n. 1
0
 /**
  * @dataProvider dataProviderTestedClients
  */
 public function testBitDateRange($redisClient)
 {
     $bitter = new TestedBitter($redisClient, $this->getPrefixKey(), $this->getPrefixTempKey());
     $this->removeAll($redisClient);
     $dateTime = DateTime::createFromFormat('Y-m-d H:i:s', '2011-11-06 15:30:45');
     $bitter->mark('drink_a_bitter_beer', 1, $dateTime);
     $dateTime = DateTime::createFromFormat('Y-m-d H:i:s', '2012-10-12 15:30:45');
     $bitter->mark('drink_a_bitter_beer', 2, $dateTime);
     $this->if($from = DateTime::createFromFormat('Y-m-d H:i:s', '2012-10-05 15:30:45'))->and($to = DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-07 15:30:45'))->and($bitter->bitDateRange('drink_a_bitter_beer', 'test_create_date_period', $from, $to))->then()->object($bitter->bitDateRange('drink_a_bitter_beer', 'test_create_date_period', $from, $to))->isIdenticalTo($bitter);
     $this->if($prefixKey = $this->getPrefixKey())->and($prefixTempKey = $this->getPrefixTempKey())->exception(function () use($redisClient, $prefixKey, $prefixTempKey) {
         $bitter = new TestedBitter($redisClient, $prefixKey, $prefixTempKey);
         $from = DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-07 15:30:45');
         $to = DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-07 14:30:45');
         $bitter->bitDateRange('drink_a_bitter_beer', 'test_create_date_period', $from, $to);
     })->hasMessage("DateTime from (2012-12-07 15:30:45) must be anterior to DateTime to (2012-12-07 14:30:45).");
     $this->if($from = DateTime::createFromFormat('Y-m-d H:i:s', '2010-10-05 20:30:45'))->and($to = DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-07 12:30:45'))->and($bitter->bitDateRange('drink_a_bitter_beer', 'test_create_date_period', $from, $to))->then()->boolean($bitter->in(1, 'test_create_date_period'))->isTrue()->boolean($bitter->in(2, 'test_create_date_period'))->isTrue()->integer($bitter->count('test_create_date_period'))->isEqualTo(2);
     $this->if($from = DateTime::createFromFormat('Y-m-d H:i:s', '2012-09-05 20:30:45'))->and($to = DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-07 12:30:45'))->and($bitter->bitDateRange('drink_a_bitter_beer', 'test_create_date_period', $from, $to))->then()->boolean($bitter->in(1, 'test_create_date_period'))->isFalse()->boolean($bitter->in(2, 'test_create_date_period'))->isTrue()->integer($bitter->count('test_create_date_period'))->isEqualTo(1);
     $this->removeAll($redisClient);
 }
Esempio n. 2
0
 public function testThatBitterMarkIncrementAndGetValue($redisClient)
 {
     $this->removeAll($redisClient);
     $bitter = new TestedBitter($redisClient, $this->getPrefixKey(), $this->getPrefixTempKey());
     $dateTime = new \DateTime();
     $dayActive = new Day('active', $dateTime);
     $dayBlocked = new Day('blocked', $dateTime);
     $this->if($dateTime = new \DateTime())->and($dayActive = new Day('active', $dateTime))->and($dayBlocked = new Day('blocked', $dateTime))->and($bitter->mark('active', 1))->and($bitter->mark('active', 2))->integer($bitter->count($dayActive))->isEqualTo(2)->if($from = new \DateTime('-1 day'))->and($to = new \DateTime('+1 day'))->and($bitter->mark('active', 3))->and($bitter->mark('blocked', 4))->and($bitter->mark('blocked', 5))->and($bitter->mark('blocked', 6))->and($bitter->mark('blocked', 7))->integer($bitter->count($dayActive))->isEqualTo(3)->integer($bitter->count($dayBlocked))->isEqualTo(4)->integer($bitter->count($dayBlocked) + $bitter->count($dayActive))->isEqualTo(7)->if($bitter->bitDateRange('active', 'active_users_period', $from, $to))->integer($bitter->count('active_users_period'))->isEqualTo(3)->if($bitter->bitDateRange('blocked', 'blocked_users_period', $from, $to))->integer($bitter->count('blocked_users_period'))->isEqualTo(4);
     $this->removeAll($redisClient);
 }