views:

29

answers:

1

Hi all,

I've got following factory class which has a dependency $client. I moved the dependency to the factory class as it first occurred in Service_Service1 class so I could test the service class. But how can I test the factory class?

class Factory implements Service
{

    public static function factory($service)
    {
        $config = Zend_Registry::get('config');

        switch ($service) {
            case Service::Service1:
                $client = new Zend_Soap_Client(
                    $config->url,
                    array(
                        'encoding' => 'UTF-8'
                    )
                );
                $pickupPoint = new Service_Service1($client);
                break;
        }
    }
}
+1  A: 

I am not sure what the question is, but if it is how to stub the hardcoded dependencies, have a look at this article by the author of PHPUnit:

Your best would be to inject instances of those classes instead of hardcoding them. As an alternative you could make their classnames properties in the Factory, so you can exchange what it will instantiate.

Gordon
I just was looking for a solution how to change the factory class to be testable without hardcoded dependencies, so thanx!
Skelton