Skip to content

Add failing test. #12

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

Closed
wants to merge 8 commits into from
Closed
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--
autoload_call_class() function - basic test for spl_autoload_call()
--CREDITS--
Jean-Marc Fontaine <[email protected]>
# Alter Way Contribution Day 2011
--FILE--
<?php
function customAutolader($class) {
class TestClass {}
}
autoload_register_class('customAutolader');

autoload_call_class('TestClass');
var_dump(class_exists('TestClass', false));
?>
--EXPECT--
bool(true)
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
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
SPL: spl_autoload() with exceptions
--INI--
include_path=.
Exceptions during autoloading
--FILE--
<?php

Expand Down Expand Up @@ -44,14 +42,14 @@ foreach($funcs as $idx => $func)

var_dump($func);
try {
spl_autoload_register($func);
autoload_register_class($func);
} catch (TypeError $e) {
echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL;
var_dump(count(spl_autoload_functions()));
var_dump(count(autoload_list_class()));
continue;
}

if (count(spl_autoload_functions())) {
if (count(autoload_list_class())) {
echo "registered\n";

try {
Expand All @@ -61,8 +59,8 @@ foreach($funcs as $idx => $func)
}
}

spl_autoload_unregister($func);
var_dump(count(spl_autoload_functions()));
autoload_unregister_class($func);
var_dump(count(autoload_list_class()));
}

?>
Expand All @@ -81,7 +79,7 @@ Exception: Bla
int(0)
====2====
string(22) "MyAutoLoader::dynaLoad"
TypeError: spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, non-static method MyAutoLoader::dynaLoad() cannot be called statically
TypeError: autoload_register_class(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::dynaLoad() cannot be called statically
int(0)
====3====
array(2) {
Expand All @@ -101,7 +99,7 @@ array(2) {
[1]=>
string(8) "dynaLoad"
}
TypeError: spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, non-static method MyAutoLoader::dynaLoad() cannot be called statically
TypeError: autoload_register_class(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::dynaLoad() cannot be called statically
int(0)
====5====
array(2) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
--TEST--
SPL: spl_autoload() capturing multiple Exceptions in __autoload
Capturing multiple Exceptions during autoloading
--FILE--
<?php

function autoload_first($name)
{
function autoload_first($name) {
echo __METHOD__ . "\n";
throw new Exception('first');
}

function autoload_second($name)
{
function autoload_second($name) {
echo __METHOD__ . "\n";
throw new Exception('second');
}

spl_autoload_register('autoload_first');
spl_autoload_register('autoload_second');
autoload_register_class('autoload_first');
autoload_register_class('autoload_second');

try {
class_exists('ThisClassDoesNotExist');
Expand Down Expand Up @@ -44,9 +42,9 @@ autoload_first
first
autoload_first

Fatal error: Uncaught Exception: first in %sspl_autoload_012.php:%d
Fatal error: Uncaught Exception: first in %s:%d
Stack trace:
#0 [internal function]: autoload_first('ThisClassDoesNo...')
#1 %sspl_autoload_012.php(%d): class_exists('ThisClassDoesNo...')
#1 %s(%d): class_exists('ThisClassDoesNo...')
#2 {main}
thrown in %s on line %d
Loading