Kahlan\Plugin\Double::classname PHP Method

classname() public static method

Creates a polyvalent static class.
public static classname ( array $options = [] ) : string
$options array Array of options. Options are: - `'class'` : the fully-namespaced class name. - `'extends'` : the fully-namespaced parent class name.
return string The created fully-namespaced class name.
    public static function classname($options = [])
    {
        $defaults = ['class' => 'Kahlan\\Spec\\Plugin\\Double\\Double' . static::$_index++];
        $options += $defaults;
        if (!static::$_pointcut) {
            $pointcut = static::$_classes['pointcut'];
            static::$_pointcut = new $pointcut();
        }
        if (!class_exists($options['class'], false)) {
            $parser = static::$_classes['parser'];
            $code = static::generate($options);
            $nodes = $parser::parse($code);
            $code = $parser::unparse(static::$_pointcut->process($nodes));
            eval('?>' . $code);
        }
        return $options['class'];
    }

Usage Example

示例#1
0
 /**
  * Sets the stub logic.
  *
  * @param mixed $substitute The logic.
  */
 public function toBeOK()
 {
     if (!is_string($this->_actual)) {
         throw new Exception("Error `toBeOK()` need to be applied on a fully-namespaced class or function name.");
     }
     if ($this->_isClass) {
         Monkey::patch($this->_actual, Double::classname());
     } else {
         Monkey::patch($this->_actual, function () {
         });
     }
 }
All Usage Examples Of Kahlan\Plugin\Double::classname