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

setWith() public method

public setWith ( $value, $checkType = true )
    public function setWith($value, $checkType = true)
    {
        $exception = $value;
        if ($exception instanceof \closure) {
            $exception = null;
            if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
                try {
                    $value($this->getTest());
                } catch (\throwable $exception) {
                }
            } else {
                try {
                    $value($this->getTest());
                } catch (\exception $exception) {
                }
            }
        }
        parent::setWith($exception, false);
        if ($checkType === true) {
            if (self::isThrowable($exception) === false) {
                $this->fail($this->_('%s is not an exception', $this));
            } else {
                $this->pass();
                static::$lastValue = $exception;
            }
        }
        return $this;
    }

Usage Example

Example #1
0
 public function testGetLastValue()
 {
     $this->variable(sut::getLastValue())->isNull()->if($asserter = new sut(new asserter\generator()))->and($asserter->setWith(function () use(&$exception) {
         $exception = new \exception();
         throw $exception;
     }))->then->object(sut::getLastValue())->isIdenticalTo($exception)->and($asserter->setWith(function () use(&$otherException) {
         $otherException = new \exception();
         throw $otherException;
     }))->then->object(sut::getLastValue())->isIdenticalTo($otherException);
 }
All Usage Examples Of mageekguy\atoum\asserters\exception::setWith