Refactoring PHP code to remove static methods

Refactoring PHP code to remove static methods

Dave Hollingworth

55 лет назад

2,135 Просмотров

Access the full course ➤ https://davehollingworth.net/phpunity

As we just saw, if you have a method that's calling a static method in another class, you can't test this class in isolation because you can't stub the method call.

The easiest way to overcome this problem is to simply change the static method into an instance one. You can of course only do this if you have full control of the code - if you're using a class you have no control over, for example in a third-party library, then this won't be possible.

In this video we'll see how we can test a dependency using PHPUnit by refactoring code to remove a static method.

Тэги:

#PHP #PHPUnit #Unit_Testing #PHP_Unit_Testing
Ссылки и html тэги не поддерживаются


Комментарии: