lithium\test\MockerChain::__call()
Validates that a given methodis called a set number of times.
Parameters
-
string
$comparison
Comparison type 'gt', 'gte', 'lt', 'lte', or 'eq'.
-
array
$args The first argument is the expected result.
Returns
objectSource
public function __call($comparison, $args) {
$methodExists = in_array($comparison, ['gt', 'gte', 'lt', 'lte', 'eq'], true);
if (!$this->_data['success'] || !$methodExists) {
return $this;
}
if (count($args) === 0 || !is_int($args[0])) {
$this->_data['success'] = false;
return $this;
}
$result = 0;
$expected = $args[0];
$method = $this->_data['method'];
$args = $this->_data['args'];
foreach ($this->_data['results'][$method] as $call) {
$correctTime = $this->_data['callTime'] <= $call['time'];
$correctArgs = !is_array($args) || $args === $call['args'];
if ($correctTime && $correctArgs) {
$this->_data['callTime'] = $call['time'];
$result++;
}
}
switch ($comparison) {
case 'gt':
$this->_data['success'] = $result > $expected;
break;
case 'gte':
$this->_data['success'] = $result >= $expected;
break;
case 'lt':
$this->_data['success'] = $result < $expected;
break;
case 'lte':
$this->_data['success'] = $result <= $expected;
break;
case 'eq':
$this->_data['success'] = $result === $expected;
break;
}
return $this;
}