Changeset 19781
- Timestamp:
- 07/01/09 12:59:46 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfLimeExtraPlugin/trunk/lib/mock/lime_mock.class.php
r19555 r19781 177 177 foreach ($class->getMethods() as $method) 178 178 { 179 /* @var $method ReflectionMethod */ 180 $modifiers = Reflection::getModifierNames($method->getModifiers()); 181 $modifiers = array_diff($modifiers, array('abstract')); 182 $modifiers = implode(' ', $modifiers); 183 184 $parameters = array(); 185 186 foreach ($method->getParameters() as $parameter) 179 if (!in_array($method->getName(), array('__construct', '__call', '__lime_getControl'))) 187 180 { 188 /* @var $parameter ReflectionParameter */ 189 if ($parameter->getClass()) 181 /* @var $method ReflectionMethod */ 182 $modifiers = Reflection::getModifierNames($method->getModifiers()); 183 $modifiers = array_diff($modifiers, array('abstract')); 184 $modifiers = implode(' ', $modifiers); 185 186 $parameters = array(); 187 188 foreach ($method->getParameters() as $parameter) 190 189 { 191 $typeHint = $parameter->getClass()->getName(); 190 /* @var $parameter ReflectionParameter */ 191 if ($parameter->getClass()) 192 { 193 $typeHint = $parameter->getClass()->getName(); 194 } 195 else if ($parameter->isArray()) 196 { 197 $typeHint = 'array'; 198 } 199 else 200 { 201 $typeHint = ''; 202 } 203 204 $name = '$'.$parameter->getName(); 205 206 if ($parameter->isOptional()) 207 { 208 $default = var_export($parameter->getDefaultValue(), true); 209 $parameters[] = sprintf(self::$parameterWithDefaultTemplate, $typeHint, $name, $default); 210 } 211 else 212 { 213 $parameters[] = sprintf(self::$parameterTemplate, $typeHint, $name); 214 } 192 215 } 193 else if ($parameter->isArray()) 194 { 195 $typeHint = 'array'; 196 } 197 198 $name = '$'.$parameter->getName(); 199 200 if ($parameter->isOptional()) 201 { 202 $default = var_export($parameter->getDefaultValue(), true); 203 $parameters[] = sprintf(self::$parameterWithDefaultTemplate, $typeHint, $name, $default); 204 } 205 else 206 { 207 $parameters[] = sprintf(self::$parameterTemplate, $typeHint, $name); 208 } 216 217 $methods .= sprintf(self::$methodTemplate, $modifiers, $method->getName(), 218 implode(', ', $parameters), $method->getName()); 209 219 } 210 211 $methods .= sprintf(self::$methodTemplate, $modifiers, $method->getName(),212 implode(', ', $parameters), $method->getName());213 220 } 214 221 plugins/sfLimeExtraPlugin/trunk/test/unit/mock/lime_mockTest.php
r19743 r19781 33 33 } 34 34 35 class TestClassWithConstructor 36 { 37 public static $calls = 0; 38 39 public function __construct() 40 { 41 self::$calls++; 42 } 43 } 44 35 45 class TestClass 36 46 { … … 46 56 47 57 48 $t = new lime_test_simple( 47, new lime_output_color());58 $t = new lime_test_simple(50, new lime_output_color()); 49 59 50 60 … … 85 95 $t->ok($m instanceof FoobarClass, 'The mock generates and inherits the class'); 86 96 $t->ok($m instanceof lime_mock_interface, 'The mock implements "lime_mock_interface"'); 97 98 99 // @Test: Classes with constructors can be mocked 100 101 $m = lime_mocK::create('TestClassWithConstructor'); 102 // assertions 103 $t->ok($m instanceof TestClassWithConstructor, 'The mock generates and inherits the class'); 104 $t->ok($m instanceof lime_mock_interface, 'The mock implements "lime_mock_interface"'); 105 $t->is(TestClassWithConstructor::$calls, 0, 'The original constructor was not called'); 87 106 88 107

