示例#1
0
 /**
  * @param \DateTime $now
  *
  * @return int
  */
 public function getSleepSeconds(\DateTime $now)
 {
     $rule = $this->schedule->getMatchedRule($now);
     if ($rule instanceof RuleInterface) {
         $seconds = $rule->getSeconds();
         return $seconds > 0 ? $seconds : 0;
     }
     return 0;
 }
示例#2
0
 /**
  * @dataProvider getMatchedRule
  *
  * @param int $count_rules
  * @param int $match_rule_number
  */
 public function testGetMatchedRule($count_rules, $match_rule_number)
 {
     $time = new \DateTime();
     $match_rule = null;
     for ($i = 1; $i <= $count_rules; ++$i) {
         /* @var $rule \PHPUnit_Framework_MockObject_MockObject|RuleInterface */
         $rule = $this->getMock('AnimeDb\\SmartSleep\\Rule\\RuleInterface');
         if ($match_rule_number && $i > $match_rule_number) {
             $rule->expects($this->never())->method('isMatched');
         } else {
             $rule->expects($this->once())->method('isMatched')->with($time)->will($this->returnValue($i == $match_rule_number));
             if ($i == $match_rule_number) {
                 $match_rule = $rule;
             }
         }
         $this->schedule->add($rule);
     }
     $this->assertEquals($match_rule, $this->schedule->getMatchedRule($time));
 }