/** * Constructor * * @param string|object $actual A fully-namespaced class name or an object instance. * @param string $expected The expected method method name to be called. */ public function __construct($actual, $expected) { $this->_backtrace = Debugger::backtrace(); if (is_string($actual)) { $actual = ltrim($actual, '\\'); } $this->_check($actual); if (!$expected) { throw new InvalidArgumentException("Method name can't be empty."); } $names = is_array($expected) ? $expected : [$expected]; $reference = $actual; if (count($names) > 1) { if (!Stub::registered(Suite::hash($reference))) { throw new InvalidArgumentException("Kahlan can't Spy chained methods on real PHP code, you need to Stub the chain first."); } } $reference = $this->_reference($reference); foreach ($names as $index => $name) { if (preg_match('/^::.*/', $name)) { $reference = is_object($reference) ? get_class($reference) : $reference; } $this->_expected[] = $name; $this->_messages[$name] = $this->_watch(new Message(['parent' => $this, 'reference' => $reference, 'name' => $name])); $reference = null; } }
/** * Constructor * * @param string|object $actual A fully-namespaced class name or an object instance. * @param string $expected The expected method method name to be called. */ public function __construct($actual) { $actual = ltrim($actual, '\\'); $this->_actual = $actual; Suite::register(Suite::hash($actual)); $this->_message = new Message(['name' => $actual]); $this->_backtrace = Debugger::backtrace(); }
/** * Constructor * * @param string|object $actual A fully-namespaced class name or an object instance. * @param string $expected The expected method method name to be called. */ public function __construct($actual, $expected) { if (preg_match('/^::.*/', $expected)) { $actual = is_object($actual) ? get_class($actual) : $actual; } $call = $this->_classes['call']; $this->_actual = $actual; $this->_expected = $expected; $this->_call = new $call($actual); $this->_message = $this->_call->method($expected); $this->_backtrace = Debugger::backtrace(); }
/** * Applies focus up to the root. */ protected function _emitFocus() { $this->_root->_focuses[] = Debugger::focus($this->backtraceFocus(), Debugger::backtrace()); $instances = $this->_parents(true); foreach ($instances as $instance) { $instance->focus(); } }
/** * Logs a result. * * @param boolean $boolean Set `true` for success and `false` for failure. * @param array $data Test details array. * @return boolean */ protected function _log($boolean, $data = []) { $not = $this->_not; $pass = $not ? !$boolean : $boolean; if ($pass) { $data['type'] = 'pass'; } else { $data['type'] = 'fail'; $this->_passed = false; } $description = $data['description']; if (is_array($description)) { $data['params'] = $description['params']; $data['description'] = $description['description']; } $data['backtrace'] = Debugger::backtrace(); $data['not'] = $not; $this->_logs[] = $data; $this->_not = false; return $boolean; }
/** * Helper which extracts the backtrace of a report. * * @param array $data The report data. */ public function _backtrace($data) { if (isset($data['exception'])) { return Debugger::backtrace(['trace' => $data['exception']]); } $type = $data['type']; $depth = $type === 'pass' || $type === 'fail' | $type === 'skip' ? 1 : null; if (!isset($data['backtrace'])) { $data['backtrace'] = []; } return Debugger::focus($this->scope()->backtraceFocus(), $data['backtrace'], $depth); }
/** * The Constructor. * * @param array $config The Suite config array. Options are: * -`'type'` _string_ : supported type are `'normal'` & `'focus'`. * -`'message'` _string_ : the description message. * -`'parent'` _object_ : the parent scope. * -`'root'` _object_ : the root scope. * -`'log'` _object_ : the log instance. * -`'timeout'` _integer_: the timeout. */ public function __construct($config = []) { $defaults = ['type' => 'normal', 'message' => '', 'parent' => null, 'root' => null, 'log' => null, 'timeout' => 0, 'summary' => null]; $config += $defaults; $this->_type = $config['type']; $this->_message = $config['message']; $this->_parent = $config['parent']; $this->_root = $this->_parent ? $this->_parent->_root : $this; $this->_timeout = $config['timeout']; $this->_backtrace = Debugger::focus($this->backtraceFocus(), Debugger::backtrace(), 1); $this->_log = $config['log'] ?: new Log(['scope' => $this, 'backtrace' => $this->_backtrace]); $this->_summary = $config['summary']; if ($this->_summary) { return; } if ($this->_root->summary()) { $this->_summary = $this->_root->summary(); } else { $this->_summary = new Summary(); } }