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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With