Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Merge [4595].

  • Loading branch information...
commit 1e4efc6e25cd24fbefc4cd11ce6c67c750d9c7e4 1 parent d5b1e3a
@sebastianbergmann authored
Showing with 55 additions and 1 deletion.
  1. +55 −1 PHPUnit/Framework/TestCase.php
View
56 PHPUnit/Framework/TestCase.php
@@ -891,7 +891,7 @@ protected function setLocale()
/**
* Returns a mock object for the specified class.
*
- * @param string $className
+ * @param string $originalClassName
* @param array $methods
* @param array $arguments
* @param string $mockClassName
@@ -899,6 +899,7 @@ protected function setLocale()
* @param boolean $callOriginalClone
* @param boolean $callAutoload
* @return object
+ * @throws InvalidArgumentException
* @since Method available since Release 3.0.0
*/
protected function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE)
@@ -958,6 +959,59 @@ protected function getMock($originalClassName, $methods = array(), array $argume
}
/**
+ * Returns a mock object for the specified abstract class with all abstract
+ * methods of the class mocked. Concrete methods are not mocked.
+ *
+ * @param string $originalClassName
+ * @param array $arguments
+ * @param string $mockClassName
+ * @param boolean $callOriginalConstructor
+ * @param boolean $callOriginalClone
+ * @param boolean $callAutoload
+ * @return object
+ * @since Method available since Release 3.4.0
+ * @throws InvalidArgumentException
+ */
+ protected function getMockForAbstractClass($originalClassName, array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE)
+ {
+ if (!is_string($originalClassName)) {
+ throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
+ }
+
+ if (!is_string($mockClassName)) {
+ throw PHPUnit_Util_InvalidArgumentHelper::factory(4, 'string');
+ }
+
+ if (class_exists($originalClassName, $callAutoload)) {
+ $methods = array();
+ $reflector = new ReflectionClass($originalClassName);
+
+ foreach ($reflector->getMethods() as $method) {
+ if ($method->isAbstract()) {
+ $methods[] = $method->getName();
+ }
+ }
+
+ return $this->getMock(
+ $originalClassName,
+ $methods,
+ $arguments,
+ $mockClassName,
+ $callOriginalConstructor,
+ $callOriginalClone,
+ $callAutoload
+ );
+ } else {
+ throw new RuntimeException(
+ sprintf(
+ 'Class "%s" does not exist.',
+ $originalClassName
+ )
+ );
+ }
+ }
+
+ /**
* Returns a mock object based on the given WSDL file.
*
* @param string $wsdlFile
Please sign in to comment.
Something went wrong with that request. Please try again.