123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
-
-
-
-
-
-
-
- class Yay_SimpleInvocation implements Yay_Invocation
- {
-
-
-
- private $_object;
-
-
-
- private $_method;
-
-
-
- private $_arguments;
-
-
-
- public function __construct($object, $method, array &$arguments)
- {
- $this->_object = $object;
-
- if ($method == '__call')
- {
- $method = array_shift($arguments);
- $args =& array_shift($arguments);
- $arguments =& $args;
- }
- $this->_method = $method;
- $this->_arguments =& $arguments;
- }
-
-
-
- public function getObject()
- {
- return $this->_object;
- }
-
-
-
- public function getMethod()
- {
- return $this->_method;
- }
-
-
-
- public function &getArguments()
- {
- return $this->_arguments;
- }
-
-
-
- public function describeTo(Yay_Description $description)
- {
- $description->appendText(sprintf(' of %s;', $this->_getInvocationSignature()));
- }
-
-
-
- private function _getInvocationSignature()
- {
- $class = Yay_MockGenerator::getInstance()
- ->reverseNamingScheme(get_class($this->_object));
- if (!empty($this->_arguments))
- {
- $args = array();
- foreach ($this->_arguments as $arg)
- {
- $args[] = $this->_describeArgument($arg, '%s [%s]');
- }
- $params = implode(', ', $args);
- }
- else
- {
- $params = '';
- }
- return sprintf('%s::%s(%s)', $class, $this->_method, $params);
- }
-
- private function _describeArgument($arg, $format)
- {
- $description = '';
- if (is_int($arg))
- {
- $description = sprintf($format, 'int', $arg);
- }
- elseif (is_float($arg))
- {
- $description = sprintf($format, 'float', preg_replace('/^(.{8}).+/', '$1..', $arg));
- }
- elseif (is_numeric($arg))
- {
- $description = sprintf($format, 'number', preg_replace('/^(.{8}).+/', '$1..', $arg));
- }
- elseif (is_string($arg))
- {
- $description = sprintf($format, 'string', preg_replace('/^(.{8}).+/', '$1..', $arg));
- }
- elseif (is_object($arg))
- {
- $description = sprintf($format, 'object', get_class($arg));
- }
- elseif (is_array($arg))
- {
- $description = sprintf($format, 'array', count($arg) . ' items');
- }
- else
- {
- $description = sprintf($format, gettype($arg), preg_replace('/^(.{8}).+/', '$1..', (string) $arg));
- }
- return $description;
- }
-
- }
|