本文整理汇总了PHP中SimpleReflection类的典型用法代码示例。如果您正苦于以下问题:PHP SimpleReflection类的具体用法?PHP SimpleReflection怎么用?PHP SimpleReflection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleReflection类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ignoreParentsIfIgnored
/**
* 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);
}
}
}
}
示例2: ignoreParentsIfIgnored
/**
* 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);
}
}
}
}
示例3: testMostGeneralPossibleSignature
function testMostGeneralPossibleSignature()
{
$reflection = new SimpleReflection('AnyOldThing');
$this->assertEqualIgnoringCase($reflection->getSignature('aMethod'), 'function &aMethod()');
}
示例4: testParameterCreationForTypeHinting
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);
}
}
示例5: _createHandlerCode
/**
* 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;
}
示例6: testUnsetFunctionSignature
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);
}
}
示例7: selectRunnableTests
/**
* 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;
}
示例8: createNewMethodCode
/**
* 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;
}
示例9: _selectRunnableTests
/**
* 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;
}
示例10: testCanProperlyGenerateAbstractMethods
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'));
}
示例11: testCopingWithSpecialMethodunsetPHP51
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')));
}
示例12: selectRunnableTests
/**
* 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;
}
示例13: testParameterCreationForTypeHinting
function testParameterCreationForTypeHinting()
{
$reflection = new SimpleReflection('AnyOldTypeHintedClass');
$function = $reflection->getSignature('aMethod');
$this->assertEqual('function aMethod(SimpleTest $argument)', $function);
}