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

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

public hasDateAndTime ( $year, $month, $day, $hours, $minutes, $seconds, $failMessage = null )
    public function hasDateAndTime($year, $month, $day, $hours, $minutes, $seconds, $failMessage = null)
    {
        if ($this->valueIsSet()->value->format('Y-m-d H:i:s') === sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year, $month, $day, $hours, $minutes, $seconds)) {
            $this->pass();
        } else {
            $this->fail($failMessage ?: $this->_('Datetime is %s instead of %s', $this->value->format('Y-m-d H:i:s'), sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year, $month, $day, $hours, $minutes, $seconds)));
        }
        return $this;
    }

Usage Example

Пример #1
0
 public function testHasDateAndTime()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->hasDateAndTime(1981, 2, 13, 1, 2, 3);
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Instance of \\dateTime is undefined')->if($asserter->setWith($dateTime = new \DateTime('1981-02-13 01:02:03')))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->hasDateAndTime(1900, 1, 1, 4, 5, 6);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Datetime is %s instead of %s'), '1981-02-13 01:02:03', '1900-01-01 04:05:06'))->object($asserter->hasDateAndTime('1981', '02', '13', '01', '02', '03'))->isIdenticalTo($asserter)->object($asserter->hasDateAndTime('1981', '2', '13', '1', '2', '3'))->isIdenticalTo($asserter)->object($asserter->hasDateAndTime(1981, 2, 13, 1, 2, 3))->isIdenticalTo($asserter);
 }