introspector = new Zend_Amf_Adobe_Introspector(); } public function testIntrospectionDoesNotIncludeConstructor() { $xml = $this->introspector->introspect('com.zend.framework.IntrospectorTest'); $this->assertNotContains('__construct', $xml); } public function testIntrospectionDoesNotIncludeMagicMethods() { $xml = $this->introspector->introspect('com.zend.framework.IntrospectorTest'); $this->assertNotContains('__get', $xml); } public function testIntrospectionContainsPublicPropertiesOfReturnClassTypes() { $xml = $this->introspector->introspect('com.zend.framework.IntrospectorTest'); $this->assertRegexp('/]*(name="com_zend_framework_IntrospectorTestCustomType")/', $xml, $xml); $this->assertRegexp('/]*(name="foo")/', $xml, $xml); $this->assertRegexp('/]*(type="string")/', $xml, $xml); } public function testIntrospectionDoesNotContainNonPublicPropertiesOfReturnClassTypes() { $xml = $this->introspector->introspect('com.zend.framework.IntrospectorTest'); $this->assertNotRegexp('/]*(name="_bar")/', $xml, $xml); } public function testIntrospectionContainsPublicMethods() { $xml = $this->introspector->introspect('com.zend.framework.IntrospectorTest'); $this->assertRegexp('/]*(name="foobar")/', $xml, $xml); $this->assertRegexp('/]*(name="barbaz")/', $xml, $xml); $this->assertRegexp('/]*(name="bazbat")/', $xml, $xml); } public function testIntrospectionContainsOperationForEachPrototypeOfAPublicMethod() { $xml = $this->introspector->introspect('com.zend.framework.IntrospectorTest'); $this->assertEquals(4, substr_count($xml, 'name="foobar"')); $this->assertEquals(1, substr_count($xml, 'name="barbaz"')); $this->assertEquals(1, substr_count($xml, 'name="bazbat"')); } public function testPassingDirectoriesOptionShouldResolveServiceClassAndType() { require_once dirname(__FILE__) . '/_files/ZendAmfAdobeIntrospectorTestType.php'; $xml = $this->introspector->introspect('ZendAmfAdobeIntrospectorTest', array( 'directories' => array(dirname(__FILE__) . '/_files'), )); $this->assertRegexp('/]*(name="foo")/', $xml, $xml); $this->assertRegexp('/]*(name="ZendAmfAdobeIntrospectorTestType")/', $xml, $xml); $this->assertRegexp('/]*(name="bar")/', $xml, $xml); } public function testMissingPropertyDocblockInTypedClassShouldReportTypeAsUnknown() { $xml = $this->introspector->introspect('com.zend.framework.IntrospectorTest'); if (!preg_match('/(]*(name="baz")[^>]*>)/', $xml, $matches)) { $this->fail('Baz property of com.zend.framework.IntrospectorTestCustomType not found'); } $node = $matches[1]; $this->assertContains('type="Unknown"', $node, $node); } public function testPropertyDocblockWithoutAnnotationInTypedClassShouldReportTypeAsUnknown() { $xml = $this->introspector->introspect('com.zend.framework.IntrospectorTest'); if (!preg_match('/(]*(name="bat")[^>]*>)/', $xml, $matches)) { $this->fail('Bat property of com.zend.framework.IntrospectorTestCustomType not found'); } $node = $matches[1]; $this->assertContains('type="Unknown"', $node, $node); } public function testTypedClassWithExplicitTypeShouldReportAsThatType() { $xml = $this->introspector->introspect('com.zend.framework.IntrospectorTest'); $this->assertRegexp('/]*(name="explicit")/', $xml, $xml); } } class com_zend_framework_IntrospectorTest { /** * Constructor * * @return void */ public function __construct() { } /** * Overloading: get properties * * @param string $name * @return mixed */ public function __get($name) { $prop = '_' . $name; if (!isset($this->$prop)) { return null; } return $this->$prop; } /** * Foobar * * @param string|int $arg * @return string|stdClass */ public function foobar($arg) { } /** * Barbaz * * @param com_zend_framework_IntrospectorTestCustomType $arg * @return boolean */ public function barbaz($arg) { } /** * Bazbat * * @return com_zend_framework_IntrospectorTestExplicitType */ public function bazbat() { } } class com_zend_framework_IntrospectorTestCustomType { /** * @var string */ public $foo; public $baz; /** * Docblock without an annotation */ public $bat; /** * @var bool */ protected $_bar; } class com_zend_framework_IntrospectorTestExplicitType { public $_explicitType = 'explicit'; } // Call Zend_Amf_Adobe_IntrospectorTest::main() if this source file is executed directly. if (PHPUnit_MAIN_METHOD == "Zend_Amf_Adobe_IntrospectorTest::main") { Zend_Amf_Adobe_IntrospectorTest::main(); }