Say I have this code:Design{    public function load()    {        $this->loadProduct();        $this->loadService();        ...    }    public function loadProduct()    {        try        {            $this->product = new Product();            $this->product->spec = $this->product->loadSpecs($this->a, $this->b, $this->c);        }        catch (\BadFunctionCallException $e)        {            $this->error = true;            $this->emsg = $e->getMessage();        }    }}Questions:Do I test loadProduct function only?Do I test Product class only?Do I move loadProduct's code into load (thereby removing loadProduct function from existence, and test the larger load function (as part of Design class)?  Say I may want to do this as part of clean up/reorganization of legacy code.Something else?
testing: which code layers should I aim to test?
php;unit testing;refactoring;legacy
You should test sufficiently to provide adequate code coverage. Sufficiently (and adequate) vary on the risk associated with an undetected problem in your code. The cost to fix a problem after development (assuming a classic SDLC) is significantly higher then the cost to fix during development, but the risk may be minimal. So, really that is another way of saying that it depends on your context. Another point to remember is that testing does not prove correctness, nor does it prove your software is bug-free - all testing can do is provide you with information. For more, I recommend the book Perfect Software: And Other Illusions about Testing by G. Weinberg.