[BUGFIX] CLI argument handling chokes on = use
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / BaseTestCase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Base testcase for the Extbase extension.
30 */
31 abstract class Tx_Extbase_Tests_Unit_BaseTestCase extends tx_phpunit_testcase {
32
33 /**
34 * @var Tx_Extbase_Object_ObjectManagerInterface The object manager
35 */
36 protected $objectManager;
37
38 /**
39 * Injects an untainted clone of the object manager and all its referencing
40 * objects for every test.
41 *
42 * @return void
43 */
44 public function runBare() {
45 $objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
46 $this->objectManager = clone $objectManager;
47 parent::runBare();
48 }
49
50 /**
51 * Returns a mock object which allows for calling protected methods and access
52 * of protected properties.
53 *
54 * @param string $originalClassName
55 * @param array $methods
56 * @param array $arguments
57 * @param string $mockClassName
58 * @param boolean $callOriginalConstructor
59 * @param boolean $callOriginalClone
60 * @param boolean $callAutoload
61 * @return object
62 * @author Robert Lemke <robert@typo3.org>
63 * @api
64 */
65 protected function getAccessibleMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE) {
66 return $this->getMock($this->buildAccessibleProxy($originalClassName), $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload);
67 }
68
69
70 /**
71 * Creates a proxy class of the specified class which allows
72 * for calling even protected methods and access of protected properties.
73 *
74 * @param $className Full qualified name of the original class
75 * @return string Full qualified name of the built class
76 */
77 protected function buildAccessibleProxy($className) {
78 $accessibleClassName = uniqid('AccessibleTestProxy');
79 $class = new ReflectionClass($className);
80 $abstractModifier = $class->isAbstract() ? 'abstract ' : '';
81 eval('
82 ' . $abstractModifier . 'class ' . $accessibleClassName . ' extends ' . $className . ' {
83 public function _call($methodName) {
84 $args = func_get_args();
85 return call_user_func_array(array($this, $methodName), array_slice($args, 1));
86 }
87 public function _callRef($methodName, &$arg1 = NULL, &$arg2 = NULL, &$arg3 = NULL, &$arg4 = NULL, &$arg5= NULL, &$arg6 = NULL, &$arg7 = NULL, &$arg8 = NULL, &$arg9 = NULL) {
88 switch (func_num_args()) {
89 case 0 : return $this->$methodName();
90 case 1 : return $this->$methodName($arg1);
91 case 2 : return $this->$methodName($arg1, $arg2);
92 case 3 : return $this->$methodName($arg1, $arg2, $arg3);
93 case 4 : return $this->$methodName($arg1, $arg2, $arg3, $arg4);
94 case 5 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5);
95 case 6 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
96 case 7 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
97 case 8 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8);
98 case 9 : return $this->$methodName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8, $arg9);
99 }
100 }
101 public function _set($propertyName, $value) {
102 $this->$propertyName = $value;
103 }
104 public function _setRef($propertyName, &$value) {
105 $this->$propertyName = $value;
106 }
107 public function _get($propertyName) {
108 return $this->$propertyName;
109 }
110 }
111 ');
112 return $accessibleClassName;
113 }
114
115 }
116 ?>