- MFH tests

This commit is contained in:
Marcus Boerger 2006-05-10 21:19:37 +00:00
parent 4df7ab403c
commit 9745215cf8
10 changed files with 298 additions and 129 deletions

View File

@ -1,21 +1,29 @@
--TEST--
ZE2 A static abstrcat method may not be called
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
ZE2 A static abstrcat methods
--FILE--
<?php
abstract class fail {
abstract static function show();
interface showable
{
static function show();
}
class pass extends fail {
class pass implements showable
{
static function show() {
echo "Call to function show()\n";
}
}
pass::show();
eval('
class fail
{
abstract static function func();
}
');
fail::show();
echo "Done\n"; // shouldn't be displayed
@ -23,4 +31,4 @@ echo "Done\n"; // shouldn't be displayed
--EXPECTF--
Call to function show()
Fatal error: Cannot call abstract method fail::show() in %s on line %d
Fatal error: Static function fail::func() cannot be abstract in %s on line %d

View File

@ -0,0 +1,30 @@
--TEST--
ZE2 An abstrcat method cannot be called indirectly
--FILE--
<?php
abstract class test_base
{
abstract function func();
}
class test extends test_base
{
function func()
{
echo __METHOD__ . "()\n";
}
}
$o = new test;
$o->func();
call_user_func(array($o, 'test_base::func'));
?>
===DONE===
--EXPECTF--
test::func()
Fatal error: Cannot call abstract method test_base::func() in %s on line %d

View File

@ -1,24 +0,0 @@
--TEST--
ZE2 An interface constructor signature must not be inherited
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
--FILE--
<?php
error_reporting(4095);
interface test {
public function __construct($foo);
}
class foo implements test {
public function __construct() {
echo "foo\n";
}
}
$foo = new foo;
?>
--EXPECT--
foo

View File

@ -7,27 +7,20 @@ class MyObject {}
interface MyInterface
{
public function __construct(Object $o);
public function __construct(MyObject $o);
}
class MyTestClass implements MyInterface
{
public function __construct(Object $o)
public function __construct(MyObject $o)
{
}
}
$obj = new MyTestClass;
class MyTestFail
{
public function __construct()
{
}
}
?>
===DONE===
--EXPECTF--
Fatal error: Argument 1 passed to MyTestClass::__construct() must be an object of class Object, called in %sinterfaces_003.php on line %d
Catchable fatal error: Argument 1 passed to MyTestClass::__construct() must be an object of class MyObject, called in %sinterfaces_003.php on line %d

View File

@ -1,86 +0,0 @@
--TEST--
ZE2 __toString()
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
--FILE--
<?php
class test1 {
}
class test2 {
function __toString() {
echo __METHOD__ . "()\n";
return "Converted\n";
}
}
echo "====test1====\n";
$o = new test1;
print_r($o);
var_dump((string)$o);
var_dump($o);
echo "====test2====\n";
$o = new test2;
print_r($o);
print $o;
var_dump($o);
echo "====test3====\n";
echo $o;
echo "====test4====\n";
echo "string:".$o;
echo "====test5====\n";
echo 1 . $o;
echo "====test6====\n";
echo $o.$o;
echo "====test7====\n";
$ar = array();
$ar[$o->__toString()] = "ERROR";
echo $ar[$o];
echo "====test8====\n";
var_dump(trim($o));
var_dump(trim((string)$o));
echo "====test9====\n";
echo sprintf("%s", $o);
?>
====DONE!====
--EXPECTF--
====test1====
test1 Object
(
)
string(1%d) "Object id #%d"
object(test1)#%d (%d) {
}
====test2====
test2 Object
(
)
test2::__toString()
Converted
object(test2)#%d (%d) {
}
====test3====
test2::__toString()
Converted
====test4====
string:Object id #%d====test5====
1Object id #%d====test6====
Object id #%dObject id #2====test7====
test2::__toString()
Warning: Illegal offset type in %stostring.php on line %d
====test8====
Notice: Object of class test2 to string conversion in %stostring.php on line %d
string(6) "Object"
string(1%d) "Object id #%d"
====test9====
Object id #%d====DONE!====

184
tests/classes/tostring_001.phpt Executable file
View File

@ -0,0 +1,184 @@
--TEST--
ZE2 __toString()
--FILE--
<?php
function my_error_handler($errno, $errstr, $errfile, $errline) {
var_dump($errstr);
}
set_error_handler('my_error_handler');
class test1
{
}
class test2
{
function __toString()
{
echo __METHOD__ . "()\n";
return "Converted\n";
}
}
class test3
{
function __toString()
{
echo __METHOD__ . "()\n";
return 42;
}
}
echo "====test1====\n";
$o = new test1;
print_r($o);
var_dump((string)$o);
var_dump($o);
echo "====test2====\n";
$o = new test2;
print_r($o);
print $o;
var_dump($o);
echo "====test3====\n";
echo $o;
echo "====test4====\n";
echo "string:".$o;
echo "====test5====\n";
echo 1 . $o;
echo 1 , $o;
echo "====test6====\n";
echo $o . $o;
echo $o , $o;
echo "====test7====\n";
$ar = array();
$ar[$o->__toString()] = "ERROR";
echo $ar[$o];
echo "====test8====\n";
var_dump(trim($o));
var_dump(trim((string)$o));
echo "====test9====\n";
echo sprintf("%s", $o);
echo "====test10====\n";
$o = new test3;
var_dump($o);
echo $o;
?>
====DONE====
--EXPECTF--
====test1====
test1 Object
(
)
string(54) "Object of class test1 could not be converted to string"
string(0) ""
object(test1)#%d (0) {
}
====test2====
test2 Object
(
)
test2::__toString()
Converted
object(test2)#%d (0) {
}
====test3====
test2::__toString()
Converted
====test4====
test2::__toString()
string:Converted
====test5====
test2::__toString()
1Converted
1test2::__toString()
Converted
====test6====
test2::__toString()
test2::__toString()
Converted
Converted
test2::__toString()
Converted
test2::__toString()
Converted
====test7====
test2::__toString()
string(19) "Illegal offset type"
====test8====
test2::__toString()
string(9) "Converted"
test2::__toString()
string(9) "Converted"
====test9====
test2::__toString()
Converted
====test10====
object(test3)#%d (0) {
}
test3::__toString()
string(53) "Method test3::__toString() must return a string value"
====DONE====
--UEXPECTF--
====test1====
test1 Object
(
)
unicode(54) "Object of class test1 could not be converted to string"
unicode(0) ""
object(test1)#%d (0) {
}
====test2====
test2 Object
(
)
test2::__toString()
Converted
object(test2)#%d (0) {
}
====test3====
test2::__toString()
Converted
====test4====
test2::__toString()
string:Converted
====test5====
test2::__toString()
1Converted
1test2::__toString()
Converted
====test6====
test2::__toString()
test2::__toString()
Converted
Converted
test2::__toString()
Converted
test2::__toString()
Converted
====test7====
test2::__toString()
unicode(19) "Illegal offset type"
====test8====
test2::__toString()
unicode(9) "Converted"
test2::__toString()
unicode(9) "Converted"
====test9====
test2::__toString()
Converted
====test10====
object(test3)#%d (0) {
}
test3::__toString()
unicode(53) "Method test3::__toString() must return a string value"
====DONE====

31
tests/classes/tostring_002.phpt Executable file
View File

@ -0,0 +1,31 @@
--TEST--
ZE2 __toString() in __destruct
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
--FILE--
<?php
class Test
{
function __toString()
{
return "Hello\n";
}
function __destruct()
{
echo $this;
}
}
$o = new Test;
$o = NULL;
$o = new Test;
?>
====DONE====
--EXPECTF--
Hello
====DONE====
Hello

33
tests/classes/tostring_003.phpt Executable file
View File

@ -0,0 +1,33 @@
--TEST--
ZE2 __toString() in __destruct/exception
--FILE--
<?php
class Test
{
function __toString()
{
throw new Exception("Damn!");
return "Hello\n";
}
function __destruct()
{
echo $this;
}
}
try
{
$o = new Test;
$o = NULL;
}
catch(Exception $e)
{
var_dump($e->getMessage());
}
?>
====DONE====
--EXPECTF--
Fatal error: Method Test::__toString() must not throw an exception in %stostring_003.php on line %d

View File

@ -35,4 +35,4 @@ $a->b($b);
?>
--EXPECTF--
Fatal error: Argument 1 passed to FooBar::a() must implement interface Foo, called in %s on line 27 and defined in %s on line 12
Catchable fatal error: Argument 1 passed to FooBar::a() must implement interface Foo, called in %s on line 27 and defined in %s on line 12

View File

@ -57,4 +57,4 @@ array(1) {
int(25)
}
Fatal error: Argument 1 passed to Test::f1() must be an array, called in %stype_hinting_003.php on line %d and defined in %stype_hinting_003.php on line %d
Catchable fatal error: Argument 1 passed to Test::f1() must be an array, called in %stype_hinting_003.php on line %d and defined in %stype_hinting_003.php on line %d