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 = array(
'startClass' => array(
'namespace {:namespace};',
'class Mock extends \{:mocker} {',
' public $mocker;',
' public $results = array();',
' public static $staticResults = array();',
' protected $_safeVars = array(',
' "_classes",',
' "_methodFilters",',
' "mocker",',
' "_safeVars",',
' "results",',
' "staticResults",',
' );',
),
'get' => array(
'public function {:reference}__get($name) {',
' $data ={:reference} $this->mocker->$name;',
' return $data;',
'}',
),
'set' => array(
'public function __set($name, $value = null) {',
' return $this->mocker->$name = $value;',
'}',
),
'isset' => array(
'public function __isset($name) {',
' return isset($this->mocker->$name);',
'}',
),
'unset' => array(
'public function __unset($name) {',
' unset($this->mocker->$name);',
'}',
),
'constructor' => array(
'{: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' => array(
'public function __destruct() {}',
),
'staticMethod' => array(
'{:modifiers} function {:method}({:args}) {',
' $args = compact({:stringArgs});',
' $args["hash"] = "1f3870be274f6c49b3e31a0c6728957f";',
' $method = \'{:namespace}\MockDelegate::{:method}\';',
' $result = {:master}::invokeMethod("_filter", array(',
' __CLASS__, ',
' "{:method}",',
' $args,',
' function($self, $args) use(&$method) {',
' return call_user_func_array($method, $args);',
' }',
' ));',
' if (!isset(self::$staticResults["{:method}"])) {',
' self::$staticResults["{:method}"] = array();',
' }',
' self::$staticResults["{:method}"][] = array(',
' "args" => func_get_args(),',
' "result" => $result,',
' "time" => microtime(true),',
' );',
' return $result;',
'}',
),
'method' => array(
'{:modifiers} function {:method}({:args}) {',
' $args = compact({:stringArgs});',
' $args["hash"] = spl_object_hash($this->mocker);',
' $method = array($this->mocker, "{:method}");',
' $result = {:master}::invokeMethod("_filter", array(',
' __CLASS__,',
' "{:method}",',
' $args,',
' function($self, $args) use(&$method) {',
' return call_user_func_array($method, $args);',
' }',
' ));',
' if (!isset($this->results["{:method}"])) {',
' $this->results["{:method}"] = array();',
' }',
' $this->results["{:method}"][] = array(',
' "args" => func_get_args(),',
' "result" => $result,',
' "time" => microtime(true),',
' );',
' return $result;',
'}',
),
'applyFilter' => array(
'public {:static} function applyFilter($method, $filter = null) {',
' return {:master}::applyFilter(__CLASS__, $method, $filter);',
'}',
),
'endClass' => array(
'}',
),
);