Refactoring PHP code to remove static methods

Refactoring PHP code to remove static methods

Dave Hollingworth

5 лет назад

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

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 тэги не поддерживаются


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

Cristhofer Alencar
Cristhofer Alencar - 13.04.2019 21:27

Hello Dave, first of all I would like to thank you for your great videos, it has helped me a lot and I learned a lot from them. I bought your 2 courses at Udemy and found it excellent, I was wondering if you plan to do some other more advanced course with a bigger project, I think it would be very interesting.

Ответить
Chris Dorman
Chris Dorman - 12.04.2019 11:59

Object orientated programming is retarded. Unnecessarily overly abstracted.

Ответить