1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
<?php
// $Id: reflection_php5_test.php,v 1.15 2007/01/17 19:00:48 tswicegood Exp $
class AnyOldLeafClass {
function aMethod() { }
}
abstract class AnyOldClass {
function aMethod() { }
}
interface AnyOldInterface {
function aMethod();
}
interface AnyOldArgumentInterface {
function aMethod(AnyOldInterface $argument);
}
interface AnyDescendentInterface extends AnyOldInterface {
}
class AnyOldImplementation implements AnyOldInterface {
function aMethod() { }
function extraMethod() { }
}
abstract class AnyAbstractImplementation implements AnyOldInterface {
}
class AnyOldSubclass extends AnyOldImplementation { }
class AnyOldArgumentClass {
function aMethod($argument) { }
}
class AnyOldArgumentImplementation implements AnyOldArgumentInterface {
function aMethod(AnyOldInterface $argument) { }
}
class AnyOldTypeHintedClass implements AnyOldArgumentInterface {
function aMethod(AnyOldInterface $argument) { }
}
class AnyDescendentImplementation implements AnyDescendentInterface {
function aMethod() { }
}
class AnyOldOverloadedClass {
function __isset($key) { }
function __unset($key) { }
}
class TestOfReflection extends UnitTestCase {
function testClassExistence() {
$reflection = new SimpleReflection('AnyOldLeafClass');
$this->assertTrue($reflection->classOrInterfaceExists());
$this->assertTrue($reflection->classOrInterfaceExistsSansAutoload());
$this->assertFalse($reflection->isAbstract());
$this->assertFalse($reflection->isInterface());
}
function testClassNonExistence() {
$reflection = new SimpleReflection('UnknownThing');
$this->assertFalse($reflection->classOrInterfaceExists());
$this->assertFalse($reflection->classOrInterfaceExistsSansAutoload());
}
function testDetectionOfAbstractClass() {
$reflection = new SimpleReflection('AnyOldClass');
$this->assertTrue($reflection->isAbstract());
}
function testFindingParentClass() {
$reflection = new SimpleReflection('AnyOldSubclass');
$this->assertEqual($reflection->getParent(), 'AnyOldImplementation');
}
function testInterfaceExistence() {
$reflection = new SimpleReflection('AnyOldInterface');
$this->assertTrue(
$reflection->classOrInterfaceExists());
$this->assertTrue(
$reflection->classOrInterfaceExistsSansAutoload());
$this->assertTrue($reflection->isInterface());
}
function testMethodsListFromClass() {
$reflection = new SimpleReflection('AnyOldClass');
$this->assertIdentical($reflection->getMethods(), array('aMethod'));
}
function testMethodsListFromInterface() {
$reflection = new SimpleReflection('AnyOldInterface');
$this->assertIdentical($reflection->getMethods(), array('aMethod'));
$this->assertIdentical($reflection->getInterfaceMethods(), array('aMethod'));
}
function testMethodsComeFromDescendentInterfacesASWell() {
$reflection = new SimpleReflection('AnyDescendentInterface');
$this->assertIdentical($reflection->getMethods(), array('aMethod'));
}
function testCanSeparateInterfaceMethodsFromOthers() {
$reflection = new SimpleReflection('AnyOldImplementation');
$this->assertIdentical($reflection->getMethods(), array('aMethod', 'extraMethod'));
$this->assertIdentical($reflection->getInterfaceMethods(), array('aMethod'));
}
function testMethodsComeFromDescendentInterfacesInAbstractClass() {
$reflection = new SimpleReflection('AnyAbstractImplementation');
$this->assertIdentical($reflection->getMethods(), array('aMethod'));
}
function testInterfaceHasOnlyItselfToImplement() {
$reflection = new SimpleReflection('AnyOldInterface');
$this->assertEqual(
$reflection->getInterfaces(),
array('AnyOldInterface'));
}
function testInterfacesListedForClass() {
$reflection = new SimpleReflection('AnyOldImplementation');
$this->assertEqual(
$reflection->getInterfaces(),
array('AnyOldInterface'));
}
function testInterfacesListedForSubclass() {
$reflection = new SimpleReflection('AnyOldSubclass');
$this->assertEqual(
$reflection->getInterfaces(),
array('AnyOldInterface'));
}
function testNoParameterCreationWhenNoInterface() {
$reflection = new SimpleReflection('AnyOldArgumentClass');
$function = $reflection->getSignature('aMethod');
if (version_compare(phpversion(), '5.0.2', '<=')) {
$this->assertEqual('function amethod()', strtolower($function));
} else {
$this->assertEqual('function aMethod()', $function);
}
}
function testParameterCreationWithoutTypeHinting() {
$reflection = new SimpleReflection('AnyOldArgumentImplementation');
$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);
}
}
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);
}
}
function testIssetFunctionSignature() {
$reflection = new SimpleReflection('AnyOldOverloadedClass');
$function = $reflection->getSignature('__isset');
if (version_compare(phpversion(), '5.1.0', '>=')) {
$this->assertEqual('function __isset($key)', $function);
} else {
$this->assertEqual('function __isset()', $function);
}
}
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);
}
}
function testProperlyReflectsTheFinalInterfaceWhenObjectImplementsAnExtendedInterface() {
$reflection = new SimpleReflection('AnyDescendentImplementation');
$interfaces = $reflection->getInterfaces();
$this->assertEqual(1, count($interfaces));
$this->assertEqual('AnyDescendentInterface', array_shift($interfaces));
}
}
?>
|