mageekguy\atoum\asserters\dateTime::hasHours PHP Method

hasHours() public method

public hasHours ( $hours, $failMessage = null )
    public function hasHours($hours, $failMessage = null)
    {
        if ($this->valueIsSet()->value->format('H') === sprintf('%02d', $hours)) {
            $this->pass();
        } else {
            $this->fail($failMessage ?: $this->_('Hours are %s instead of %02d', $this->value->format('H'), $hours));
        }
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 public function testHasHours()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->exception(function () use($asserter) {
         $asserter->hasHours(rand(0, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Instance of \\dateTime is undefined')->if($asserter->setWith($dateTime = new \DateTime('01:02:03')))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->hasHours(2);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Hours are %02d instead of %02d'), 1, 2))->object($asserter->hasHours('01'))->isIdenticalTo($asserter)->object($asserter->hasHours('1'))->isIdenticalTo($asserter)->object($asserter->hasHours(1))->isIdenticalTo($asserter);
 }