summaryrefslogtreecommitdiff
path: root/ext/reflection/tests
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2015-03-30 12:14:43 +0300
committerDmitry Stogov <dmitry@zend.com>2015-03-30 12:14:43 +0300
commit9155a267adeeb6f442f97892de441e4b6666ce73 (patch)
tree7d525ab7379401c38b4416886655b4753ec5701a /ext/reflection/tests
parentc71c97e101f239d487c7a9797bdf193098d469ca (diff)
parent910a3243063f0490a60e5c3c0e1467a6171f4e39 (diff)
downloadphp-git-9155a267adeeb6f442f97892de441e4b6666ce73.tar.gz
Merge branch 'InternalClassClean' of github.com:Danack/php-src into InternalClassClean
* 'InternalClassClean' of github.com:Danack/php-src: Fixed indentation. Fixed comment style. Fixed commented out code. Reverted change to function name and added note of why it is different from the class it is actually changing. Made UConverter throw an exception if the constructor fails. Fixed PDO constructor to not return null. Fixed fileinfo behaviour. Made Phar throw exception on bad constructor. Converted intl extension to use IntlException in constructors. Fixed SplFixedArray and tests. Fixed ReflectionExtension and ReflectionProperty. Fixed ReflectionFunction, ReflectionMethod and ReflectionParameter. Fixed PDORow behaviour and message.
Diffstat (limited to 'ext/reflection/tests')
-rw-r--r--ext/reflection/tests/ReflectionExtension_constructor_error.phpt30
-rw-r--r--ext/reflection/tests/ReflectionFunction_construct.001.phpt39
-rw-r--r--ext/reflection/tests/ReflectionMethod_006.phpt31
-rw-r--r--ext/reflection/tests/ReflectionMethod_constructor_error2.phpt39
-rw-r--r--ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt21
-rw-r--r--ext/reflection/tests/ReflectionProperty_error.phpt50
6 files changed, 145 insertions, 65 deletions
diff --git a/ext/reflection/tests/ReflectionExtension_constructor_error.phpt b/ext/reflection/tests/ReflectionExtension_constructor_error.phpt
index 9eae206c50..f731ab51cc 100644
--- a/ext/reflection/tests/ReflectionExtension_constructor_error.phpt
+++ b/ext/reflection/tests/ReflectionExtension_constructor_error.phpt
@@ -5,12 +5,32 @@ Gerrit "Remi" te Sligte <remi@wolerized.com>
Leon Luijkx <leon@phpgg.nl>
--FILE--
<?php
-$obj = new ReflectionExtension();
-$test = $obj instanceof ReflectionExtension;
-var_dump($test);
+try {
+ $obj = new ReflectionExtension();
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+try {
+ $obj = new ReflectionExtension('foo', 'bar');
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+try {
+ $obj = new ReflectionExtension([]);
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+
?>
==DONE==
--EXPECTF--
-Warning: ReflectionExtension::__construct() expects exactly %d parameter, %d given in %s.php on line %d
-bool(true)
+Ok - ReflectionExtension::__construct() expects exactly %d parameter, %d given
+Ok - ReflectionExtension::__construct() expects exactly %d parameter, %d given
+Ok - ReflectionExtension::__construct() expects parameter 1 to be string, array given
==DONE==
diff --git a/ext/reflection/tests/ReflectionFunction_construct.001.phpt b/ext/reflection/tests/ReflectionFunction_construct.001.phpt
index c8e0a17a9d..90259ac997 100644
--- a/ext/reflection/tests/ReflectionFunction_construct.001.phpt
+++ b/ext/reflection/tests/ReflectionFunction_construct.001.phpt
@@ -6,18 +6,41 @@ Steve Seear <stevseea@php.net>
--FILE--
<?php
-$a = new ReflectionFunction(array(1, 2, 3));
+try {
+ $a = new ReflectionFunction(array(1, 2, 3));
+ echo "exception not thrown.".PHP_EOL;
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
try {
$a = new ReflectionFunction('nonExistentFunction');
} catch (Exception $e) {
- echo $e->getMessage();
+ echo $e->getMessage().PHP_EOL;
+}
+try {
+ $a = new ReflectionFunction();
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+try {
+ $a = new ReflectionFunction(1, 2);
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+try {
+ $a = new ReflectionFunction([]);
}
-$a = new ReflectionFunction();
-$a = new ReflectionFunction(1, 2);
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
?>
--EXPECTF--
-Warning: ReflectionFunction::__construct() expects parameter 1 to be string, array given in %s on line %d
+Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given
Function nonExistentFunction() does not exist
-Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 0 given in %s on line %d
-
-Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 2 given in %s on line %d
+Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 0 given
+Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 2 given
+Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given
diff --git a/ext/reflection/tests/ReflectionMethod_006.phpt b/ext/reflection/tests/ReflectionMethod_006.phpt
index a5164190ca..0b8228989c 100644
--- a/ext/reflection/tests/ReflectionMethod_006.phpt
+++ b/ext/reflection/tests/ReflectionMethod_006.phpt
@@ -6,8 +6,18 @@ Steve Seear <stevseea@php.net>
--FILE--
<?php
-var_dump(new ReflectionMethod());
-var_dump(new ReflectionMethod('a', 'b', 'c'));
+try {
+ new ReflectionMethod();
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+try {
+ new ReflectionMethod('a', 'b', 'c');
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
class C {
public function f() {}
@@ -35,21 +45,8 @@ var_dump($rm->getName(1));
?>
--EXPECTF--
-Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line %d
-object(ReflectionMethod)#%d (2) {
- ["name"]=>
- string(0) ""
- ["class"]=>
- string(0) ""
-}
-
-Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line %d
-object(ReflectionMethod)#%d (2) {
- ["name"]=>
- string(0) ""
- ["class"]=>
- string(0) ""
-}
+Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given
+Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given
Warning: ReflectionMethod::isFinal() expects exactly 0 parameters, 1 given in %s on line %d
NULL
diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
index 1c2d3a138f..85f8097825 100644
--- a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
+++ b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
@@ -16,22 +16,47 @@ class TestClass
try {
echo "Too few arguments:\n";
$methodInfo = new ReflectionMethod();
-} catch (Exception $e) {
- print $e->__toString();
+} catch (ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
echo "\nToo many arguments:\n";
$methodInfo = new ReflectionMethod("TestClass", "foo", true);
-} catch (Exception $e) {
- print $e->__toString();
+} catch (ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+
+try {
+ //invalid class
+ $methodInfo = new ReflectionMethod("InvalidClassName", "foo");
+} catch (ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+
+try {
+ //invalid 1st param
+ $methodInfo = new ReflectionMethod([], "foo");
+} catch (ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+try{
+ //invalid 2nd param
+ $methodInfo = new ReflectionMethod("TestClass", []);
+} catch (ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
}
?>
--EXPECTF--
Too few arguments:
-
-Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line 12
+Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given
Too many arguments:
+Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given
+Ok - Class InvalidClassName does not exist
+Ok - The parameter class is expected to be either a string or an object
+Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 2 given
-Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line 18
diff --git a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
index 3118c17be8..1775dee514 100644
--- a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
+++ b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
@@ -6,7 +6,7 @@ ReflectionParameter::__construct(): Invalid method as constructor
// Invalid class name
try {
new ReflectionParameter (array ('A', 'b'), 0);
-} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; }
+} catch (ReflectionException $e) { echo $e->getMessage()."\n"; }
// Invalid class method
try {
@@ -18,14 +18,31 @@ try {
new ReflectionParameter (array (new C, 'b'), 0);
} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; }
-echo "Done.\n";
class C {
}
+try {
+ new ReflectionParameter(array ('A', 'b'));
+}
+catch(ReflectionException $e) {
+ printf( "Ok - %s\n", $e->getMessage());
+}
+
+try {
+ new ReflectionParameter(0, 0);
+}
+catch(ReflectionException $e) {
+ printf( "Ok - %s\n", $e->getMessage());
+}
+
+echo "Done.\n";
+
?>
--EXPECTF--
Class A does not exist
Method C::b() does not exist
Method C::b() does not exist
+Ok - ReflectionParameter::__construct() expects exactly 2 parameters, 1 given
+Ok - The parameter class is expected to be either a string, an array(class, method) or a callable object
Done.
diff --git a/ext/reflection/tests/ReflectionProperty_error.phpt b/ext/reflection/tests/ReflectionProperty_error.phpt
index 56de6e1f2e..d3910296b5 100644
--- a/ext/reflection/tests/ReflectionProperty_error.phpt
+++ b/ext/reflection/tests/ReflectionProperty_error.phpt
@@ -7,9 +7,27 @@ class C {
public static $p;
}
-var_dump(new ReflectionProperty());
-var_dump(new ReflectionProperty('C::p'));
-var_dump(new ReflectionProperty('C', 'p', 'x'));
+try {
+ new ReflectionProperty();
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+try {
+ new ReflectionProperty('C::p');
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+try {
+ new ReflectionProperty('C', 'p', 'x');
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+
$rp = new ReflectionProperty('C', 'p');
var_dump($rp->getName(1));
var_dump($rp->isPrivate(1));
@@ -21,29 +39,9 @@ var_dump($rp->isDefault(1));
?>
--EXPECTF--
-Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 0 given in %s on line %d
-object(ReflectionProperty)#%d (2) {
- ["name"]=>
- string(0) ""
- ["class"]=>
- string(0) ""
-}
-
-Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 1 given in %s on line %d
-object(ReflectionProperty)#%d (2) {
- ["name"]=>
- string(0) ""
- ["class"]=>
- string(0) ""
-}
-
-Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 3 given in %s on line %d
-object(ReflectionProperty)#%d (2) {
- ["name"]=>
- string(0) ""
- ["class"]=>
- string(0) ""
-}
+Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 0 given
+Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 1 given
+Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 3 given
Warning: ReflectionProperty::getName() expects exactly 0 parameters, 1 given in %s on line %d
NULL