1
votes

Take for example I have a class SampleService like following, now how can I write unit test with PHPUnit for the getName() method? more specifically how can i mock self::_getName(); with Mockery? If that is not possible, what are the best approach/way to write unit test for this kinds of scenarios? Thanks.

class SampleService implements Service
{    
    public function getName(){
        $name = self::_getName();
        return 'Mr. '.$name;
    }

    private static function _getName(){
        return 'Some Name';
    }
}
1

1 Answers

1
votes

No, and you should not use them in TDD. Use them only if you shall never need to mock it.

And if you need to mock it - move all the code into a new class and mock the new class.