]> granicus.if.org Git - php/commitdiff
Testfest: various tests for ReflectionParameter
authorLars Strojny <lstrojny@php.net>
Thu, 12 Jun 2008 21:41:09 +0000 (21:41 +0000)
committerLars Strojny <lstrojny@php.net>
Thu, 12 Jun 2008 21:41:09 +0000 (21:41 +0000)
ext/reflection/tests/reflectionParameter_export_basic.phpt [new file with mode: 0644]
ext/reflection/tests/reflectionParameter_export_error.phpt [new file with mode: 0644]
ext/reflection/tests/reflectionParameter_export_error2.phpt [new file with mode: 0644]
ext/reflection/tests/reflectionParameter_export_error3.phpt [new file with mode: 0644]
ext/reflection/tests/reflectionParameter_getDeclaringFunction_basic.phpt [new file with mode: 0644]
ext/reflection/tests/reflectionParameter_getPosition_basic.phpt [new file with mode: 0644]
ext/reflection/tests/reflectionParameter_toString_basic.phpt [new file with mode: 0644]

diff --git a/ext/reflection/tests/reflectionParameter_export_basic.phpt b/ext/reflection/tests/reflectionParameter_export_basic.phpt
new file mode 100644 (file)
index 0000000..74428cc
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+ReflectionParameter::export()
+--CREDITS--
+Stefan Koopmanschap <stefan@stefankoopmanschap.nl>
+--FILE--
+<?php
+function ReflectionParameterTest($test, $test2 = null) {
+       echo $test;
+}
+$reflect = new ReflectionFunction('ReflectionParameterTest');
+foreach($reflect->getParameters() as $key => $value) {
+       echo ReflectionParameter::export('ReflectionParameterTest', $key);
+}
+?>
+==DONE==
+--EXPECT--
+Parameter #0 [ <required> $test ]
+Parameter #1 [ <optional> $test2 = NULL ]
+==DONE==
diff --git a/ext/reflection/tests/reflectionParameter_export_error.phpt b/ext/reflection/tests/reflectionParameter_export_error.phpt
new file mode 100644 (file)
index 0000000..31acfe1
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+ReflectionParameter::export() without parameters
+--CREDITS--
+Stefan Koopmanschap <stefan@stefankoopmanschap.nl>
+--FILE--
+<?php
+function ReflectionParameterTest($test, $test2 = null) {
+       echo $test;
+}
+$reflect = new ReflectionFunction('ReflectionParameterTest');
+foreach($reflect->getParameters() as $key => $value) {
+       ReflectionParameter::export();
+}
+?>
+==DONE==
+--EXPECTF--
+
+Warning: ReflectionParameter::export() expects at least 2 parameters, 0 given in %s.php on line %d
+
+Warning: ReflectionParameter::export() expects at least 2 parameters, 0 given in %s.php on line %d
+==DONE==
diff --git a/ext/reflection/tests/reflectionParameter_export_error2.phpt b/ext/reflection/tests/reflectionParameter_export_error2.phpt
new file mode 100644 (file)
index 0000000..50baff5
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+ReflectionParameter::export() with incorrect first parameter
+--CREDITS--
+Stefan Koopmanschap <stefan@stefankoopmanschap.nl>
+--FILE--
+<?php
+function ReflectionParameterTest($test, $test2 = null) {
+       echo $test;
+}
+$reflect = new ReflectionFunction('ReflectionParameterTest');
+$params = $reflect->getParameters();
+foreach($params as $key => $value) {
+       ReflectionParameter::export($reflect, $key);
+}
+?>
+--EXPECTF--
+
+Fatal error: Uncaught exception 'ReflectionException' with message 'The parameter class is expected to be either a string or an array(class, method)' in %s.php:%d
+Stack trace:
+#0 [internal function]: ReflectionParameter->__construct(Object(ReflectionFunction), 0)
+#1 %s.php(%d): ReflectionParameter::export(Object(ReflectionFunction), 0)
+#2 {main}
+  thrown in %s.php on line %d
diff --git a/ext/reflection/tests/reflectionParameter_export_error3.phpt b/ext/reflection/tests/reflectionParameter_export_error3.phpt
new file mode 100644 (file)
index 0000000..2937853
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+ReflectionParameter::export() with incorrect second parameter
+--CREDITS--
+Stefan Koopmanschap <stefan@stefankoopmanschap.nl>
+--FILE--
+<?php
+function ReflectionParameterTest($test, $test2 = null) {
+       echo $test;
+}
+$reflect = new ReflectionFunction('ReflectionParameterTest');
+$params = $reflect->getParameters();
+foreach($params as $key => $value) {
+       ReflectionParameter::export('ReflectionParameterTest', 'incorrect_parameter');
+}
+--EXPECTF--
+
+Fatal error: Uncaught exception 'ReflectionException' with message 'The parameter specified by its name could not be found' in %s.php:%d
+Stack trace:
+#0 [internal function]: ReflectionParameter->__construct('ReflectionParam...', 'incorrect_param...')
+#1 %s.php(%d): ReflectionParameter::export('ReflectionParam...', 'incorrect_param...')
+#2 {main}
+  thrown in %s.php on line %d
diff --git a/ext/reflection/tests/reflectionParameter_getDeclaringFunction_basic.phpt b/ext/reflection/tests/reflectionParameter_getDeclaringFunction_basic.phpt
new file mode 100644 (file)
index 0000000..59e15a7
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+ReflectionParameter::getDeclaringFunction()
+--CREDITS--
+Stefan Koopmanschap <stefan@stefankoopmanschap.nl>
+#testfest roosendaal on 2008-05-10
+--FILE--
+<?php
+function ReflectionParameterTest($test, $test2 = null) {
+       echo $test;
+}
+$reflect = new ReflectionFunction('ReflectionParameterTest');
+$params = $reflect->getParameters();
+foreach($params as $key => $value) {
+       echo $value->getDeclaringFunction() . "\n";
+}
+?>
+==DONE==
+--EXPECTF--
+Function [ <user> function ReflectionParameterTest ] {
+  @@ %s.php %d - %d
+
+  - Parameters [2] {
+    Parameter #0 [ <required> $test ]
+    Parameter #1 [ <optional> $test2 = NULL ]
+  }
+}
+
+Function [ <user> function ReflectionParameterTest ] {
+  @@ %s.php %d - %d
+
+  - Parameters [2] {
+    Parameter #0 [ <required> $test ]
+    Parameter #1 [ <optional> $test2 = NULL ]
+  }
+}
+
+==DONE==
diff --git a/ext/reflection/tests/reflectionParameter_getPosition_basic.phpt b/ext/reflection/tests/reflectionParameter_getPosition_basic.phpt
new file mode 100644 (file)
index 0000000..2807bdf
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+ReflectionParameter::getPosition()
+--CREDITS--
+Stefan Koopmanschap <stefan@stefankoopmanschap.nl>
+#testfest roosendaal on 2008-05-10
+--FILE--
+<?php
+function ReflectionParameterTest($test, $test2 = null) {
+       echo $test;
+}
+$reflect = new ReflectionFunction('ReflectionParameterTest');
+$params = $reflect->getParameters();
+foreach($params as $key => $value) {
+       var_dump($value->getPosition());
+}
+?>
+==DONE==
+--EXPECT--
+int(0)
+int(1)
+==DONE==
diff --git a/ext/reflection/tests/reflectionParameter_toString_basic.phpt b/ext/reflection/tests/reflectionParameter_toString_basic.phpt
new file mode 100644 (file)
index 0000000..268ced1
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+ReflectionParameter::__toString()
+--CREDITS--
+Stefan Koopmanschap <stefan@stefankoopmanschap.nl>
+--FILE--
+<?php
+function ReflectionParameterTest($test, $test2 = null) {
+       echo $test;
+}
+$reflect = new ReflectionFunction('ReflectionParameterTest');
+$params = $reflect->getParameters();
+foreach($params as $key => $value) {
+       echo $value->__toString() . "\n";
+}
+?>
+==DONE==
+--EXPECT--
+Parameter #0 [ <required> $test ]
+Parameter #1 [ <optional> $test2 = NULL ]
+==DONE==