[TASK] Add possibility creating accessible mock for abstract classes 52/27252/2
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Tue, 12 Nov 2013 15:09:30 +0000 (16:09 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 9 Feb 2014 18:27:59 +0000 (19:27 +0100)
Resolves: #53564
Releases: 6.0, 6.1, 6.2
Change-Id: If7d69e4f87e368c1eef672cb68f1af92d6ae501b
Reviewed-on: https://review.typo3.org/27252
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/core/Tests/BaseTestCase.php

index 6925173..bc667e3 100644 (file)
@@ -83,6 +83,40 @@ abstract class BaseTestCase extends \PHPUnit_Framework_TestCase {
        }
 
        /**
+        * Returns a mock object which allows for calling protected methods and access
+        * of protected properties.
+        *
+        * @param string $originalClassName Full qualified name of the original class
+        * @param array $arguments
+        * @param string $mockClassName
+        * @param boolean $callOriginalConstructor
+        * @param boolean $callOriginalClone
+        * @param boolean $callAutoload
+        *
+        * @throws \InvalidArgumentException
+        *
+        * @return \PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
+        *
+        */
+       protected function getAccessibleMockForAbstractClass(
+               $originalClassName, array $arguments = array(), $mockClassName = '',
+               $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE
+       ) {
+               if ($originalClassName === '') {
+                       throw new \InvalidArgumentException('$originalClassName must not be empty.', 1384268260);
+               }
+
+               return $this->getMockForAbstractClass(
+                       $this->buildAccessibleProxy($originalClassName),
+                       $arguments,
+                       $mockClassName,
+                       $callOriginalConstructor,
+                       $callOriginalClone,
+                       $callAutoload
+               );
+       }
+
+       /**
         * Creates a proxy class of the specified class which allows
         * for calling even protected methods and access of protected properties.
         *
@@ -211,4 +245,4 @@ abstract class BaseTestCase extends \PHPUnit_Framework_TestCase {
                return $reflectionMethod->invokeArgs($object, $arguments);
        }
 }
-?>
\ No newline at end of file
+?>