diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:36:21 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:36:21 -0400 |
| commit | d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (patch) | |
| tree | b38e2e5c6974b9a15f103e5cf884cba9fff90ef4 /ext/reflection/tests | |
| parent | a88a88d0986a4a32288c102cdbfebd78d7e91d99 (diff) | |
| download | php-upstream/5.2.0.tar.gz | |
Imported Upstream version 5.2.0upstream/5.2.0
Diffstat (limited to 'ext/reflection/tests')
| -rwxr-xr-x | ext/reflection/tests/008.phpt | 39 | ||||
| -rw-r--r-- | ext/reflection/tests/bug29986.phpt | 12 | ||||
| -rwxr-xr-x | ext/reflection/tests/bug37816.phpt | 28 | ||||
| -rwxr-xr-x | ext/reflection/tests/bug38132.phpt | 34 | ||||
| -rwxr-xr-x | ext/reflection/tests/bug38194.phpt | 13 | ||||
| -rw-r--r-- | ext/reflection/tests/bug38217.phpt | 40 | ||||
| -rw-r--r-- | ext/reflection/tests/bug38465.phpt | 66 | ||||
| -rw-r--r-- | ext/reflection/tests/bug38653.phpt | 28 | ||||
| -rwxr-xr-x | ext/reflection/tests/bug38942.phpt | 34 | ||||
| -rw-r--r-- | ext/reflection/tests/bug39001.phpt | 27 | ||||
| -rw-r--r-- | ext/reflection/tests/bug39067.phpt | 45 |
11 files changed, 360 insertions, 6 deletions
diff --git a/ext/reflection/tests/008.phpt b/ext/reflection/tests/008.phpt new file mode 100755 index 000000000..2abdcdb57 --- /dev/null +++ b/ext/reflection/tests/008.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionMethod::__construct() tests +--FILE-- +<?php + +$a = array("", 1, "::", "a::", "::b", "a::b"); + +foreach ($a as $val) { + try { + new ReflectionMethod($val); + } catch (Exception $e) { + var_dump($e->getMessage()); + } +} + +$a = array("", 1, ""); +$b = array("", "", 1); + +foreach ($a as $key=>$val) { + try { + new ReflectionMethod($val, $b[$key]); + } catch (Exception $e) { + var_dump($e->getMessage()); + } +} + +echo "Done\n"; +?> +--EXPECTF-- +string(20) "Invalid method name " +string(21) "Invalid method name 1" +string(21) "Class does not exist" +string(22) "Class a does not exist" +string(21) "Class does not exist" +string(22) "Class a does not exist" +string(21) "Class does not exist" +string(66) "The parameter class is expected to be either a string or an object" +string(21) "Class does not exist" +Done diff --git a/ext/reflection/tests/bug29986.phpt b/ext/reflection/tests/bug29986.phpt index 85bad6d6e..997bcf7cc 100644 --- a/ext/reflection/tests/bug29986.phpt +++ b/ext/reflection/tests/bug29986.phpt @@ -17,14 +17,14 @@ Reflection::export(new ReflectionClass('just_constants')); ?> --EXPECTF-- Class [ <user> class just_constants ] { - @@ %s + @@ %s %d-%d - Constants [5] { - Constant [ boolean BOOLEAN_CONSTANT ] { } - Constant [ null NULL_CONSTANT ] { } - Constant [ string STRING_CONSTANT ] { } - Constant [ integer INTEGER_CONSTANT ] { } - Constant [ double FLOAT_CONSTANT ] { } + Constant [ boolean BOOLEAN_CONSTANT ] { 1 } + Constant [ null NULL_CONSTANT ] { } + Constant [ string STRING_CONSTANT ] { This is a string } + Constant [ integer INTEGER_CONSTANT ] { 1000 } + Constant [ double FLOAT_CONSTANT ] { 3.14159265 } } - Static properties [0] { diff --git a/ext/reflection/tests/bug37816.phpt b/ext/reflection/tests/bug37816.phpt new file mode 100755 index 000000000..18a49046d --- /dev/null +++ b/ext/reflection/tests/bug37816.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #37816 (ReflectionProperty does not throw exception when accessing protected attribute) +--FILE-- +<?php + +class TestClass +{ + protected $p = 2; +} + +$o = new TestClass; + +$r = new ReflectionProperty($o, 'p'); + +try +{ + $x = $r->getValue($o); +} +catch (Exception $e) +{ + echo 'Caught: ' . $e->getMessage() . "\n"; +} + +?> +===DONE=== +--EXPECTF-- +Caught: Cannot access non-public member TestClass::p +===DONE=== diff --git a/ext/reflection/tests/bug38132.phpt b/ext/reflection/tests/bug38132.phpt new file mode 100755 index 000000000..aeb6246b8 --- /dev/null +++ b/ext/reflection/tests/bug38132.phpt @@ -0,0 +1,34 @@ +--TEST-- +Reflection Bug #38132 (ReflectionClass::getStaticProperties() retains \0 in key names) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php +class foo { + static protected $bar = 'baz'; + static public $a = 'a'; +} + +$class = new ReflectionClass('foo'); +$properties = $class->getStaticProperties(); +var_dump($properties, array_keys($properties)); +var_dump(isset($properties['*bar'])); +var_dump(isset($properties["\0*\0bar"])); +var_dump(isset($properties["bar"])); +?> +--EXPECT-- +array(2) { + ["bar"]=> + string(3) "baz" + ["a"]=> + string(1) "a" +} +array(2) { + [0]=> + string(3) "bar" + [1]=> + string(1) "a" +} +bool(false) +bool(false) +bool(true) diff --git a/ext/reflection/tests/bug38194.phpt b/ext/reflection/tests/bug38194.phpt new file mode 100755 index 000000000..5c888af59 --- /dev/null +++ b/ext/reflection/tests/bug38194.phpt @@ -0,0 +1,13 @@ +--TEST-- +Reflection Bug #38194 (ReflectionClass::isSubclassOf() returns TRUE for the class itself) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php +class Object { } + +$objectClass= new ReflectionClass('Object'); +var_dump($objectClass->isSubclassOf($objectClass)); +?> +--EXPECT-- +bool(false) diff --git a/ext/reflection/tests/bug38217.phpt b/ext/reflection/tests/bug38217.phpt new file mode 100644 index 000000000..55e0c4664 --- /dev/null +++ b/ext/reflection/tests/bug38217.phpt @@ -0,0 +1,40 @@ +--TEST-- +#38217 (ReflectionClass::newInstanceArgs() tries to allocate too much memory) +--FILE-- +<?php + +class Object { + public function __construct() { + } +} + +$class= new ReflectionClass('Object'); +var_dump($class->newInstanceArgs()); + +class Object1 { + public function __construct($var) { + var_dump($var); + } +} + +$class= new ReflectionClass('Object1'); +var_dump($class->newInstanceArgs()); +var_dump($class->newInstanceArgs(array('test'))); + + +echo "Done\n"; +?> +--EXPECTF-- +object(Object)#%d (0) { +} + +Warning: Missing argument 1 for Object1::__construct() in %s on line %d + +Notice: Undefined variable: var in %s on line %d +NULL +object(Object1)#%d (0) { +} +string(4) "test" +object(Object1)#%d (0) { +} +Done diff --git a/ext/reflection/tests/bug38465.phpt b/ext/reflection/tests/bug38465.phpt new file mode 100644 index 000000000..4947180e9 --- /dev/null +++ b/ext/reflection/tests/bug38465.phpt @@ -0,0 +1,66 @@ +--TEST-- +Reflection Bug #38465 (ReflectionParameter fails on access to self::) +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php +class Baz { + const B = 3; +} + +class Foo { + const X = 1; + public function x($a = self::X, $b = Baz::B, $c = 99) {} +} + +class Bar extends Foo { + const Y = 2; + public function y($a = self::Y, $b = Baz::B, $c = 99) {} +} + + +echo "From global scope:\n"; + +$clazz = new ReflectionClass('Bar'); +foreach ($clazz->getMethods() as $method) { + foreach ($method->getParameters() as $param) { + if ($param->isDefaultValueAvailable()) { + echo $method->getDeclaringClass()->getName(), '::', $method->getName(), '($', $param->getName(), ' = ', $param->getDefaultValue(), ")\n"; + } + } +} + +echo "\nFrom class context:\n"; + +class Test { + function __construct() { + $clazz = new ReflectionClass('Bar'); + foreach ($clazz->getMethods() as $method) { + foreach ($method->getParameters() as $param) { + if ($param->isDefaultValueAvailable()) { + echo $method->getDeclaringClass()->getName(), '::', $method->getName(), '($', $param->getName(), ' = ', $param->getDefaultValue(), ")\n"; + } + } + } + } +} + +new Test(); + +?> +--EXPECT-- +From global scope: +Bar::y($a = 2) +Bar::y($b = 3) +Bar::y($c = 99) +Foo::x($a = 1) +Foo::x($b = 3) +Foo::x($c = 99) + +From class context: +Bar::y($a = 2) +Bar::y($b = 3) +Bar::y($c = 99) +Foo::x($a = 1) +Foo::x($b = 3) +Foo::x($c = 99) diff --git a/ext/reflection/tests/bug38653.phpt b/ext/reflection/tests/bug38653.phpt new file mode 100644 index 000000000..68781d2ab --- /dev/null +++ b/ext/reflection/tests/bug38653.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #38653 (memory leak in ReflectionClass::getConstant()) +--FILE-- +<?php + +class foo { + const cons = 10; + const cons1 = ""; + const cons2 = "test"; +} + +class bar extends foo { +} + +$foo = new ReflectionClass("foo"); +var_dump($foo->getConstant("cons")); +var_dump($foo->getConstant("cons1")); +var_dump($foo->getConstant("cons2")); +var_dump($foo->getConstant("no such const")); + +echo "Done\n"; +?> +--EXPECTF-- +int(10) +string(0) "" +string(4) "test" +bool(false) +Done diff --git a/ext/reflection/tests/bug38942.phpt b/ext/reflection/tests/bug38942.phpt new file mode 100755 index 000000000..f66f2552b --- /dev/null +++ b/ext/reflection/tests/bug38942.phpt @@ -0,0 +1,34 @@ +--TEST--
+Bug #38942 (Double old-style-ctor inheritance)
+--FILE--
+<?php
+class foo {
+ public function foo() {}
+}
+
+class bar extends foo {
+}
+ReflectionClass::export("bar");
+?>
+--EXPECTF--
+Class [ <user> class bar extends foo ] {
+ @@ %sbug38942.php 6-7
+
+ - Constants [0] {
+ }
+
+ - Static properties [0] {
+ }
+
+ - Static methods [0] {
+ }
+
+ - Properties [0] {
+ }
+
+ - Methods [1] {
+ Method [ <user, inherits foo, ctor> public method foo ] {
+ @@ %sbug38942.php 3 - 3
+ }
+ }
+}
diff --git a/ext/reflection/tests/bug39001.phpt b/ext/reflection/tests/bug39001.phpt new file mode 100644 index 000000000..1ed675f02 --- /dev/null +++ b/ext/reflection/tests/bug39001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #39001 (ReflectionProperty returns incorrect declaring class for protected properties) +--FILE-- +<?php + +class Meta { +} + +class CParent extends Meta { + public $publicVar; + protected $protectedVar; +} + +class Child extends CParent { +} + +$r = new ReflectionClass('Child'); + +var_dump($r->getProperty('publicVar')->getDeclaringClass()->getName()); +var_dump($r->getProperty('protectedVar')->getDeclaringClass()->getName()); + +echo "Done\n"; +?> +--EXPECTF-- +string(7) "CParent" +string(7) "CParent" +Done diff --git a/ext/reflection/tests/bug39067.phpt b/ext/reflection/tests/bug39067.phpt new file mode 100644 index 000000000..8a7a6044e --- /dev/null +++ b/ext/reflection/tests/bug39067.phpt @@ -0,0 +1,45 @@ +--TEST-- +Bug #39067 (getDeclaringClass() and private properties) +--FILE-- +<?php + +class A { + private $x; +} + +class B extends A { + private $x; +} + +class C extends B { + private $x; +} + +$rc = new ReflectionClass('C'); +var_dump($rc->getProperty('x')->getDeclaringClass()->getName()); + +$rc = new ReflectionClass('B'); +var_dump($rc->getProperty('x')->getDeclaringClass()->getName()); + +$rc = new ReflectionClass('A'); +var_dump($rc->getProperty('x')->getDeclaringClass()->getName()); + +class Test { + private $x; +} + +class Test2 extends Test { + public $x; +} + +$rc = new ReflectionClass('Test2'); +var_dump($rc->getProperty('x')->getDeclaringClass()->getName()); + +echo "Done\n"; +?> +--EXPECTF-- +string(1) "C" +string(1) "B" +string(1) "A" +string(5) "Test2" +Done |
