0

i'm working on an application in a modular way, that is, i have a interface and i want to make an unit test for all the classes that implement that interface so i made an abstract class that have all the logic implemented(testing if the class is actually implementing the interface, testing the return values and so on) but when i try to inherit the abstract class i get an class not found exception i'm working with namespaces so my directory structure is like this

namespaceA
|->abstract.php
|->namespaceB
    |->pluginTest.php

so my pluginTest.php class definition is like this

namespace namespaceA\namespaceB;    
use namespaceA\Abstract;

class pluginTest extends Abstract

and obviously in my abstract class there is the namespaceA definition, i have also tried to manually include the file (include("../Abstract.php")) but it failed, but since i have used autoloading for a while maybe i don't remember well how to manually import, i also have tried with alias of the class (using namespaceA\Abstract as X) and by putting an \ before the namespaceA but nothing work, what im doing wrong, or what im missing

==edit==

i managed to load the class using

include __DIR__ ."/../Abstract.php";

but still not autoloading

  • you do not need to import it, always use autoloading – Xerkus Sep 04 '13 at 01:23
  • In your phpunit.xml you can specify bootstrap file location, setup all the autoloading there. for example https://github.com/ZF-Commons/ZfcUser/blob/master/tests/phpunit.xml and https://github.com/ZF-Commons/ZfcUser/blob/master/tests/bootstrap.php – Xerkus Sep 04 '13 at 01:26
  • @Xerkus i know, i just tried to see if it can load, and also i did the bootstraping using the documentantion of zend in this page http://framework.zend.com/manual/2.1/en/tutorials/unittesting.html but still nothing – Juan Antonio Orozco Sep 04 '13 at 02:02
  • Try renaming your abstract.php to Abstract.php. autoloading using psr0 is case sensitive – Bram Gerritsen Sep 04 '13 at 05:31
  • well the real clas names are `testAbstract` (`testAbstract.php`) and `pluginTest` (`pluginTest.php`), an infact autoloading is working whit another namespaces,(pluginTest loads an class from an other namespace), but it dont work whit the parent class – Juan Antonio Orozco Sep 04 '13 at 15:47

1 Answers1

0

i solved it i just have to add the test directory to the module.php like this

public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
            ),
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                    'namespaceA' => __DIR__ . '/test/' .'namespaceA', //added this line
                ),
            ),
        );
    }