diff --git a/src/TUnit/framework/mock/MockInvocation.php b/src/TUnit/framework/mock/MockInvocation.php index d71d6b3..3fd45e5 100644 --- a/src/TUnit/framework/mock/MockInvocation.php +++ b/src/TUnit/framework/mock/MockInvocation.php @@ -1,12 +1,64 @@ className = $className; $this->method = $methodName; @@ -14,18 +66,54 @@ $this->count = $count; } + /** + * Gets the name of the method + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return string + */ public function getMethod() { return $this->method; } + /** + * Gets the arguments + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return array + */ public function getArgs() { return $this->args; } + /** + * Gets the name of the class + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return mixed + */ public function getClass() { return $this->className; } + /** + * Gets the count + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return mixed + */ public function getCount() { return $this->count; } diff --git a/src/TUnit/framework/mock/MockObjectCreator.php b/src/TUnit/framework/mock/MockObjectCreator.php index 4abc910..c3a8aa0 100644 --- a/src/TUnit/framework/mock/MockObjectCreator.php +++ b/src/TUnit/framework/mock/MockObjectCreator.php @@ -1,15 +1,60 @@ referenceObject->hasMethod($methodName)) { @@ -58,10 +117,35 @@ return $this; } - protected function methodIsMockable(ReflectionMethod $method) { + /** + * Determines if a method is mockable + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param ReflectionMethod $method + * @return bool + */ + protected final function methodIsMockable(ReflectionMethod $method) { return !$method->isFinal() && !$method->isPrivate() && !$method->isStatic(); } + /** + * Generates the mock object + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses generateClassDefinition() + * @uses MockRegistry::addClass() + * + * @param array $constructorArgs Arguments to pass to the constructor + * @param string $name Custom name to give the newly created mock object, by default + * a random, unused name is chosen + * @throws LogicException if a name is given that is already in use + * @return object + */ public function generate(array $constructorArgs = array(), $name = '') { if (empty($name)) { $className = $this->referenceObject->getName(); @@ -71,7 +155,7 @@ } if (class_exists($name) || interface_exists($name)) { - throw new RuntimeException('Cannot use the name "' . $name . '" for mock object because the class or interface already exists'); + throw new LogicException('Cannot use the name "' . $name . '" for mock object because the class or interface already exists'); } $code = $this->generateClassDefinition($name); @@ -84,6 +168,17 @@ return $obj; } + /** + * Generates the class definition of the mock object + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses generateMethodDefinition() + * + * @param string $name The name of the class + * @return string Executable PHP code that will generate a class when eval()'d + */ protected function generateClassDefinition($name) { $code = 'class ' . $name . ' '; if ($this->referenceObject->isInterface()) { @@ -104,6 +199,18 @@ return $code; } + /** + * Generates a method definition + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param string $type "default" or "generic" + * @param string $name Name of the method + * @param array $methodData Should have keys "call_parent" and "body" + * @return string + */ protected function generateMethodDefinition($type, $name, array $methodData) { $modifier = 'public'; $params = ''; diff --git a/src/TUnit/framework/mock/MockRegistry.php b/src/TUnit/framework/mock/MockRegistry.php index 1f0314a..362413c 100644 --- a/src/TUnit/framework/mock/MockRegistry.php +++ b/src/TUnit/framework/mock/MockRegistry.php @@ -1,22 +1,85 @@ getInvocations() as $invocation) {