lithium\test\Mocker::$_mockIngredients
A list of code to be generated for the Mock
.
The Mock class directly extends the class you wish to mock but only
interacts with the Delegate
directly. This class is the public
interface for users.
Source
protected static $_mockIngredients = [
'startClass' => [
'namespace {:namespace};',
'use lithium\aop\Filters as _Filters;',
'class Mock extends \{:mocker} {',
' public $mocker;',
' public $results = [];',
' public static $staticResults = [];',
' protected $_safeVars = [',
' "_classes",',
' "mocker",',
' "_safeVars",',
' "results",',
' "staticResults",',
' "_methodFilters",',
' ];',
],
'get' => [
'public function {:reference}__get($name) {',
' $data ={:reference} $this->mocker->$name;',
' return $data;',
'}',
],
'set' => [
'public function __set($name, $value = null) {',
' return $this->mocker->$name = $value;',
'}',
],
'isset' => [
'public function __isset($name) {',
' return isset($this->mocker->$name);',
'}',
],
'unset' => [
'public function __unset($name) {',
' unset($this->mocker->$name);',
'}',
],
'constructor' => [
'{:modifiers} function __construct({:args}) {',
' $args = compact({:stringArgs});',
' array_push($args, $this);',
' foreach (get_class_vars(get_class($this)) as $key => $value) {',
' if (isset($this->{$key}) && !in_array($key, $this->_safeVars)) {',
' unset($this->$key);',
' }',
' }',
' $class = new \ReflectionClass(\'{:namespace}\MockDelegate\');',
' $class->newInstanceArgs($args);',
'}',
],
'destructor' => [
'public function __destruct() {}',
],
'staticMethod' => [
'{:modifiers} function {:method}({:args}) {',
' $args = compact({:stringArgs});',
' $args["hash"] = "1f3870be274f6c49b3e31a0c6728957f";',
' $method = \'{:namespace}\MockDelegate::{:method}\';',
' $result = _Filters::run(__CLASS__, "{:method}", $args,',
' function($args) use(&$method) {',
' return call_user_func_array($method, $args);',
' }',
' );',
' if (!isset(static::$staticResults["{:method}"])) {',
' static::$staticResults["{:method}"] = [];',
' }',
' static::$staticResults["{:method}"][] = [',
' "args" => func_get_args(),',
' "result" => $result,',
' "time" => microtime(true),',
' ];',
' return $result;',
'}',
],
'method' => [
'{:modifiers} function {:method}({:args}) {',
' $args = compact({:stringArgs});',
' $args["hash"] = spl_object_hash($this->mocker);',
' $_method = [$this->mocker, "{:method}"];',
' $result = _Filters::run(__CLASS__, "{:method}", $args,',
' function($args) use(&$_method) {',
' return call_user_func_array($_method, $args);',
' }',
' );',
' if (!isset($this->results["{:method}"])) {',
' $this->results["{:method}"] = [];',
' }',
' $this->results["{:method}"][] = [',
' "args" => func_get_args(),',
' "result" => $result,',
' "time" => microtime(true),',
' ];',
' return $result;',
'}',
],
'applyFilter' => [
'public {:static} function applyFilter($method, $filter = null) {',
' $message = "<mocked class>::applyFilter() is deprecated. ";',
' $message .= "Use Filters::applyFilter(" . __CLASS__ .", ...) instead.";',
' // trigger_error($message, E_USER_DEPRECATED);',
' foreach ((array) $method as $m) {',
' if ($filter === null) {',
' _Filters::clear(__CLASS__, $m);',
' } else {',
' _Filters::apply(__CLASS__, $m, $filter);',
' }',
' }',
'}',
],
'endClass' => [
'}',
],
];