mageekguy\atoum\asserters\error::exists PHP Метод

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

public exists ( )
    public function exists()
    {
        $key = $this->score->errorExists($this->message, $this->type, $this->messageIsPattern);
        if ($key !== null) {
            $this->score->deleteError($key);
            $this->pass();
        } else {
            switch (true) {
                case $this->type === null && $this->message === null:
                    $failReason = $this->_('error does not exist');
                    break;
                case $this->type === null && $this->message !== null:
                    $failReason = $this->_('error with message \'%s\' does not exist', $this->message);
                    break;
                case $this->type !== null && $this->message === null:
                    $failReason = $this->_('error of type %s does not exist', self::getAsString($this->type));
                    break;
                default:
                    $failReason = $this->_('error of type %s with message \'%s\' does not exist', self::getAsString($this->type), $this->message);
            }
            $this->fail($failReason);
        }
        return $this;
    }

Usage Example

Пример #1
0
 public function testExists()
 {
     $this->if($asserter = new asserters\error($generator = new asserter\generator()))->then->exception(function () use(&$line, $asserter) {
         $asserter->exists();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($generator->getLocale()->_('error does not exist'))->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), rand(0, PHP_INT_MAX), uniqid(), uniqid(), rand(1, PHP_INT_MAX)))->then->object($asserter->exists())->isIdenticalTo($asserter)->array($asserter->getScore()->getErrors())->isEmpty()->if($asserter->setWith($message = uniqid(), null))->then->exception(function () use(&$line, $asserter) {
         $asserter->exists();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('error with message \'%s\' does not exist'), $message))->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), rand(0, PHP_INT_MAX), $message, uniqid(), rand(1, PHP_INT_MAX)))->then->object($asserter->exists())->isIdenticalTo($asserter)->array($asserter->getScore()->getErrors())->isEmpty()->if($asserter->setWith($message = uniqid(), $type = E_USER_ERROR))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->exists();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('error of type %s with message \'%s\' does not exist'), asserters\error::getAsString($type), $message))->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $type, $message, uniqid(), rand(1, PHP_INT_MAX)))->then->object($asserter->exists())->isIdenticalTo($asserter)->array($asserter->getScore()->getErrors())->isEmpty()->if($asserter->setWith(null, $type = E_USER_ERROR))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->exists();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('error of type %s does not exist'), asserters\error::getAsString($type)))->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $type, uniqid(), uniqid(), rand(1, PHP_INT_MAX)))->then->object($asserter->exists())->isIdenticalTo($asserter)->array($asserter->getScore()->getErrors())->isEmpty()->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), rand(1, PHP_INT_MAX), $message = uniqid() . 'FOO' . uniqid(), uniqid(), rand(1, PHP_INT_MAX)))->and($asserter->withPattern('/FOO/')->withType(null))->then->object($asserter->exists())->isIdenticalTo($asserter)->array($asserter->getScore()->getErrors())->isEmpty();
 }