Tester\Assert::type PHP Method

type() public static method

Checks assertion.
public static type ( $type, $value, $description = NULL ) : void
return void
    public static function type($type, $value, $description = NULL)
    {
        self::$counter++;
        if (!is_object($type) && !is_string($type)) {
            throw new \Exception('Type must be a object or a string.');
        } elseif ($type === 'list') {
            if (!is_array($value) || $value && array_keys($value) !== range(0, count($value) - 1)) {
                self::fail(self::describe("%1 should be {$type}", $description), $value);
            }
        } elseif (in_array($type, ['array', 'bool', 'callable', 'float', 'int', 'integer', 'null', 'object', 'resource', 'scalar', 'string'], TRUE)) {
            if (!call_user_func("is_{$type}", $value)) {
                self::fail(self::describe(gettype($value) . " should be {$type}", $description));
            }
        } elseif (!$value instanceof $type) {
            $actual = is_object($value) ? get_class($value) : gettype($value);
            self::fail(self::describe("{$actual} should be instance of {$type}", $description));
        }
    }

Usage Example

Example #1
0
 /**
  * @param  string                $presenterName is fully qualified presenter name (module:module:presenter)
  * @param  string                $action
  * @param  string                $method
  * @param  array                 $params
  * @param  array                 $post
  * @return Application\IResponse
  */
 public function assertFormSubmitted($presenterName, $action, $method = 'GET', $params = array(), $post = array())
 {
     $presenter = $this->createPresenter($presenterName);
     $res = $this->processRequest($presenter, $presenterName, $action, $method, $params, $post);
     Assert::type('Nette\\Application\\Responses\\RedirectResponse', $res);
     return $res;
 }
All Usage Examples Of Tester\Assert::type