php - __autoload not respected when testing with PHPUnit -



php - __autoload not respected when testing with PHPUnit -

how can create phpunit respect __autoload functions?

for example, have these 3 files:

loader.php

function __autoload($name) { echo "foo\n"; require_once("$name.php"); }

test.php

require_once("loader.php"); class footest extends phpunit_framework_testcase { function testfoo() { new foo(); } }

foo.php

require_once("loader.php"); new foo();

as expected php foo.php errors out, saying file "foo.php" doesn't exist. testfoo() function errors out saying there no such class foo, , never echos "foo\n" line.

this expected behavior.

see phpunit bugtracker entry: upgrading 3.5.10 has broken function of "autoload"

as of phpunit 3.5:

phpunit uses autoloader load classes. if tested code requires autoloader, utilize spl_autoload_register() register it.

quick fix:

the alter required add together spl_autoload_register('__autoload') in bootstrap script.

longer fix:

if can i'd suggest rid of __autoload , utilize spl_autoload_register in application way go php 5 code. (if have 1 autoloader can't utilize autoloader of framework , on)

php phpunit autoload

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -