Skip to content

Commit 4e210ad

Browse files
author
Robin Fernandes
committed
Adding tests for class features, including __autoload(), property inheritance rules and class constants. Note: autoload_012.phpt failing on php6, fix expected via bug 43973.
1 parent f3643b5 commit 4e210ad

File tree

70 files changed

+2376
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2376
-0
lines changed

tests/classes/__call_003.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Force pass-by-reference to __call
3+
--FILE--
4+
<?php
5+
class C
6+
{
7+
function __call($name, $values)
8+
{
9+
$values[0][0] = 'changed';
10+
}
11+
}
12+
13+
$a = array('original');
14+
15+
$b = array('original');
16+
$hack =& $b[0];
17+
18+
$c = new C;
19+
$c->f($a);
20+
$c->f($b);
21+
22+
var_dump($a, $b);
23+
?>
24+
--EXPECTF--
25+
array(1) {
26+
[0]=>
27+
string(8) "original"
28+
}
29+
array(1) {
30+
[0]=>
31+
&string(7) "changed"
32+
}
33+
--UEXPECTF--
34+
array(1) {
35+
[0]=>
36+
unicode(8) "original"
37+
}
38+
array(1) {
39+
[0]=>
40+
&unicode(7) "changed"
41+
}

tests/classes/autoload_007.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Ensure instanceof does not trigger autoload.
3+
--FILE--
4+
<?php
5+
function __autoload($name)
6+
{
7+
echo "In autoload: ";
8+
var_dump($name);
9+
}
10+
11+
$a = new stdClass;
12+
var_dump($a instanceof UndefC);
13+
?>
14+
--EXPECTF--
15+
bool(false)

tests/classes/autoload_008.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Ensure catch blocks for unknown exception types do not trigger autoload.
3+
--FILE--
4+
<?php
5+
function __autoload($name)
6+
{
7+
echo "In autoload: ";
8+
var_dump($name);
9+
}
10+
11+
function f()
12+
{
13+
throw new Exception();
14+
}
15+
try {
16+
f();
17+
}
18+
catch (UndefC $u) {
19+
echo "In UndefClass catch block.\n";
20+
}
21+
catch (Exception $e) {
22+
echo "In Exception catch block. Autoload should not have been triggered.\n";
23+
}
24+
?>
25+
--EXPECTF--
26+
In Exception catch block. Autoload should not have been triggered.

tests/classes/autoload_009.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Ensure type hints for unknown types do not trigger autoload.
3+
--FILE--
4+
<?php
5+
function __autoload($name)
6+
{
7+
echo "In autoload: ";
8+
var_dump($name);
9+
}
10+
11+
function f(UndefClass $x)
12+
{
13+
}
14+
f(new stdClass);
15+
?>
16+
--EXPECTF--
17+
18+
Catchable fatal error: Argument 1 passed to f() must be an instance of UndefClass, instance of stdClass given, called in %s
19+
20+

tests/classes/autoload_010.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Ensure implements does trigger autoload.
3+
--FILE--
4+
<?php
5+
function __autoload($name)
6+
{
7+
echo "In autoload: ";
8+
var_dump($name);
9+
}
10+
11+
class C implements UndefI
12+
{
13+
}
14+
?>
15+
--EXPECTF--
16+
In autoload: string(6) "UndefI"
17+
18+
Fatal error: Interface 'UndefI' not found in %s on line %d
19+
20+
--UEXPECTF--
21+
In autoload: unicode(6) "UndefI"
22+
23+
Fatal error: Interface 'UndefI' not found in %s on line %d

tests/classes/autoload_011.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Ensure extends does trigger autoload.
3+
--FILE--
4+
<?php
5+
function __autoload($name)
6+
{
7+
echo "In autoload: ";
8+
var_dump($name);
9+
}
10+
11+
class C extends UndefBase
12+
{
13+
}
14+
?>
15+
--EXPECTF--
16+
In autoload: string(9) "UndefBase"
17+
18+
Fatal error: Class 'UndefBase' not found in %s on line %d
19+
20+
--UEXPECTF--
21+
In autoload: unicode(9) "UndefBase"
22+
23+
Fatal error: Class 'UndefBase' not found in %s on line %d

tests/classes/autoload_012.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Ensure callback methods in unknown classes trigger autoload.
3+
--FILE--
4+
<?php
5+
function __autoload($name)
6+
{
7+
echo "In autoload: ";
8+
var_dump($name);
9+
}
10+
call_user_func("UndefC::test");
11+
?>
12+
--EXPECTF--
13+
In autoload: string(6) "UndefC"
14+
15+
Warning: call_user_func() expects parameter 1 to be valid callback, string given in %s on line %d
16+
17+
--UEXPECTF--
18+
In autoload: unicode(6) "UndefC"
19+
20+
Warning: call_user_func() expects parameter 1 to be valid callback, Unicode string given in %s on line %d

tests/classes/autoload_013.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Ensure the ReflectionClass constructor triggers autoload.
3+
--SKIPIF--
4+
<?php extension_loaded('reflection') or die('skip'); ?>
5+
--FILE--
6+
<?php
7+
function __autoload($name)
8+
{
9+
echo "In autoload: ";
10+
var_dump($name);
11+
}
12+
13+
try {
14+
new ReflectionClass("UndefC");
15+
}
16+
catch (ReflectionException $e) {
17+
echo $e->getMessage();
18+
}
19+
?>
20+
--EXPECTF--
21+
In autoload: string(6) "UndefC"
22+
Class UndefC does not exist
23+
--UEXPECTF--
24+
In autoload: unicode(6) "UndefC"
25+
Class UndefC does not exist

tests/classes/autoload_014.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Ensure the ReflectionMethod constructor triggers autoload.
3+
--SKIPIF--
4+
<?php extension_loaded('reflection') or die('skip'); ?>
5+
--FILE--
6+
<?php
7+
function __autoload($name)
8+
{
9+
echo "In autoload: ";
10+
var_dump($name);
11+
}
12+
13+
try {
14+
new ReflectionMethod("UndefC::test");
15+
}
16+
catch (ReflectionException $e) {
17+
echo $e->getMessage();
18+
}
19+
?>
20+
--EXPECTF--
21+
In autoload: string(6) "UndefC"
22+
Class UndefC does not exist
23+
--UEXPECTF--
24+
In autoload: unicode(6) "UndefC"
25+
Class UndefC does not exist

tests/classes/autoload_015.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Ensure the ReflectionProperty constructor triggers autoload.
3+
--SKIPIF--
4+
<?php extension_loaded('reflection') or die('skip'); ?>
5+
--FILE--
6+
<?php
7+
function __autoload($name)
8+
{
9+
echo "In autoload: ";
10+
var_dump($name);
11+
}
12+
13+
try {
14+
new ReflectionProperty('UndefC', 'p');
15+
}
16+
catch (ReflectionException $e) {
17+
echo $e->getMessage();
18+
}
19+
?>
20+
--EXPECTF--
21+
In autoload: string(6) "UndefC"
22+
Class UndefC does not exist
23+
--UEXPECTF--
24+
In autoload: unicode(6) "UndefC"
25+
Class UndefC does not exist

0 commit comments

Comments
 (0)