mageekguy\atoum\asserters\exception::hasCode PHP Method

hasCode() public method

public hasCode ( $code, $failMessage = null )
    public function hasCode($code, $failMessage = null)
    {
        if ($this->valueIsSet()->value->getCode() === $code) {
            $this->pass();
        } else {
            $this->fail($failMessage ?: $this->_('code is %s instead of %s', $this->value->getCode(), $code));
        }
        return $this;
    }

Usage Example

Example #1
0
 public function testHasCode()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->boolean($asserter->wasSet())->isFalse()->exception(function () use($asserter) {
         $asserter->hasCode(rand(-PHP_INT_MAX, PHP_INT_MAX));
     })->isInstanceOf('logicException')->hasMessage('Exception is undefined')->if($asserter->setWith(new atoum\exceptions\runtime(uniqid(), $code = rand(2, PHP_INT_MAX))))->then->exception(function () use($asserter, &$otherCode) {
         $asserter->hasCode($otherCode = 1);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('code is %d instead of %d'), $code, $otherCode))->object($asserter->hasCode($code))->isIdenticalTo($asserter);
 }