Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing test with arguably the correct behaviour. #13

Open
wants to merge 17 commits into
base: zend_autoloader
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Zend/tests/autoloading/class/autoload_call_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Basic autoload_call_class() function
--CREDITS--
Jean-Marc Fontaine <[email protected]>
# Alter Way Contribution Day 2011
--FILE--
<?php
function customAutoloader($class) {
class TestClass {}
}
autoload_register_class('customAutoloader');

autoload_call_class('TestClass');
var_dump(class_exists('TestClass', false));
?>
--EXPECT--
bool(true)
36 changes: 36 additions & 0 deletions Zend/tests/autoloading/class/autoload_call_invalid_name.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
Test autoload_call_class() with invalid symbol name
--FILE--
<?php
function customAutoloader($name) {
var_dump($name);
}
autoload_register_class('customAutoloader');

try {
autoload_call_class('12ayhs');
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage();
}
try {
autoload_call_class('"');
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage();
}
try {
autoload_call_class('');
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage();
}
try {
autoload_call_class("al\no");
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage();
}
?>
--EXPECT--
string(6) "12ayhs"
string(1) """
string(0) ""
string(4) "al
o"
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--TEST--
SPL autoloader should not do anything magic with called scope
Autoloader should not do anything magic with called scope
--FILE--
<?php

class Test {
public static function register() {
spl_autoload_register([Test::class, 'autoload']);
autoload_register_class([Test::class, 'autoload']);
}

public static function autoload($class) {
Expand All @@ -15,7 +15,7 @@ class Test {

class Test2 extends Test {
public static function register() {
spl_autoload_register([Test2::class, 'autoload']);
autoload_register_class([Test2::class, 'autoload']);
}

public static function runTest() {
Expand Down
41 changes: 41 additions & 0 deletions Zend/tests/autoloading/class/autoload_invalid_name_variable.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
Dynamic autoload with invalid symbol name in variable
--FILE--
<?php
function customAutoloader($name) {
var_dump($name);
}
autoload_register_class('customAutoloader');
$name = '12ayhs';

try {
new $name;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), \PHP_EOL;
}
$name = '"';
try {
new $name;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), \PHP_EOL;
}
$name = '';
try {
new $name;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), \PHP_EOL;
}
$name = "al\no";
try {
new $name;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), \PHP_EOL;
}
?>
--EXPECT--
string(6) "12ayhs"
Error: Class "12ayhs" not found
Error: Class """ not found
Error: Class "" not found
Error: Class "al
o" not found
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--TEST--
Autoloading with closures and invocables
--FILE--
<?php
$closure = function ($name) {
echo 'autoload(' . $name . ")\n";
};

class Autoloader {
public function __construct(private string $dir) {}
public function __invoke($class) {
echo ("Autoloader('{$this->dir}') called with $class\n");
}
}

class WorkingAutoloader {
public function __invoke($class) {
echo ("WorkingAutoloader() called with $class\n");
eval("class $class { }");
}
}

$al1 = new Autoloader('d1');
$al2 = new WorkingAutoloader('d2');

autoload_register_class($closure);
autoload_register_class($al1);
autoload_register_class($al2);

var_dump(autoload_list_class());

$x = new TestX;

autoload_unregister_class($closure);
autoload_unregister_class($al1);

$y = new TestY;

?>
--EXPECT--
array(3) {
[0]=>
object(Closure)#1 (1) {
["parameter"]=>
array(1) {
["$name"]=>
string(10) "<required>"
}
}
[1]=>
object(Autoloader)#2 (1) {
["dir":"Autoloader":private]=>
string(2) "d1"
}
[2]=>
object(WorkingAutoloader)#3 (0) {
}
}
autoload(TestX)
Autoloader('d1') called with TestX
WorkingAutoloader() called with TestX
WorkingAutoloader() called with TestY
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
--TEST--
Bug #42798 (_autoload() not triggered for classes used in method signature)
Bug #42798 (Autoloading not triggered for classes used in method signature)
--FILE--
<?php
spl_autoload_register(function ($className) {
autoload_register_class(function ($className) {
print "$className\n";
exit();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bug #46665 (Triggering autoload with a variable classname causes truncated autol
--FILE--
<?php

spl_autoload_register(function ($class) {
autoload_register_class(function ($class) {
var_dump($class);
require __DIR__ .'/bug46665_autoload.inc';
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
--TEST--
Bug #65006: spl_autoload_register fails with multiple callables using self, same method
Bug #65006: autoload_register_class fails with multiple callables using self, same method
--FILE--
<?php

class first {
public static function init() {
spl_autoload_register(array('self','load'));
autoload_register_class(array('self','load'));
}
public static function load($class) {}
}

class second {
public static function init() {
spl_autoload_register(array('self','load'));
autoload_register_class(array('self','load'));
}
public static function load($class){}
}

first::init();
second::init();
var_dump(spl_autoload_functions());
var_dump(autoload_list_class());

?>
--EXPECTF--
Expand Down
19 changes: 19 additions & 0 deletions Zend/tests/autoloading/class/bug71204.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Bug #71204 (segfault if clean autoloaders while autoloading)
--FILE--
<?php

autoload_register_class(function ($name) {
autoload_unregister_class("autoload_unregister_class");
});

autoload_register_class(function ($name) {
});

new A();
?>
--EXPECTF--
Fatal error: Uncaught Error: Class "A" not found in %s:%d
Stack trace:
#0 {main}
thrown in %sbug71204.php on line %d
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
--TEST--
Bug #73896 (spl_autoload() crashes when calls magic _call())
Bug #73896 (autoload_register_class() crashes when calls magic __call())
--FILE--
<?php
class Registrator {
public static function call($callable, array $args) {
public static function call($callable, array $args) {
return call_user_func_array($callable, [$args]);
}
}

class teLoader {
public function __construct() {
Registrator::call('spl_autoload_register', [$this, 'autoload']);
Registrator::call('autoload_register_class', [$this, 'autoload']);
}

public function __call($method, $args) {
$this->doSomething();
}

protected function autoload($class) {
die("Protected autoload() called!\n");
echo "Protected autoload() called!\n";
}

public function doSomething() {
Expand All @@ -35,4 +35,5 @@ try {
}
?>
--EXPECT--
Protected autoload() called!
Exception: Class "teException" not found
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
SPL: spl_autoload() and object freed
--INI--
include_path=.
Destructor call of autoloader when object freed
--FILE--
<?php
class A {
Expand All @@ -17,7 +15,7 @@ class A {
$a = new A;
$a->var = 2;

spl_autoload_register(array($a, 'autoload'));
autoload_register_class(array($a, 'autoload'));
unset($a);

var_dump(class_exists("C", true));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
--TEST--
Bug #74372: autoloading file with syntax error uses next autoloader, may hide parse error
Parse errors should be thrown if occuring from an autoloader
--FILE--
<?php

spl_autoload_register(function($class) {
autoload_register_class(function($class) {
eval("ha ha ha");
});
spl_autoload_register(function($class) {
autoload_register_class(function($class) {
echo "Don't call me.\n";
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
--TEST--
SPL: spl_autoload() and friends
--INI--
include_path=.
Exception thrown from within autoloading function
--FILE--
<?php

function TestFunc1($classname)
{
function TestFunc1($classname) {
echo __METHOD__ . "($classname)\n";
}

function TestFunc2($classname)
{
function TestFunc2($classname) {
echo __METHOD__ . "($classname)\n";
throw new Exception("Class $classname missing");
}

function TestFunc3($classname)
{
function TestFunc3($classname) {
echo __METHOD__ . "($classname)\n";
}

spl_autoload_register("TestFunc1");
spl_autoload_register("TestFunc2");
spl_autoload_register("TestFunc3");
autoload_register_class("TestFunc1");
autoload_register_class("TestFunc2");
autoload_register_class("TestFunc3");

try
{
try {
var_dump(class_exists("TestClass", true));
}
catch(Exception $e)
{
} catch(Exception $e) {
echo 'Exception: ' . $e->getMessage() . "\n";
}

Expand Down
Loading