setWith() public method

public setWith ( $value, $checkType = true )
Example #1
0
 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;
 }
 protected function matches($actual)
 {
     $asserter = new asserters\object();
     try {
         $asserter->setWith($actual)->isNotInstanceOf($this->expected);
     } catch (logic $exception) {
         throw new \PHPUnit_Framework_Exception($exception->getMessage());
     }
 }
Example #3
0
 /**
  * @param mixed $value
  * @param bool  $checkType
  *
  * @return $this
  */
 public function setWith($value, $checkType = false)
 {
     parent::setWith($value, $checkType);
     if (self::isCrawler($this->value) === false) {
         $this->fail(sprintf($this->getLocale()->_('%s is not a crawler'), $this));
     } else {
         $this->pass();
     }
     return $this;
 }
Example #4
0
 /**
  * @param mixed       $value
  * @param string|null $selector
  *
  * @return $this
  */
 public function setWith($value, $selector = null)
 {
     parent::setWith($value, false);
     if (self::isCrawler($this->value) === false) {
         $this->fail(sprintf($this->getLocale()->_('%s is not a crawler'), $this));
     } else {
         $this->pass();
     }
     $this->selector = $selector;
     return $this;
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function setWith($value, $checkType = true)
 {
     parent::setWith($value, $checkType);
     if ($checkType === true) {
         if (self::isDataSource($this->value) === false) {
             $this->fail($this->getLocale()->_('%s is not an datasource', $this));
         } else {
             $this->pass();
         }
     }
     return $this;
 }
Example #6
0
 public function setWith($value, $checkType = true)
 {
     parent::setWith($value, false);
     if ($checkType === true) {
         if (self::isDateInterval($this->value) === true) {
             $this->pass();
         } else {
             $this->fail($this->_('%s is not an instance of \\dateInterval', $this));
         }
     }
     return $this;
 }
Example #7
0
 /**
  * @param mixed $value
  * @param bool  $checkType
  *
  * @return $this
  */
 public function setWith($value, $checkType = true)
 {
     parent::setWith($value, false);
     if ($checkType === true) {
         if (self::isResponse($this->value) === false) {
             $this->fail(sprintf($this->getLocale()->_('%s is not a response'), $this->getTypeOf($this->value)));
         } else {
             $this->pass();
         }
     }
     return $this;
 }
Example #8
0
 public function setWith($value, $checkType = true)
 {
     parent::setWith($value, false);
     if ($checkType === true) {
         if (self::isDateTime($this->value) === false) {
             $this->fail(sprintf($this->getLocale()->_('%s is not an instance of \\dateTime'), $this));
         } else {
             $this->pass();
         }
     }
     return $this;
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function setWith($value, $checkType = true)
 {
     parent::setWith($value, $checkType);
     if ($checkType === true) {
         if ($this->value instanceof EnumerableInterface) {
             $this->pass();
         } else {
             $this->fail($this->getLocale()->_('%s is not an enumerable', $this));
         }
     }
     return $this;
 }
 protected function matches($actual)
 {
     if ($this->analyzer->isArray($actual) === false && $actual instanceof \traversable === false) {
         throw new \PHPUnit_Framework_Exception('Actual value of ' . __CLASS__ . ' must be an array or a traversable object');
     }
     try {
         $asserter = new asserters\object(null, $this->analyzer);
         foreach ($actual as $value) {
             $asserter->setWith($value)->isInstanceOf($this->expected);
         }
     } catch (exceptions\logic $exception) {
         throw new \PHPUnit_Framework_Exception('Expected value of ' . __CLASS__ . ' must be a class instance or class name');
     }
 }
Example #11
0
 public function setWith($value, $label = null, $check = true)
 {
     $exception = $value;
     if ($exception instanceof \closure) {
         $exception = null;
         try {
             $value();
         } catch (\exception $exception) {
         }
     }
     parent::setWith($exception, $label, false);
     if ($check === true) {
         if (self::isException($exception) === false) {
             $this->fail(sprintf($this->getLocale()->_('%s is not an exception'), $this));
         } else {
             $this->pass();
         }
     }
     return $this;
 }
 public function setWith($value, $checkType = true)
 {
     $exception = $value;
     if ($exception instanceof \closure) {
         $exception = null;
         try {
             $value($this->getTest());
         } catch (\exception $exception) {
         }
     }
     parent::setWith($exception, false);
     if ($checkType === true) {
         if ($exception instanceof \exception === false) {
             $this->fail($this->_('%s is not an exception', $this));
         } else {
             $this->pass();
             static::$lastValue = $exception;
         }
     }
     return $this;
 }
 /**
  * @param Client $client
  * @param \closure $callback
  * @param Configuration $config
  *
  * @return $this
  */
 public function setWith($client, $callback = null, $config = null)
 {
     if (!$client instanceof Client) {
         $this->fail($this->_('%s is not a blackfire client', $this));
     }
     if (!$callback instanceof \closure) {
         $this->fail($this->_('%s is not a closure', $this));
     }
     if (!$config instanceof Configuration) {
         $this->fail($this->_('%s is not a profile configuration', $this));
     }
     try {
         $probe = $client->createProbe($config);
         $callback();
         $profile = $client->endProbe($probe);
     } catch (ExceptionInterface $e) {
         $this->fail($e->getMessage());
     }
     parent::setWith($profile);
     return $this;
 }
Example #14
0
 public function testToString()
 {
     $this->if($asserter = new asserters\object($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->toString();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Object is undefined')->if($asserter->setWith($this))->then->object($asserter->toString())->isInstanceOf('mageekguy\\atoum\\asserters\\castToString');
 }