-1

I really hope this isn't a duplicate, but here I go:

I use Zend's autoloader to load classes. It seems to work, at least it loads the correct file when instantiating my class (Common_TestTest) which is implemented in Common/TestTest.php. But then I get the following error message:

"Class Common_TestTest could not be found in Common/TestTest.php."

There's nothing in TestTest.php other than the class:

<?php

class Common_TestTest extends PHPUnit_Framework_TestCase
{
    public function testTesting() {
        $this->assertTrue(true);
        $this->assertFalse(true);
    }
}

I tried dumping get_declared_classes at the end of the file, everything looks fine, Common_TestTest is one of the declared classes - but the exception is still thrown when leaving the file.

The funniest bit is: When I change the name of the class from Common_TestTest to TestTest the same things happens - only that the error message states the name of the missing class as "TestTest". So it definitely sees the class and reacts to it's presence.

hakre
  • 193,403
  • 52
  • 435
  • 836
Jan Olaf Krems
  • 2,274
  • 1
  • 14
  • 11
  • Additionally to namespaces: Which component is giving your the error message? Is it Zend? To which directory does the message refer to? It's a relative path not an absolute one so this would be interesting. If the autoloader is looking in the wrong directory, the file is not found. – hakre Jan 30 '12 at 13:23
  • This apparently a testing class. Is it stored in the application/Common or in Test FIles/Common? If it's in Testing Files/Common you may have left out a path when you bootstrap your test suite. – RockyFord Jan 30 '12 at 14:12
  • Autoloading here shouldn't matter because PHPUnit loads all test cases by scanning the directory for files ending in `Test.php` by default. In fact, I would avoid registering the directory containing tests with the autoloader. – David Harkness Jan 31 '12 at 03:39

1 Answers1

0

There are 2 possibilities that come to my mind as to what causes the problem:

  1. You have some case-mismatch between class-name and file-name, e.g. Testtest.php

  2. When registering the Namespace you use "Common" instead of "Common_". Zend_Loader_Autoloader does not distinguish between PHP 5.3 style namespaces and ZF-style namespaces (rather Prefix). By appending the underscore you make sure, that your namespace is interpreted as a class-prefix rather than a real namespace.

dbrumann
  • 16,803
  • 2
  • 42
  • 58