- MFH: New tests

This commit is contained in:
Felipe Pena 2008-05-11 03:50:28 +00:00
parent c83d916a98
commit e4c7664158
26 changed files with 639 additions and 0 deletions

11
Zend/tests/031.phpt Normal file
View File

@ -0,0 +1,11 @@
--TEST--
Testing array with '[]' passed as argument by value
--FILE--
<?php
function test($var) { }
test($arr[]);
?>
--EXPECTF--
Fatal error: Cannot use [] for reading in %s on line %d

13
Zend/tests/032.phpt Normal file
View File

@ -0,0 +1,13 @@
--TEST--
Testing array with '[]' passed as argument by reference
--FILE--
<?php
function test(&$var) { }
test($arr[]);
print "ok!\n";
?>
--EXPECT--
ok!

31
Zend/tests/033.phpt Normal file
View File

@ -0,0 +1,31 @@
--TEST--
Using undefined multidimensional array
--FILE--
<?php
$arr[1][2][3][4][5];
echo $arr[1][2][3][4][5];
$arr[1][2][3][4][5]->foo;
$arr[1][2][3][4][5]->foo = 1;
$arr[][] = 2;
$arr[][]->bar = 2;
?>
--EXPECTF--
Notice: Undefined variable: arr in %s on line %d
Notice: Undefined variable: arr in %s on line %d
Notice: Undefined variable: arr in %s on line %d
Notice: Trying to get property of non-object in %s on line %d
Strict Standards: Creating default object from empty value in %s on line %d
Strict Standards: Creating default object from empty value in %s on line %d

View File

@ -0,0 +1,35 @@
--TEST--
Testing calls to anonymous function
--FILE--
<?php
for ($i = 0; $i < 10; $i++) {
$a = create_function('', 'return '. $i .';');
var_dump($a());
$b = "\0lambda_". ($i + 1);
var_dump($b());
}
?>
--EXPECT--
int(0)
int(0)
int(1)
int(1)
int(2)
int(2)
int(3)
int(3)
int(4)
int(4)
int(5)
int(5)
int(6)
int(6)
int(7)
int(7)
int(8)
int(8)
int(9)
int(9)

View File

@ -0,0 +1,16 @@
--TEST--
Testing anonymous function return as array key and accessing $GLOBALS
--FILE--
<?php
$test = create_function('$v', 'return $v;');
$arr = array(create_function('', 'return $GLOBALS["arr"];'), 2);
var_dump($arr[$test(1)]);
var_dump($arr[$test(0)]() == $arr);
?>
--EXPECT--
int(2)
bool(true)

View File

@ -0,0 +1,15 @@
--TEST--
Using throw $var with anonymous function return
--FILE--
<?php
try {
$a = create_function('', 'return new Exception("test");');
throw $a();
} catch (Exception $e) {
var_dump($e->getMessage() == 'test');
}
?>
--EXPECT--
bool(true)

View File

@ -0,0 +1,17 @@
--TEST--
Testing dynamic call to constructor (old-style)
--FILE--
<?php
class foo {
public function foo() {
}
}
$a = 'foo';
$a::$a();
?>
--EXPECTF--
Fatal error: Non-static method foo::foo() cannot be called statically in %s on line %d

View File

@ -0,0 +1,12 @@
--TEST--
Testing dynamic call with invalid value for method name
--FILE--
<?php
$a = new stdClass;
$a::$a();
?>
--EXPECTF--
Fatal error: Function name must be a string in %s on line %d

View File

@ -0,0 +1,13 @@
--TEST--
Testing dynamic call with invalid method name
--FILE--
<?php
$a = new stdClass;
$b = 1;
$a::$b();
?>
--EXPECTF--
Fatal error: Function name must be a string in %s on line %d

View File

@ -0,0 +1,12 @@
--TEST--
Testing dynamic call with undefined variables
--FILE--
<?php
$a::$b();
?>
--EXPECTF--
Notice: Undefined variable: a in %s on line %d
Fatal error: Class name must be a valid object or a string in %s on line %d

View File

@ -0,0 +1,38 @@
--TEST--
Testing nested exceptions
--FILE--
<?php
try {
try {
try {
try {
throw new Exception(NULL);
} catch (Exception $e) {
var_dump($e->getMessage());
throw $e;
}
} catch (Exception $e) {
var_dump($e->getMessage());
throw $e;
}
} catch (Exception $e) {
var_dump($e->getMessage());
throw $e;
}
} catch (Exception $e) {
var_dump($e->getMessage());
throw $e;
}
?>
--EXPECTF--
string(0) ""
string(0) ""
string(0) ""
string(0) ""
Fatal error: Uncaught exception 'Exception' in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d

View File

@ -0,0 +1,19 @@
--TEST--
Testing exception and GOTO
--FILE--
<?php
goto foo;
try {
print 1;
foo:
print 2;
} catch (Exception $e) {
}
?>
--EXPECT--
2

View File

@ -0,0 +1,14 @@
--TEST--
Throwing exception in global scope
--FILE--
<?php
throw new Exception(1);
?>
--EXPECTF--
Fatal error: Uncaught exception 'Exception' with message '1' in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d

View File

@ -0,0 +1,41 @@
--TEST--
Testing heredoc with escape sequences
--FILE--
<?php
$test = <<<TEST
TEST;
var_dump(strlen($test) == 0);
$test = <<<TEST
\
TEST;
var_dump(strlen($test) == 1);
$test = <<<TEST
\0
TEST;
var_dump(strlen($test) == 1);
$test = <<<TEST
\n
TEST;
var_dump(strlen($test) == 1);
$test = <<<TEST
\\'
TEST;
var_dump(strlen($test) == 2);
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)

View File

@ -0,0 +1,42 @@
--TEST--
Testing heredoc (double quotes) with escape sequences
--FILE--
<?php
$test = <<<"TEST"
TEST;
var_dump(strlen($test) == 0);
$test = <<<"TEST"
\
TEST;
var_dump(strlen($test) == 1);
$test = <<<"TEST"
\0
TEST;
var_dump(strlen($test) == 1);
$test = <<<"TEST"
\n
TEST;
var_dump(strlen($test) == 1);
$test = <<<"TEST"
\\'
TEST;
var_dump(strlen($test) == 2);
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)

View File

@ -0,0 +1,17 @@
--TEST--
Testinh heredoc syntax
--FILE--
<?php
$a = <<<A
A;
;
A;
\;
A;
var_dump(strlen($a) == 12);
?>
--EXPECT--
bool(true)

View File

@ -0,0 +1,29 @@
--TEST--
Testing instanceof operator with several operators
--FILE--
<?php
$a = new stdClass;
var_dump($a instanceof stdClass);
var_dump(new stdCLass instanceof stdClass);
$b = create_function('', 'return new stdClass;');
var_dump($b() instanceof stdClass);
$c = array(new stdClass);
var_dump($c[0] instanceof stdClass);
var_dump(@$inexistent instanceof stdClass);
var_dump("$a" instanceof stdClass);
?>
--EXPECTF--
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
Catchable fatal error: Object of class stdClass could not be converted to string in %s on line %d

View File

@ -0,0 +1,33 @@
--TEST--
Testing instanceof operator with class and interface inheriteds
--FILE--
<?php
interface ITest {
}
interface IFoo extends ITest {
}
class foo extends stdClass implements ITest {
}
var_dump(new foo instanceof stdClass);
var_dump(new foo instanceof ITest);
var_dump(new foo instanceof IFoo);
class bar extends foo implements IFoo {
}
var_dump(new bar instanceof stdClass);
var_dump(new bar instanceof ITest);
var_dump(new bar instanceof IFoo);
?>
--EXPECT--
bool(true)
bool(true)
bool(false)
bool(true)
bool(true)
bool(true)

28
Zend/tests/jump14.phpt Normal file
View File

@ -0,0 +1,28 @@
--TEST--
Testing GOTO inside blocks
--FILE--
<?php
goto A;
{
B:
goto C;
return;
}
A:
goto B;
{
C:
{
print "Done!\n";
}
}
?>
--EXPECT--
Done!

24
Zend/tests/list_003.phpt Normal file
View File

@ -0,0 +1,24 @@
--TEST--
list() with non-array
--FILE--
<?php
list($a) = NULL;
list($b) = 1;
list($c) = 1.;
list($d) = 'foo';
list($e) = print '';
var_dump($a, $b, $c, $d, $e);
?>
--EXPECT--
NULL
NULL
NULL
NULL
NULL

21
Zend/tests/list_004.phpt Normal file
View File

@ -0,0 +1,21 @@
--TEST--
list() with array reference
--FILE--
<?php
$arr = array(2, 1);
$b =& $arr;
list(,$a) = $b;
var_dump($a, $b);
?>
--EXPECT--
int(1)
array(2) {
[0]=>
int(2)
[1]=>
int(1)
}

47
Zend/tests/list_005.phpt Normal file
View File

@ -0,0 +1,47 @@
--TEST--
Testing list() with several variables
--FILE--
<?php
$a = "foo";
list($a, $b, $c) = $a;
var_dump($a, $b, $c);
print "----\n";
$a = 1;
list($a, $b, $c) = $a;
var_dump($a, $b, $c);
print "----\n";
$a = new stdClass;
list($a, $b, $c) = $a;
var_dump($a, $b, $c);
print "----\n";
$a = array(1, 2, 3);
list($a, $b, $c) = $a;
var_dump($a, $b, $c);
?>
--EXPECTF--
string(1) "f"
string(1) "o"
string(1) "o"
----
NULL
NULL
NULL
----
Fatal error: Cannot use object of type stdClass as array in %s on line %d

View File

@ -0,0 +1,41 @@
--TEST--
Testing nowdocs with escape sequences
--FILE--
<?php
$test = <<<'TEST'
TEST;
var_dump(strlen($test));
$test = <<<'TEST'
\
TEST;
var_dump(strlen($test));
$test = <<<'TEST'
\0
TEST;
var_dump(strlen($test));
$test = <<<'TEST'
\n
TEST;
var_dump(strlen($test));
$test = <<<'TEST'
\\'
TEST;
var_dump(strlen($test));
?>
--EXPECT--
int(0)
int(1)
int(2)
int(2)
int(3)

View File

@ -0,0 +1,16 @@
--TEST--
Testing nowdoc in default value for property
--FILE--
<?php
class foo {
public $bar = <<<'EOT'
bar
EOT;
}
print "ok!\n";
?>
--EXPECT--
ok!

View File

@ -0,0 +1,39 @@
--TEST--
Testing 'self', 'parent' as type-hint
--FILE--
<?php
interface iTest { }
class baz implements iTest {}
class bar { }
class foo extends bar {
public function testFoo(self $obj) {
var_dump($obj);
}
public function testBar(parent $obj) {
var_dump($obj);
}
public function testBaz(iTest $obj) {
var_dump($obj);
}
}
$foo = new foo;
$foo->testFoo(new foo);
$foo->testBar(new bar);
$foo->testBaz(new baz);
$foo->testFoo(new stdClass); // Catchable fatal error
?>
--EXPECTF--
object(foo)#%d (0) {
}
object(bar)#%d (0) {
}
object(baz)#%d (0) {
}
Catchable fatal error: Argument 1 passed to foo::testFoo() must be an instance of foo, instance of stdClass given, called in %s on line %d and defined in %s on line %d

View File

@ -0,0 +1,15 @@
--TEST--
Creating instances dynamically
--FILE--
<?php
$arr = array(new stdClass, 'stdClass');
new $arr[0]();
new $arr[1]();
print "ok\n";
?>
--EXPECT--
ok