如何重构类,其中公共方法只是getter,对测试单元友好?

时间:2016-12-08 16:49:06

标签: php unit-testing

如何重构类,其中公共方法只是getter,对测试单元友好?

如何测试这个类,测试哪些方法?

class Order
{
    private $em;
    private $orders;
    private $foo;

    function __construct(EntityManager $em)
    {
        $this->em = $em;
    }

    public function prepareOrder($foo)
    {
        $this->setFields($foo);
        $this->doSomething() 
        $this->prepareRepository();
    }

    private function setFields($foo)
    {
        $this->foo = $foo;
    }

    private function doSomething()
    {
        //do something with $this->foo
    }


    private function prepareRepository()
    {
        //use $this->foo;  
        $this->orders = $this->em->getRepository(..)->findBy(..);
    }


    public function getOrder()
    {
        return $this->orders;
    }
}

0 个答案:

没有答案