views:

51

answers:

1

I'm writing and testing a ClassLoader component, which can be instantiated many times, with various mappings between class names and their relevant paths. Each ClassLoader should work as a loader for a specific package.

Is there an easy, unobtrusive way to test or mock inclusion of files handled by the ClassLoader?

Let me clarify with a simplest possible Loader:

class TestTwoPackageLoader implements IPackageLoader
{
 private $directory;

 public function register()
 {
  spl_autoload_register(array($this, 'loadClass'));
  $this->directory = dirname(__FILE__);
 }

 public function loadClass($class)
 {
  if (isset($this->classes[$class]))
   include $this->directory.'/'.$this->classes[$class];
 }

 private $classes = array(
  'SecClass' => 'test_two/SecClass.php',
  'ThClass' => 'test_two/ThClass.php',
 );
}
+2  A: 

I'm not certain if you should be testing language functionality, rather than your own code. That said, you might test for successful inclusion via class_exists or function_exists, assuming the included files define known classes or functions.

Grant Palin