Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit - test autoloader class

I need to create an autoloader to my application. I don't want to depend on a file in the filesystem, so how do I mock a new call? Or how do you test an autoloader class? Thanks.

like image 358
thom Avatar asked Sep 20 '11 16:09

thom


1 Answers

Or how do you test an autoloader class

Imho you don't need to unit test your autoloader at all.

If you bootstrap your application it will ether crash really hard because it can find all the needed classes or your autoloader works fine.

Every single test in your test suite will test that the autoloader is able to load the "class under test" so i wouldn't worry to much about unit testing it.

Maybe call it "integration testing as a side effect" if you want but I'd say thats good enough.

If you don't think thats good enough I'd put the require/include statement in a protected function and override that function in a test autoloader and check if it receives the right values.

like image 110
edorian Avatar answered Sep 25 '22 02:09

edorian