mageekguy\atoum\asserters\dateTime::hasYear PHP Метод

hasYear() публичный Метод

public hasYear ( $year, $failMessage = null )
    public function hasYear($year, $failMessage = null)
    {
        if ($this->valueIsSet()->value->format('Y') === sprintf('%04d', $year)) {
            $this->pass();
        } else {
            $this->fail($failMessage ?: $this->_('Year is %s instead of %s', $this->value->format('Y'), $year));
        }
        return $this;
    }

Usage Example

Пример #1
0
 public function testHasYear()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->exception(function () use($asserter) {
         $asserter->hasYear(rand(0, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Instance of \\dateTime is undefined')->if($asserter->setWith($dateTime = new \DateTime('1976-10-06')))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->hasYear(1981);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Year is %s instead of %s'), 1976, 1981))->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->hasYear(76);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Year is %s instead of %s'), 1976, 76))->object($asserter->hasYear('1976'))->isIdenticalTo($asserter)->object($asserter->hasYear(1976))->isIdenticalTo($asserter);
 }