/** * Scans the now complete ignore list, and adds * all parent classes to the list. If a class * is not a runnable test case, then it's parents * wouldn't be either. This is syntactic sugar * to cut down on ommissions of ignore()'s or * missing abstract declarations. This cannot * be done whilst loading classes wiithout forcing * a particular order on the class declarations and * the ignore() calls. It's just nice to have the ignore() * calls at the top of the file before the actual declarations. * @param array $classes Class names of interest. * @static * @access public */ function ignoreParentsIfIgnored($classes) { $registry = &SimpleTest::_getRegistry(); foreach ($classes as $class) { if (SimpleTest::isIgnored($class)) { $reflection = new SimpleReflection($class); if ($parent = $reflection->getParent()) { SimpleTest::ignore($parent); } } } }
/** * Scans the now complete ignore list, and adds * all parent classes to the list. If a class * is not a runnable test case, then it's parents * wouldn't be either. This is syntactic sugar * to cut down on ommissions of ignore()'s or * missing abstract declarations. This cannot * be done whilst loading classes wiithout forcing * a particular order on the class declarations and * the ignore() calls. It's just nice to have the ignore() * calls at the top of the file before the actual declarations. * @param array $classes Class names of interest. */ public static function ignoreParentsIfIgnored($classes) { foreach ($classes as $class) { if (SimpleTest::isIgnored($class)) { $reflection = new SimpleReflection($class); $parent = $reflection->getParent(); if ($parent) { SimpleTest::ignore($parent); } } } }
function testMostGeneralPossibleSignature() { $reflection = new SimpleReflection('AnyOldThing'); $this->assertEqualIgnoringCase($reflection->getSignature('aMethod'), 'function &aMethod()'); }
function testParameterCreationForTypeHinting() { $reflection = new SimpleReflection('AnyOldTypeHintedClass'); $function = $reflection->getSignature('aMethod'); if (version_compare(phpversion(), '5.0.2', '<=')) { $this->assertEqual('function amethod(AnyOldInterface $argument)', $function); } else { $this->assertEqual('function aMethod(AnyOldInterface $argument)', $function); } }
/** * Creates code within a class to generate replaced * methods. All methods call the _invoke() handler * with the method name and the arguments in an * array. * @param array $methods Additional methods. * @access private */ function _createHandlerCode($methods) { $code = ''; $methods = array_merge($methods, $this->_reflection->getMethods()); foreach ($methods as $method) { if ($this->_isConstructor($method)) { continue; } $mock_reflection = new SimpleReflection($this->_mock_base); if (in_array($method, $mock_reflection->getMethods())) { continue; } $code .= " " . $this->_reflection->getSignature($method) . " {\n"; $code .= " \$args = func_get_args();\n"; $code .= " \$result = &\$this->_invoke(\"{$method}\", \$args);\n"; $code .= " return \$result;\n"; $code .= " }\n"; } return $code; }
function testUnsetFunctionSignature() { $reflection = new SimpleReflection('AnyOldOverloadedClass'); $function = $reflection->getSignature('__unset'); if (version_compare(phpversion(), '5.1.0', '>=')) { $this->assertEqual('function __unset($key)', $function); } else { $this->assertEqual('function __unset()', $function); } }
/** * Calculates the incoming test cases. Skips abstract * and ignored classes. * @param array $candidates Candidate classes. * @return array New classes which are test * cases that shouldn't be ignored. * @access public */ function selectRunnableTests($candidates) { $classes = array(); foreach ($candidates as $class) { if (TestSuite::getBaseTestCase($class)) { $reflection = new SimpleReflection($class); if ($reflection->isAbstract()) { SimpleTest::ignore($class); } else { $classes[] = $class; } } } return $classes; }
/** * Creates code within a class to generate a new * methods. All methods call the invoke() handler * on the internal mock with the method name and * the arguments in an array. * @param array $methods Additional methods. */ protected function createNewMethodCode($methods) { $code = ''; foreach ($methods as $method) { if ($this->isConstructor($method)) { continue; } $mock_reflection = new SimpleReflection($this->mock_base); if (in_array($method, $mock_reflection->getMethods())) { continue; } $code .= " " . $this->reflection->getSignature($method) . " {\n"; $code .= " \$args = func_get_args();\n"; $code .= " \$result = &\$this->mock->invoke(\"{$method}\", \$args);\n"; $code .= " return \$result;\n"; $code .= " }\n"; } return $code; }
/** * Calculates the incoming test cases from a before * and after list of loaded classes. Skips abstract * classes. * @param array $existing_classes Classes before require(). * @param array $new_classes Classes after require(). * @return array New classes which are test * cases that shouldn't be ignored. * @access private */ function _selectRunnableTests($existing_classes, $new_classes) { $classes = array(); foreach ($new_classes as $class) { if (in_array($class, $existing_classes)) { continue; } if ($this->_getBaseTestCase($class)) { $reflection = new SimpleReflection($class); if ($reflection->isAbstract()) { SimpleTest::ignore($class); } $classes[] = $class; } } return $classes; }
function testCanProperlyGenerateAbstractMethods() { $reflection = new SimpleReflection('AnyOldAbstractClassWithAbstractMethods'); $this->assertEqual('function anAbstract()', $reflection->getSignature('anAbstract')); $this->assertEqual('function anAbstractWithParameter($foo)', $reflection->getSignature('anAbstractWithParameter')); $this->assertEqual('function anAbstractWithMultipleParameters($foo, $bar)', $reflection->getSignature('anAbstractWithMultipleParameters')); }
function testCopingWithSpecialMethodunsetPHP51() { $reflection = new SimpleReflection('AnyOldClassInvokingMethodsWithArgumentsInConstructor'); $this->assertEqual('function __unset($key)', $reflection->getSignature('__unset')); $this->assertEqual('function __unset($key)', $reflection->getSignature('__unset', SIG_GEN_DECLARE)); $this->assertEqual('parent::__unset($key)', $reflection->getSignature('__unset', SIG_GEN_INVOKE_AS_PARENT)); $this->expectError(new PatternExpectation('/Reflection does not \\(yet\\) support mode ' . SIG_GEN_ASSIGN_ONLY_THE_ARGS . ' for __unset/')); $this->assertEqual('$key', $reflection->getSignature('__unset', SIG_GEN_DECLARE_ONLY_THE_ARGS)); $this->assertEqual('$key', $reflection->getSignature('__unset', SIG_GEN_INVOKE_ONLY_THE_ARGS)); $this->assertEqual('', $reflection->getSignature('__unset', SIG_GEN_ASSIGN_ONLY_THE_ARGS)); $this->expectError(new PatternExpectation('/Reflection does not \\(yet\\) support mode ' . SIG_GEN_ASSIGN_ONLY_THE_ARGS . ' for __unset/')); $this->expectError(new PatternExpectation('/Reflection does not \\(yet\\) support mode ' . SIG_GEN_ASSIGN_ONLY_THE_ARGS . ' for __unset/')); $this->expectError(new PatternExpectation('/Reflection does not \\(yet\\) support mode ' . SIG_GEN_ASSIGN_ONLY_THE_ARGS . ' for __unset/')); $this->assertEqual('function __unset($key)', $reflection->getSignature('__unset', SIG_GEN_DECLARE, array('assign' => array('arg1' => 'A10', 'arg2' => 'B20')))); $this->assertEqual('parent::__unset($key)', $reflection->getSignature('__unset', SIG_GEN_INVOKE_AS_PARENT, array('assign' => array('arg1' => 'A10', 'arg2' => 'B20')))); $this->assertEqual('', $reflection->getSignature('__unset', SIG_GEN_ASSIGN_ONLY_THE_ARGS, array('assign' => array('arg1' => 'A10', 'arg2' => 'B20')))); $this->assertEqual('PREFIX::$key::POSTFIX', $reflection->getSignature('__unset', SIG_GEN_DECLARE_ONLY_THE_ARGS, array('prefix' => 'PREFIX::', 'postfix' => '::POSTFIX'))); $this->assertEqual('PREFIX::$key::POSTFIX', $reflection->getSignature('__unset', SIG_GEN_INVOKE_ONLY_THE_ARGS, array('prefix' => 'PREFIX::', 'postfix' => '::POSTFIX'))); $this->assertEqual('', $reflection->getSignature('__unset', SIG_GEN_ASSIGN_ONLY_THE_ARGS, array('prefix' => 'PREFIX::', 'postfix' => '::POSTFIX'))); $this->assertEqual('', $reflection->getSignature('__unset', SIG_GEN_ASSIGN_ONLY_THE_ARGS, array('assign' => array('arg1' => 'A10', 'arg2' => 'B20'), 'prefix' => 'PREFIX::', 'postfix' => '::POSTFIX'))); $this->assertEqual('PREFIX::$key::POSTFIX', $reflection->getSignature('__unset', SIG_GEN_DECLARE_ONLY_THE_ARGS, array('assign' => array('arg1' => 'A10'), 'prefix' => 'PREFIX::', 'postfix' => '::POSTFIX'))); }
/** * Calculates the incoming test cases. Skips abstract * and ignored classes. * @param array $candidates Candidate classes. * @return array New classes which are test * cases that shouldn't be ignored. * @access public */ function selectRunnableTests($candidates) { $classes = array(); foreach ($candidates as $class) { if (TestSuite::getBaseTestCase($class)) { $reflection = new SimpleReflection($class); if ($reflection->isAbstract()) { SimpleTest::ignore($class); } else { // only pick classes which do have test methods we can run: $methods = $reflection->getMethods(); foreach ($methods as $method) { if (SimpleTestCase::isTest($class, $method)) { $classes[] = $class; break; } } } } } return $classes; }
function testParameterCreationForTypeHinting() { $reflection = new SimpleReflection('AnyOldTypeHintedClass'); $function = $reflection->getSignature('aMethod'); $this->assertEqual('function aMethod(SimpleTest $argument)', $function); }